Lines Matching full:mutex
17 * 11/22/99 aliu Make non-global mutex autoinitialize [j151]
73 * A note on ICU Mutex Initialization and ICU startup:
77 * of other ICU mutexes. For the global mutex itself, we need some other mechanism
80 * were racing into the mutex initialization code.
82 * The solution for the global mutex init is platform dependent.
83 * On POSIX systems, C-style init can be used on a mutex, with the
84 * macro PTHREAD_MUTEX_INITIALIZER. The mutex is then ready for use, without
87 * Windows has no equivalent statically initialized mutex or CRITICAL SECION.
88 * InitializeCriticalSection() must be called. If the global mutex does not
93 * If an application has overridden the ICU mutex implementation
96 * the same mutex. The first thread should do the init, and the others should
121 * the global mutex as well as for other mutexes in the pool.
134 * Note: Non-global mutex checking only happens if there is no custom
142 static int32_t gRecursionCount = 0; /* detect global mutex locking */
179 Note that user can still set mutex functions at run time,
180 and that the global mutex variable is still needed in that case. */
182 #error no ICU mutex implementation for this platform
191 * User mutex implementation functions. If non-null, call back to these rather than
207 umtx_lock(UMTX *mutex)
209 if (mutex == NULL) {
210 mutex = &gGlobalMutex;
213 if (*mutex == NULL) {
214 /* Lock of an uninitialized mutex. Initialize it before proceeding. */
215 umtx_init(mutex);
219 (*pMutexLockFn)(gMutexContext, mutex);
224 EnterCriticalSection((CRITICAL_SECTION*) *mutex);
226 pthread_mutex_lock((pthread_mutex_t*) *mutex);
232 if (mutex == &gGlobalMutex) { /* Detect Reentrant locking of the global mutex. */
238 size_t i = ((CRITICAL_SECTION*)*mutex) - &gMutexes[0];
246 U_ASSERT((CRITICAL_SECTION*)*mutex >= &gMutexes[0] &&
247 (CRITICAL_SECTION*)*mutex <= &gMutexes[MAX_MUTEXES]);
248 U_ASSERT(((CRITICAL_SECTION*)*mutex)->RecursionCount == 1);
260 umtx_unlock(UMTX* mutex)
262 if(mutex == NULL) {
263 mutex = &gGlobalMutex;
266 if(*mutex == NULL) {
268 U_ASSERT(FALSE); /* This mutex is not initialized. */
274 if (mutex == &gGlobalMutex) {
276 U_ASSERT(gRecursionCount == 0); /* Detect unlock of an already unlocked mutex */
280 size_t i = ((CRITICAL_SECTION*)*mutex) - &gMutexes[0];
289 U_ASSERT((CRITICAL_SECTION*)*mutex >= &gMutexes[0] &&
290 (CRITICAL_SECTION*)*mutex <= &gMutexes[MAX_MUTEXES]);
291 U_ASSERT(((CRITICAL_SECTION*)*mutex)->RecursionCount == 1);
297 (*pMutexUnlockFn)(gMutexContext, mutex);
301 LeaveCriticalSection((CRITICAL_SECTION*)*mutex);
303 pthread_mutex_unlock((pthread_mutex_t*)*mutex);
313 * initGlobalMutex Do the platform specific initialization of the ICU global mutex.
315 * Mutex storage is static for POSIX, init must be thread safe
316 * without the use of another mutex.
320 * If User Supplied mutex functions are in use
321 * init the icu global mutex using them.
335 /* No user override of mutex functions.
336 * Use default ICU mutex implementations.
371 * for both Windows & POSIX, the first mutex in the array is used
372 * for the ICU global mutex.
378 gGlobalMutex = &gGlobalMutex; /* With no threads, we must still set the mutex to
380 * (not ifdefed) mutex code think that it is initialized.
390 umtx_init(UMTX *mutex)
392 if (mutex == NULL || mutex == &gGlobalMutex) {
396 if (*mutex != NULL) {
397 /* Another thread initialized this mutex first. */
404 (*pMutexInitFn)(gMutexContext, mutex, &status);
417 *mutex = &gMutexes[i];
428 U_ASSERT(*mutex != NULL);
435 * umtx_destroy. Un-initialize a mutex, releasing any underlying resources
437 * mutex has no effect. Unlike umtx_init(), this function
439 * destroy the same mutex.
442 umtx_destroy(UMTX *mutex) {
443 if (mutex == NULL) { /* destroy the global mutex */
444 mutex = &gGlobalMutex;
447 if (*mutex == NULL) { /* someone already did it. */
451 /* The life of the inc/dec mutex is tied to that of the global mutex. */
452 if (mutex == &gGlobalMutex) {
458 (*pMutexDestroyFn)(gMutexContext, mutex);
462 /* Return this mutex to the pool of available mutexes, if it came from the
468 if (*mutex == &gMutexes[i]) {
476 *mutex = NULL;
488 /* Can not set a mutex function to a NULL value */
500 /* Swap in the mutex function pointers. */
506 mutex will be pre-initialized */
583 /* Can not set a mutex function to a NULL value */
612 * Mutex Cleanup Function
614 * Destroy the global mutex(es), and reset the mutex function callback pointers.