2 * critical-sections.c: Critical sections
5 * Dick Porter (dick@ximian.com)
7 * (C) 2002 Ximian, Inc.
15 #include <mono/io-layer/wapi.h>
16 #include <mono/io-layer/critical-section-private.h>
18 #include <mono/utils/mono-mutex.h>
20 /* A critical section is really just like a lightweight mutex. It
21 * can't be waited for, and doesn't have a handle.
25 * InitializeCriticalSection:
26 * @section: The critical section to initialise
28 * Initialises a critical section.
30 void InitializeCriticalSection(WapiCriticalSection
*section
)
34 ret
= mono_mutex_init_recursive (§ion
->mutex
);
39 * InitializeCriticalSectionAndSpinCount:
40 * @section: The critical section to initialise.
41 * @spincount: The spin count for this critical section. Not
44 * Initialises a critical section and sets the spin count. This
45 * implementation just calls InitializeCriticalSection().
47 * Return value: %TRUE on success, %FALSE otherwise. (%FALSE never
50 gboolean
InitializeCriticalSectionAndSpinCount(WapiCriticalSection
*section
,
51 guint32 spincount G_GNUC_UNUSED
)
53 InitializeCriticalSection(section
);
59 * DeleteCriticalSection:
60 * @section: The critical section to delete.
62 * Releases all resources owned by critical section @section.
64 void DeleteCriticalSection(WapiCriticalSection
*section
)
68 ret
= mono_mutex_destroy(§ion
->mutex
);
70 g_error ("Failed to destroy mutex %p error code %d errno %d", §ion
->mutex
, ret
, errno
);
74 * SetCriticalSectionSpinCount:
75 * @section: The critical section to set
76 * @spincount: The new spin count for this critical section. Not
79 * Sets the spin count for the critical section @section. The spin
80 * count is currently ignored, and set to zero.
82 * Return value: The previous spin count. (Currently always zero).
84 guint32
SetCriticalSectionSpinCount(WapiCriticalSection
*section G_GNUC_UNUSED
, guint32 spincount G_GNUC_UNUSED
)
90 * TryEnterCriticalSection:
91 * @section: The critical section to try and enter
93 * Attempts to enter a critical section without blocking. If
94 * successful the calling thread takes ownership of the critical
97 * A thread can recursively call EnterCriticalSection() and
98 * TryEnterCriticalSection(), but must call LeaveCriticalSection() an
99 * equal number of times.
101 * Return value: %TRUE if the thread successfully locked the critical
102 * section, %FALSE otherwise.
104 gboolean
TryEnterCriticalSection(WapiCriticalSection
*section
)
108 ret
=mono_mutex_trylock(§ion
->mutex
);