2000-02-18 03:38:33 +08:00
|
|
|
/* sync.h: Header file for cygwin synchronization primitives.
|
|
|
|
|
2013-01-21 12:34:52 +08:00
|
|
|
Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2010, 2011,
|
|
|
|
2012, 2013 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2012-03-17 04:20:29 +08:00
|
|
|
#pragma once
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* FIXME: Note that currently this class cannot be allocated via `new' since
|
|
|
|
there are issues with malloc and fork. */
|
|
|
|
class muto
|
|
|
|
{
|
2005-04-05 12:31:00 +08:00
|
|
|
public:
|
2013-04-23 17:44:36 +08:00
|
|
|
char *name;
|
2005-04-05 12:31:00 +08:00
|
|
|
private:
|
2000-02-18 03:38:33 +08:00
|
|
|
LONG sync; /* Used to serialize access to this class. */
|
|
|
|
LONG waiters; /* Number of threads waiting for lock. */
|
|
|
|
HANDLE bruteforce; /* event handle used to control waiting for lock. */
|
|
|
|
public:
|
2004-03-15 23:50:20 +08:00
|
|
|
LONG visits; /* Count of number of times a thread has called acquire. */
|
2004-05-16 12:18:50 +08:00
|
|
|
void *tls; /* Tls of lock owner. */
|
2004-01-14 23:45:37 +08:00
|
|
|
// class muto *next;
|
2001-11-03 11:32:27 +08:00
|
|
|
|
|
|
|
/* The real constructor. */
|
2013-01-21 12:34:52 +08:00
|
|
|
muto __reg2 *init (const char *);
|
2001-11-03 11:32:27 +08:00
|
|
|
|
2002-02-15 05:20:06 +08:00
|
|
|
#if 0 /* FIXME: See comment in sync.cc */
|
|
|
|
~muto ()
|
|
|
|
#endif
|
2013-01-21 12:34:52 +08:00
|
|
|
int __reg2 acquire (DWORD ms = INFINITE); /* Acquire the lock. */
|
|
|
|
int __reg2 release (_cygtls * = &_my_tls); /* Release the lock. */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2013-01-21 12:34:52 +08:00
|
|
|
bool __reg1 acquired ();
|
2004-05-16 12:18:50 +08:00
|
|
|
void upforgrabs () {tls = this;} // just set to an invalid address
|
2013-01-21 12:34:52 +08:00
|
|
|
void __reg1 grab ();
|
2005-04-05 12:31:00 +08:00
|
|
|
operator int () const {return !!name;}
|
2000-02-18 03:38:33 +08:00
|
|
|
};
|
|
|
|
|
2005-10-24 07:47:45 +08:00
|
|
|
class lock_process
|
|
|
|
{
|
|
|
|
bool skip_unlock;
|
|
|
|
static muto locker;
|
|
|
|
public:
|
|
|
|
static void init () {locker.init ("lock_process");}
|
2006-07-15 06:15:12 +08:00
|
|
|
void dont_bother () {skip_unlock = true;}
|
2012-12-22 11:16:43 +08:00
|
|
|
lock_process (bool exiting = false)
|
2005-10-24 07:47:45 +08:00
|
|
|
{
|
2012-12-22 11:16:43 +08:00
|
|
|
locker.acquire ();
|
2005-10-24 07:47:45 +08:00
|
|
|
skip_unlock = exiting;
|
|
|
|
}
|
2012-12-29 02:06:17 +08:00
|
|
|
void release ()
|
|
|
|
{
|
|
|
|
locker.release ();
|
|
|
|
skip_unlock = true;
|
|
|
|
}
|
2005-10-24 07:47:45 +08:00
|
|
|
~lock_process ()
|
|
|
|
{
|
|
|
|
if (!skip_unlock)
|
2012-12-29 02:06:17 +08:00
|
|
|
release ();
|
2005-10-24 07:47:45 +08:00
|
|
|
}
|
2013-01-14 14:03:59 +08:00
|
|
|
operator LONG () const {return locker.visits; }
|
2012-12-22 05:30:56 +08:00
|
|
|
static void force_release (_cygtls *tid) {locker.release (tid);}
|
2005-10-24 07:47:45 +08:00
|
|
|
friend class dtable;
|
2006-06-23 08:19:39 +08:00
|
|
|
friend class fhandler_fifo;
|
2005-10-24 07:47:45 +08:00
|
|
|
};
|