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
|