2009-05-15 Geoff Norton <gnorton@novell.com>
[mono-project.git] / mono / io-layer / critical-sections.h
blob6926e7687c7c518a0dfd5df9570a6b8a90bfa90c
1 /*
2 * critical-sections.h: Critical sections
4 * Author:
5 * Dick Porter (dick@ximian.com)
7 * (C) 2002 Ximian, Inc.
8 */
10 #ifndef _WAPI_CRITICAL_SECTIONS_H_
11 #define _WAPI_CRITICAL_SECTIONS_H_
13 #include <glib.h>
14 #include <pthread.h>
16 #include "mono-mutex.h"
18 G_BEGIN_DECLS
20 typedef struct _WapiCriticalSection WapiCriticalSection;
22 struct _WapiCriticalSection
24 guint32 depth;
25 mono_mutex_t mutex;
28 extern void InitializeCriticalSection(WapiCriticalSection *section);
29 extern gboolean InitializeCriticalSectionAndSpinCount(WapiCriticalSection *section, guint32 spincount);
30 extern void DeleteCriticalSection(WapiCriticalSection *section);
31 extern guint32 SetCriticalSectionSpinCount(WapiCriticalSection *section, guint32 spincount);
32 extern gboolean TryEnterCriticalSection(WapiCriticalSection *section);
34 /* These two are perf critical so avoid the wrapper function */
36 #define EnterCriticalSection(section) do { \
37 int ret = mono_mutex_lock(&(section)->mutex); \
38 if (ret != 0) \
39 g_warning ("Bad call to mono_mutex_lock result %d", ret); \
40 g_assert (ret == 0); \
41 } while (0)
43 #define LeaveCriticalSection(section) do { \
44 int ret = mono_mutex_unlock(&(section)->mutex); \
45 if (ret != 0) \
46 g_warning ("Bad call to mono_mutex_unlock result %d", ret); \
47 g_assert (ret == 0); \
48 } while (0)
50 G_END_DECLS
52 #endif /* _WAPI_CRITICAL_SECTIONS_H_ */