2000-02-17 20:38:33 +01:00
|
|
|
/* sync.h: Header file for cygwin synchronization primitives.
|
|
|
|
|
2004-02-09 05:04:24 +01:00
|
|
|
Copyright 1999, 2000, 2001, 2002, 2003, 2004 Red Hat, Inc.
|
2000-02-17 20:38:33 +01: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 16:45:37 +01:00
|
|
|
#ifndef _SYNC_H
|
|
|
|
#define _SYNC_H
|
2000-02-17 20:38:33 +01: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 06:31:00 +02:00
|
|
|
public:
|
|
|
|
const char *name;
|
|
|
|
private:
|
2004-01-14 16:45:37 +01:00
|
|
|
static DWORD exiting_thread;
|
2000-02-17 20:38:33 +01: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 16:50:20 +01:00
|
|
|
LONG visits; /* Count of number of times a thread has called acquire. */
|
2004-05-16 06:18:50 +02:00
|
|
|
void *tls; /* Tls of lock owner. */
|
2004-01-14 16:45:37 +01:00
|
|
|
// class muto *next;
|
2001-11-03 04:32:27 +01:00
|
|
|
|
|
|
|
/* The real constructor. */
|
2005-04-05 06:31:00 +02:00
|
|
|
muto *init (const char *) __attribute__ ((regparm (2)));
|
2001-11-03 04:32:27 +01:00
|
|
|
|
2002-02-14 22:20:06 +01:00
|
|
|
#if 0 /* FIXME: See comment in sync.cc */
|
|
|
|
~muto ()
|
|
|
|
#endif
|
2002-08-16 21:41:39 +02:00
|
|
|
int acquire (DWORD ms = INFINITE) __attribute__ ((regparm (2))); /* Acquire the lock. */
|
|
|
|
int release () __attribute__ ((regparm (1))); /* Release the lock. */
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2004-05-16 06:18:50 +02:00
|
|
|
bool acquired () __attribute__ ((regparm (1)));
|
|
|
|
void upforgrabs () {tls = this;} // just set to an invalid address
|
|
|
|
void grab () __attribute__ ((regparm (1)));
|
2005-04-05 06:31:00 +02:00
|
|
|
operator int () const {return !!name;}
|
2004-01-14 16:45:37 +01:00
|
|
|
static void set_exiting_thread () {exiting_thread = GetCurrentThreadId ();}
|
2000-02-17 20:38:33 +01:00
|
|
|
};
|
|
|
|
|
2005-10-24 01:47:45 +02:00
|
|
|
class lock_process
|
|
|
|
{
|
|
|
|
bool skip_unlock;
|
|
|
|
static muto locker;
|
|
|
|
public:
|
|
|
|
static void init () {locker.init ("lock_process");}
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2004-01-14 16:45:37 +01:00
|
|
|
#endif /*_SYNC_H*/
|