ObjFW  Check-in [f771ddda2d]

Overview
Comment:Add abstraction for conditions.

No support for Win32 yet, as we will need our own implementation of
conditions there.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f771ddda2d9bc44afdfaf136a9537965502b42d7792b0c84eb54c224a2b776c7
User & Date: js on 2011-03-07 15:39:48
Other Links: manifest | tags
Context
2011-03-07
16:00
Add class OFCondition. check-in: 615eb3e46b user: js tags: trunk
15:39
Add abstraction for conditions. check-in: f771ddda2d user: js tags: trunk
13:43
Throw an exception when trying to deallocate a locked mutex. check-in: f5515b0a1f user: js tags: trunk
Changes

Modified src/threading.h from [f35468bbe4] to [0b981f818f].

21
22
23
24
25
26
27

28
29
30
31
32
33
34

35
36
37
38
39
40
41
#endif

#import "macros.h"

#if defined(OF_HAVE_PTHREADS)
# include <pthread.h>
typedef pthread_t of_thread_t;

typedef pthread_mutex_t of_mutex_t;
typedef pthread_key_t of_tlskey_t;
#elif defined(_WIN32)
# include <windows.h>
typedef HANDLE of_thread_t;
typedef CRITICAL_SECTION of_mutex_t;
typedef DWORD of_tlskey_t;

#endif

#if defined(OF_ATOMIC_OPS)
# import "atomic.h"
typedef volatile int of_spinlock_t;
# define OF_SPINCOUNT 10
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)







>

|



<

>







21
22
23
24
25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
#endif

#import "macros.h"

#if defined(OF_HAVE_PTHREADS)
# include <pthread.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;
#elif defined(_WIN32)
# include <windows.h>
typedef HANDLE of_thread_t;

typedef DWORD of_tlskey_t;
typedef CRITICAL_SECTION of_mutex_t;
#endif

#if defined(OF_ATOMIC_OPS)
# import "atomic.h"
typedef volatile int of_spinlock_t;
# define OF_SPINCOUNT 10
#elif defined(OF_HAVE_PTHREAD_SPINLOCKS)
145
146
147
148
149
150
151


















































152
153
154
155
156
157
158
#if defined(OF_HAVE_PTHREADS)
	return (pthread_mutex_unlock(mutex) ? NO : YES);
#elif defined(_WIN32)
	LeaveCriticalSection(mutex);
	return YES;
#endif
}



















































static OF_INLINE BOOL
of_tlskey_new(of_tlskey_t *key)
{
#if defined(OF_HAVE_PTHREADS)
	return (pthread_key_create(key, NULL) ? NO : YES);
#elif defined(_WIN32)







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#if defined(OF_HAVE_PTHREADS)
	return (pthread_mutex_unlock(mutex) ? NO : YES);
#elif defined(_WIN32)
	LeaveCriticalSection(mutex);
	return YES;
#endif
}

static OF_INLINE BOOL
of_condition_new(of_condition_t *condition)
{
#if defined(OF_HAVE_PTHREADS)
	return (pthread_cond_init(condition, NULL) ? NO : YES);
#elif defined(_WIN32)
	// XXX
#endif
}

static OF_INLINE BOOL
of_condition_wait(of_condition_t *condition, of_mutex_t *mutex)
{
#if defined(OF_HAVE_PTHREADS)
	return (pthread_cond_wait(condition, mutex) ? NO : YES);
#elif defined(_WIN32)
	// XXX
#endif
}

static OF_INLINE BOOL
of_condition_signal(of_condition_t *condition)
{
#if defined(OF_HAVE_PTHREADS)
	return (pthread_cond_signal(condition) ? NO : YES);
#elif defined(_WIN32)
	// XXX
#endif
}

static OF_INLINE BOOL
of_condition_broadcast(of_condition_t *condition)
{
#if defined(OF_HAVE_PTHREADS)
	return (pthread_cond_broadcast(condition) ? NO : YES);
#elif defined(_WIN32)
	// XXX
#endif
}

static OF_INLINE BOOL
of_condition_free(of_condition_t *condition)
{
#if defined(OF_HAVE_PTHREADS)
	return (pthread_cond_destroy(condition) ? NO : YES);
#elif defined(_WIN32)
	// XXX
#endif
}

static OF_INLINE BOOL
of_tlskey_new(of_tlskey_t *key)
{
#if defined(OF_HAVE_PTHREADS)
	return (pthread_key_create(key, NULL) ? NO : YES);
#elif defined(_WIN32)