54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#if defined(OF_HAVE_RECURSIVE_PTHREAD_MUTEXES) || defined(OF_WINDOWS) || \
defined(OF_AMIGAOS)
# define of_rmutex_t of_mutex_t
#else
# import "tlskey.h"
typedef struct {
of_mutex_t mutex;
of_tlskey_t count;
} of_rmutex_t;
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern int of_mutex_new(of_mutex_t *mutex);
|
|
|
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#if defined(OF_HAVE_RECURSIVE_PTHREAD_MUTEXES) || defined(OF_WINDOWS) || \
defined(OF_AMIGAOS)
# define of_rmutex_t of_mutex_t
#else
# import "tlskey.h"
typedef struct {
of_mutex_t mutex;
OFTLSKey count;
} of_rmutex_t;
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern int of_mutex_new(of_mutex_t *mutex);
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#ifdef __cplusplus
}
#endif
/* Spinlocks are inlined for performance. */
static OF_INLINE void
of_thread_yield(void)
{
#if defined(OF_HAVE_SCHED_YIELD)
sched_yield();
#elif defined(OF_WINDOWS)
Sleep(0);
#endif
}
|
|
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#ifdef __cplusplus
}
#endif
/* Spinlocks are inlined for performance. */
static OF_INLINE void
OFYieldThread(void)
{
#if defined(OF_HAVE_SCHED_YIELD)
sched_yield();
#elif defined(OF_WINDOWS)
Sleep(0);
#endif
}
|
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
size_t i;
for (i = 0; i < OF_SPINCOUNT; i++)
if (of_spinlock_trylock(spinlock) == 0)
return 0;
while (of_spinlock_trylock(spinlock) == EBUSY)
of_thread_yield();
return 0;
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
return pthread_spin_lock(spinlock);
#else
return of_mutex_lock(spinlock);
#endif
|
|
|
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
size_t i;
for (i = 0; i < OF_SPINCOUNT; i++)
if (of_spinlock_trylock(spinlock) == 0)
return 0;
while (of_spinlock_trylock(spinlock) == EBUSY)
OFYieldThread();
return 0;
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
return pthread_spin_lock(spinlock);
#else
return of_mutex_lock(spinlock);
#endif
|