45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# define OF_SPINCOUNT 10
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
typedef pthread_spinlock_t of_spinlock_t;
#else
typedef of_mutex_t of_spinlock_t;
#endif
typedef struct {
of_mutex_t mutex;
of_tlskey_t count;
} of_rmutex_t;
#if defined(OF_HAVE_PTHREADS)
# define of_thread_is_current(t) pthread_equal(t, pthread_self())
# define of_thread_current pthread_self
#elif defined(_WIN32)
# define of_thread_is_current(t) (t == GetCurrentThread())
# define of_thread_current GetCurrentThread
|
>
>
>
>
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# define OF_SPINCOUNT 10
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
typedef pthread_spinlock_t of_spinlock_t;
#else
typedef of_mutex_t of_spinlock_t;
#endif
#ifdef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES
# define of_rmutex_t of_mutex_t
#else
typedef struct {
of_mutex_t mutex;
of_tlskey_t count;
} of_rmutex_t;
#endif
#if defined(OF_HAVE_PTHREADS)
# define of_thread_is_current(t) pthread_equal(t, pthread_self())
# define of_thread_current pthread_self
#elif defined(_WIN32)
# define of_thread_is_current(t) (t == GetCurrentThread())
# define of_thread_current GetCurrentThread
|
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
return !pthread_spin_destroy(spinlock);
#else
return of_mutex_free(spinlock);
#endif
}
static OF_INLINE BOOL
of_rmutex_new(of_rmutex_t *rmutex)
{
if (!of_mutex_new(&rmutex->mutex))
return NO;
if (!of_tlskey_new(&rmutex->count))
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
return !pthread_spin_destroy(spinlock);
#else
return of_mutex_free(spinlock);
#endif
}
#ifdef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES
static OF_INLINE BOOL
of_rmutex_new(of_mutex_t *mutex)
{
pthread_mutexattr_t attr;
if (pthread_mutexattr_init(&attr))
return NO;
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE))
return NO;
if (pthread_mutex_init(mutex, &attr))
return NO;
if (pthread_mutexattr_destroy(&attr))
return NO;
return YES;
}
# define of_rmutex_lock of_mutex_lock
# define of_rmutex_unlock of_mutex_unlock
# define of_rmutex_free of_mutex_free
#else
static OF_INLINE BOOL
of_rmutex_new(of_rmutex_t *rmutex)
{
if (!of_mutex_new(&rmutex->mutex))
return NO;
if (!of_tlskey_new(&rmutex->count))
|
430
431
432
433
434
435
436
|
return NO;
if (!of_tlskey_free(rmutex->count))
return NO;
return YES;
}
|
>
|
459
460
461
462
463
464
465
466
|
return NO;
if (!of_tlskey_free(rmutex->count))
return NO;
return YES;
}
#endif
|