]> sourceware.org Git - newlib-cygwin.git/blob - winsup/cygwin/sync.h
revert previous not-ready-for-primetime checkin.
[newlib-cygwin.git] / winsup / cygwin / sync.h
1 /* sync.h: Header file for cygwin synchronization primitives.
2
3 Copyright 1999, 2000, 2001, 2002, 2003, 2004 Red Hat, Inc.
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 #ifndef _SYNC_H
14 #define _SYNC_H
15 /* FIXME: Note that currently this class cannot be allocated via `new' since
16 there are issues with malloc and fork. */
17 class muto
18 {
19 static DWORD exiting_thread;
20 LONG sync; /* Used to serialize access to this class. */
21 LONG waiters; /* Number of threads waiting for lock. */
22 HANDLE bruteforce; /* event handle used to control waiting for lock. */
23 public:
24 LONG visits; /* Count of number of times a thread has called acquire. */
25 DWORD tid; /* Thread Id of lock owner. */
26 // class muto *next;
27 const char *name;
28
29 /* The real constructor. */
30 muto *init(const char *name) __attribute__ ((regparm (3)));
31
32 #if 0 /* FIXME: See comment in sync.cc */
33 ~muto ()
34 #endif
35 int acquire (DWORD ms = INFINITE) __attribute__ ((regparm (2))); /* Acquire the lock. */
36 int release () __attribute__ ((regparm (1))); /* Release the lock. */
37
38 /* Return true if caller thread owns the lock. */
39 int ismine () {return tid == GetCurrentThreadId ();}
40 DWORD owner () {return tid;}
41 int unstable () {return !tid && (sync || waiters >= 0);}
42 void reset () __attribute__ ((regparm (1)));
43 bool acquired ();
44 static void set_exiting_thread () {exiting_thread = GetCurrentThreadId ();}
45 };
46
47 extern muto muto_start;
48
49 /* Use a statically allocated buffer as the storage for a muto */
50 #define new_muto(__name) \
51 ({ \
52 static muto __name##_storage __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy1"))); \
53 __name = __name##_storage.init (#__name); \
54 })
55
56 /* Use a statically allocated buffer as the storage for a muto */
57 #define new_muto1(__name, __storage) \
58 ({ \
59 static muto __storage __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy1"))); \
60 __name = __storage.init (#__name); \
61 })
62 #endif /*_SYNC_H*/
This page took 0.03618 seconds and 5 git commands to generate.