2000-02-18 03:38:33 +08:00
|
|
|
/* sync.h: Header file for cygwin synchronization primitives.
|
|
|
|
|
2006-06-23 08:19:39 +08:00
|
|
|
Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
Written by Christopher Faylor <cgf@cygnus.com>
|
|
|
|
|
|
|
|
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. */
|
|
|
|
|
2004-01-14 23:45:37 +08:00
|
|
|
#ifndef _SYNC_H
|
|
|
|
#define _SYNC_H
|
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:
|
|
|
|
const char *name;
|
|
|
|
private:
|
2004-01-14 23:45:37 +08:00
|
|
|
static DWORD exiting_thread;
|
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. */
|
2005-04-05 12:31:00 +08:00
|
|
|
muto *init (const char *) __attribute__ ((regparm (2)));
|
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
|
2002-08-17 03:41:39 +08:00
|
|
|
int acquire (DWORD ms = INFINITE) __attribute__ ((regparm (2))); /* Acquire the lock. */
|
|
|
|
int release () __attribute__ ((regparm (1))); /* Release the lock. */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2004-05-16 12:18:50 +08:00
|
|
|
bool acquired () __attribute__ ((regparm (1)));
|
|
|
|
void upforgrabs () {tls = this;} // just set to an invalid address
|
|
|
|
void grab () __attribute__ ((regparm (1)));
|
2005-04-05 12:31:00 +08:00
|
|
|
operator int () const {return !!name;}
|
2004-01-14 23:45:37 +08:00
|
|
|
static void set_exiting_thread () {exiting_thread = GetCurrentThreadId ();}
|
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;}
|
2005-10-24 07:47:45 +08:00
|
|
|
lock_process (bool exiting = false)
|
|
|
|
{
|
|
|
|
locker.acquire ();
|
|
|
|
skip_unlock = exiting;
|
|
|
|
if (exiting && exit_state < ES_SET_MUTO)
|
|
|
|
{
|
|
|
|
exit_state = ES_SET_MUTO;
|
|
|
|
muto::set_exiting_thread ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
~lock_process ()
|
|
|
|
{
|
|
|
|
if (!skip_unlock)
|
|
|
|
locker.release ();
|
|
|
|
}
|
|
|
|
friend class dtable;
|
2006-06-23 08:19:39 +08:00
|
|
|
friend class fhandler_fifo;
|
2005-10-24 07:47:45 +08:00
|
|
|
};
|
|
|
|
|
2004-01-14 23:45:37 +08:00
|
|
|
#endif /*_SYNC_H*/
|