Differences From Artifact [9b92c5e911]:
- File
src/threading.h
— part of check-in
[ffb39d1df6]
at
2015-03-30 21:33:29
on branch trunk
— Add OF_NO_RETURN_FUNC
OF_NO_RETURN_FUNC is defined when __attribute__((__noreturn__)) is
supported for functions, whereas OF_NO_RETURN is only defined when it is
supported for both functions and methods. (user: js, size: 6484) [annotate] [blame] [check-ins using]
To Artifact [ddfe6e7a81]:
- File src/threading.h — part of check-in [1ba08eebc5] at 2015-10-19 22:15:13 on branch trunk — Add platform.h & make platform defines consistent (user: js, size: 6548) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
10 11 12 13 14 15 16 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ | | > > | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "objfw-defs.h" #include "platform.h" #if !defined(OF_HAVE_THREADS) || \ (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS)) # error No threads available! #endif #include <math.h> #import "OFObject.h" #if defined(OF_HAVE_PTHREADS) # include <pthread.h> # include <sched.h> typedef pthread_t of_thread_t; typedef pthread_key_t of_tlskey_t; typedef pthread_mutex_t of_mutex_t; typedef pthread_cond_t of_condition_t; typedef pthread_once_t of_once_t; # define OF_ONCE_INIT PTHREAD_ONCE_INIT #elif defined(OF_WINDOWS) /* * winsock2.h needs to be included before windows.h. Not including it here * would make it impossible to use sockets after threading.h has been * imported. */ # ifdef OF_HAVE_SOCKETS # include <winsock2.h> |
︙ | ︙ | |||
67 68 69 70 71 72 73 | typedef of_mutex_t of_spinlock_t; #endif #ifdef OF_HAVE_SCHED_YIELD # include <sched.h> #endif | | | | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | typedef of_mutex_t of_spinlock_t; #endif #ifdef OF_HAVE_SCHED_YIELD # include <sched.h> #endif #if defined(OF_HAVE_RECURSIVE_PTHREAD_MUTEXES) || defined(OF_WINDOWS) # define of_rmutex_t of_mutex_t #else typedef struct { of_mutex_t mutex; of_tlskey_t count; } of_rmutex_t; #endif typedef struct of_thread_attr_t { float priority; size_t stackSize; } of_thread_attr_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(OF_WINDOWS) # define of_thread_is_current(t) (t == GetCurrentThread()) # define of_thread_current GetCurrentThread #else # error of_thread_is_current not implemented! # error of_thread_current not implemented! #endif |
︙ | ︙ | |||
125 126 127 128 129 130 131 | /* TLS keys and spinlocks are inlined for performance. */ static OF_INLINE bool of_tlskey_new(of_tlskey_t *key) { #if defined(OF_HAVE_PTHREADS) return !pthread_key_create(key, NULL); | | | | | | 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | /* TLS keys and spinlocks are inlined for performance. */ static OF_INLINE bool of_tlskey_new(of_tlskey_t *key) { #if defined(OF_HAVE_PTHREADS) return !pthread_key_create(key, NULL); #elif defined(OF_WINDOWS) return ((*key = TlsAlloc()) != TLS_OUT_OF_INDEXES); #else # error of_tlskey_new not implemented! #endif } static OF_INLINE void* of_tlskey_get(of_tlskey_t key) { #if defined(OF_HAVE_PTHREADS) return pthread_getspecific(key); #elif defined(OF_WINDOWS) return TlsGetValue(key); #else # error of_tlskey_get not implemented! #endif } static OF_INLINE bool of_tlskey_set(of_tlskey_t key, void *ptr) { #if defined(OF_HAVE_PTHREADS) return !pthread_setspecific(key, ptr); #elif defined(OF_WINDOWS) return TlsSetValue(key, ptr); #else # error of_tlskey_set not implemented! #endif } static OF_INLINE bool of_tlskey_free(of_tlskey_t key) { #if defined(OF_HAVE_PTHREADS) return !pthread_key_delete(key); #elif defined(OF_WINDOWS) return TlsFree(key); #else # error of_tlskey_free not implemented! #endif } static OF_INLINE bool |
︙ | ︙ | |||
197 198 199 200 201 202 203 | #endif } static OF_INLINE bool of_spinlock_lock(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) | | | | 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | #endif } static OF_INLINE bool of_spinlock_lock(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) # if defined(OF_HAVE_SCHED_YIELD) || defined(OF_WINDOWS) int i; for (i = 0; i < OF_SPINCOUNT; i++) if (of_spinlock_trylock(spinlock)) return true; while (!of_spinlock_trylock(spinlock)) # ifndef OF_WINDOWS sched_yield(); # else Sleep(0); # endif # else while (!of_spinlock_trylock(spinlock)); # endif |
︙ | ︙ |