]>
Commit | Line | Data |
---|---|---|
1fd5e000 CF |
1 | /* sync.h: Header file for cygwin synchronization primitives. |
2 | ||
39be53dc | 3 | Copyright 1999, 2000, 2001, 2002 Red Hat, Inc. |
1fd5e000 CF |
4 | |
5 | Written by Christopher Faylor <cgf@cygnus.com> | |
6 | ||
7 | This file is part of Cygwin. | |
8 | ||
9 | This software is a copyrighted work licensed under the terms of the | |
10 | Cygwin license. Please consult the file "CYGWIN_LICENSE" for | |
11 | details. */ | |
12 | ||
13 | /* FIXME: Note that currently this class cannot be allocated via `new' since | |
14 | there are issues with malloc and fork. */ | |
15 | class muto | |
16 | { | |
17 | LONG sync; /* Used to serialize access to this class. */ | |
18 | LONG visits; /* Count of number of times a thread has called acquire. */ | |
19 | LONG waiters; /* Number of threads waiting for lock. */ | |
20 | HANDLE bruteforce; /* event handle used to control waiting for lock. */ | |
21 | DWORD tid; /* Thread Id of lock owner. */ | |
22 | public: | |
d3bda1df | 23 | class muto *next; |
332600d8 | 24 | const char *name; |
243a041b | 25 | |
243a041b | 26 | /* The real constructor. */ |
2bd22312 | 27 | muto *init(const char *name) __attribute__ ((regparm (3))); |
243a041b | 28 | |
907dc7d0 CF |
29 | #if 0 /* FIXME: See comment in sync.cc */ |
30 | ~muto () | |
31 | #endif | |
c7e2187a CF |
32 | int acquire (DWORD ms = INFINITE) __attribute__ ((regparm (2))); /* Acquire the lock. */ |
33 | int release () __attribute__ ((regparm (1))); /* Release the lock. */ | |
1fd5e000 CF |
34 | |
35 | /* Return true if caller thread owns the lock. */ | |
36 | int ismine () {return tid == GetCurrentThreadId ();} | |
f02f1f14 | 37 | DWORD owner () {return tid;} |
9aa07a8f | 38 | int unstable () {return !tid && (sync || waiters >= 0);} |
c7e2187a | 39 | void reset () __attribute__ ((regparm (1))); |
1fd5e000 CF |
40 | }; |
41 | ||
d3bda1df CF |
42 | extern muto muto_start; |
43 | ||
1fd5e000 | 44 | /* Use a statically allocated buffer as the storage for a muto */ |
2bd22312 | 45 | #define new_muto(__name) \ |
1fd5e000 | 46 | ({ \ |
083abe54 CF |
47 | static muto __name##_storage __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy"))); \ |
48 | __name = __name##_storage.init (#__name); \ | |
1fd5e000 | 49 | }) |