threads.h
Go to the documentation of this file.
1 #pragma once
7 #ifndef KRK_DISABLE_THREADS
8 #include <pthread.h>
9 #include <sched.h>
10 
11 #ifdef _WIN32
12 #include <windows.h>
13 #include <winnt.h>
14 #define sched_yield() YieldProcessor()
15 #endif
16 
17 static inline void _krk_internal_spin_lock(int volatile * lock) {
18  while(__sync_lock_test_and_set(lock, 0x01)) {
19  sched_yield();
20  }
21 }
22 
23 static inline void _krk_internal_spin_unlock(int volatile * lock) {
24  __sync_lock_release(lock);
25 }
26 
27 #define _obtain_lock(v) _krk_internal_spin_lock(&v);
28 #define _release_lock(v) _krk_internal_spin_unlock(&v);
29 
30 #else
31 
32 #define _obtain_lock(v)
33 #define _release_lock(v)
34 
35 #define pthread_rwlock_init(a,b) ((void)0)
36 #define pthread_rwlock_wrlock(a) ((void)0)
37 #define pthread_rwlock_rdlock(a) ((void)0)
38 #define pthread_rwlock_unlock(a) ((void)0)
39 
40 #endif
41