diff options
author | David Walter Seikel | 2012-04-22 09:19:23 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-04-22 09:19:23 +1000 |
commit | c963d75dfdeec11f82e79e727062fbf89afa2c04 (patch) | |
tree | 895633dbf641110be46f117c29890c49b3ffc0bd /libraries/eina/src/include/eina_inline_lock_win32.x | |
parent | Adding the new extantz viewer and grid manager. (diff) | |
download | SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.zip SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.gz SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.bz2 SledjHamr-c963d75dfdeec11f82e79e727062fbf89afa2c04.tar.xz |
Update EFL to latest beta.
Diffstat (limited to 'libraries/eina/src/include/eina_inline_lock_win32.x')
-rw-r--r-- | libraries/eina/src/include/eina_inline_lock_win32.x | 70 |
1 files changed, 54 insertions, 16 deletions
diff --git a/libraries/eina/src/include/eina_inline_lock_win32.x b/libraries/eina/src/include/eina_inline_lock_win32.x index e8363d5..1988724 100644 --- a/libraries/eina/src/include/eina_inline_lock_win32.x +++ b/libraries/eina/src/include/eina_inline_lock_win32.x | |||
@@ -23,6 +23,9 @@ | |||
23 | 23 | ||
24 | typedef CRITICAL_SECTION Eina_Lock; | 24 | typedef CRITICAL_SECTION Eina_Lock; |
25 | typedef struct _Eina_Condition Eina_Condition; | 25 | typedef struct _Eina_Condition Eina_Condition; |
26 | typedef struct _Eina_RWLock Eina_RWLock; | ||
27 | typedef DWORD Eina_TLS; | ||
28 | typedef HANDLE Eina_Semaphore; | ||
26 | 29 | ||
27 | #if _WIN32_WINNT >= 0x0600 | 30 | #if _WIN32_WINNT >= 0x0600 |
28 | struct _Eina_Condition | 31 | struct _Eina_Condition |
@@ -30,6 +33,13 @@ struct _Eina_Condition | |||
30 | CRITICAL_SECTION *mutex; | 33 | CRITICAL_SECTION *mutex; |
31 | CONDITION_VARIABLE condition; | 34 | CONDITION_VARIABLE condition; |
32 | }; | 35 | }; |
36 | |||
37 | struct _Eina_RWLock | ||
38 | { | ||
39 | SRWLOCK mutex; | ||
40 | |||
41 | Eina_Bool is_read_mode : 1; | ||
42 | }; | ||
33 | #else | 43 | #else |
34 | struct _Eina_Condition | 44 | struct _Eina_Condition |
35 | { | 45 | { |
@@ -40,28 +50,24 @@ struct _Eina_Condition | |||
40 | HANDLE waiters_done; | 50 | HANDLE waiters_done; |
41 | Eina_Bool was_broadcast; | 51 | Eina_Bool was_broadcast; |
42 | }; | 52 | }; |
43 | #endif | ||
44 | 53 | ||
45 | typedef struct _Eina_Win32_RWLock Eina_RWLock; | 54 | struct _Eina_RWLock |
46 | |||
47 | struct _Eina_Win32_RWLock | ||
48 | { | 55 | { |
49 | LONG readers_count; | 56 | LONG readers_count; |
50 | LONG writers_count; | 57 | LONG writers_count; |
51 | int readers; | 58 | int readers; |
52 | int writers; | 59 | int writers; |
53 | 60 | ||
54 | Eina_Lock mutex; | 61 | Eina_Lock mutex; |
55 | Eina_Condition cond_read; | 62 | Eina_Condition cond_read; |
56 | Eina_Condition cond_write; | 63 | Eina_Condition cond_write; |
57 | }; | 64 | }; |
65 | #endif | ||
58 | 66 | ||
59 | typedef DWORD Eina_TLS; | ||
60 | |||
61 | typedef HANDLE Eina_Semaphore; | ||
62 | 67 | ||
63 | EAPI extern Eina_Bool _eina_threads_activated; | 68 | EAPI extern Eina_Bool _eina_threads_activated; |
64 | 69 | ||
70 | |||
65 | static inline Eina_Bool | 71 | static inline Eina_Bool |
66 | eina_lock_new(Eina_Lock *mutex) | 72 | eina_lock_new(Eina_Lock *mutex) |
67 | { | 73 | { |
@@ -143,9 +149,9 @@ eina_condition_new(Eina_Condition *cond, Eina_Lock *mutex) | |||
143 | CloseHandle(cond->semaphore); | 149 | CloseHandle(cond->semaphore); |
144 | return EINA_FALSE; | 150 | return EINA_FALSE; |
145 | } | 151 | } |
152 | #endif | ||
146 | 153 | ||
147 | return EINA_TRUE; | 154 | return EINA_TRUE; |
148 | #endif | ||
149 | } | 155 | } |
150 | 156 | ||
151 | static inline void | 157 | static inline void |
@@ -153,6 +159,7 @@ eina_condition_free(Eina_Condition *cond) | |||
153 | { | 159 | { |
154 | #if _WIN32_WINNT >= 0x0600 | 160 | #if _WIN32_WINNT >= 0x0600 |
155 | /* Nothing to do */ | 161 | /* Nothing to do */ |
162 | (void)cond; | ||
156 | #else | 163 | #else |
157 | CloseHandle(cond->waiters_done); | 164 | CloseHandle(cond->waiters_done); |
158 | DeleteCriticalSection(&cond->waiters_count_lock); | 165 | DeleteCriticalSection(&cond->waiters_count_lock); |
@@ -309,20 +316,29 @@ eina_condition_signal(Eina_Condition *cond) | |||
309 | if (!ReleaseSemaphore(cond->semaphore, 1, 0)) | 316 | if (!ReleaseSemaphore(cond->semaphore, 1, 0)) |
310 | return EINA_FALSE; | 317 | return EINA_FALSE; |
311 | } | 318 | } |
319 | #endif | ||
312 | 320 | ||
313 | return EINA_TRUE; | 321 | return EINA_TRUE; |
314 | #endif | ||
315 | } | 322 | } |
316 | 323 | ||
317 | static inline Eina_Bool | 324 | static inline Eina_Bool |
318 | eina_rwlock_new(Eina_RWLock *mutex) | 325 | eina_rwlock_new(Eina_RWLock *mutex) |
319 | { | 326 | { |
327 | #if _WIN32_WINNT >= 0x0600 | ||
328 | InitializeSRWLock(&mutex->mutex); | ||
329 | return EINA_TRUE; | ||
330 | #else | ||
320 | if (!eina_lock_new(&(mutex->mutex))) return EINA_FALSE; | 331 | if (!eina_lock_new(&(mutex->mutex))) return EINA_FALSE; |
321 | if (!eina_condition_new(&(mutex->cond_read), &(mutex->mutex))) | 332 | if (!eina_condition_new(&(mutex->cond_read), &(mutex->mutex))) |
322 | goto on_error1; | 333 | goto on_error1; |
323 | if (!eina_condition_new(&(mutex->cond_write), &(mutex->mutex))) | 334 | if (!eina_condition_new(&(mutex->cond_write), &(mutex->mutex))) |
324 | goto on_error2; | 335 | goto on_error2; |
325 | 336 | ||
337 | mutex->readers_count = 0; | ||
338 | mutex->writers_count = 0; | ||
339 | mutex->readers = 0; | ||
340 | mutex->writers = 0; | ||
341 | |||
326 | return EINA_TRUE; | 342 | return EINA_TRUE; |
327 | 343 | ||
328 | on_error2: | 344 | on_error2: |
@@ -330,20 +346,29 @@ eina_rwlock_new(Eina_RWLock *mutex) | |||
330 | on_error1: | 346 | on_error1: |
331 | eina_lock_free(&(mutex->mutex)); | 347 | eina_lock_free(&(mutex->mutex)); |
332 | return EINA_FALSE; | 348 | return EINA_FALSE; |
349 | #endif | ||
333 | } | 350 | } |
334 | 351 | ||
335 | static inline void | 352 | static inline void |
336 | eina_rwlock_free(Eina_RWLock *mutex) | 353 | eina_rwlock_free(Eina_RWLock *mutex) |
337 | { | 354 | { |
355 | #if _WIN32_WINNT >= 0x0600 | ||
356 | (void)mutex; | ||
357 | #else | ||
338 | eina_condition_free(&(mutex->cond_read)); | 358 | eina_condition_free(&(mutex->cond_read)); |
339 | eina_condition_free(&(mutex->cond_write)); | 359 | eina_condition_free(&(mutex->cond_write)); |
340 | eina_lock_free(&(mutex->mutex)); | 360 | eina_lock_free(&(mutex->mutex)); |
361 | #endif | ||
341 | } | 362 | } |
342 | 363 | ||
343 | static inline Eina_Lock_Result | 364 | static inline Eina_Lock_Result |
344 | eina_rwlock_take_read(Eina_RWLock *mutex) | 365 | eina_rwlock_take_read(Eina_RWLock *mutex) |
345 | { | 366 | { |
346 | DWORD res; | 367 | #if _WIN32_WINNT >= 0x0600 |
368 | AcquireSRWLockShared(&mutex->mutex); | ||
369 | mutex->is_read_mode = EINA_TRUE; | ||
370 | #else | ||
371 | DWORD res = 0; | ||
347 | 372 | ||
348 | if (eina_lock_take(&(mutex->mutex)) == EINA_LOCK_FAIL) | 373 | if (eina_lock_take(&(mutex->mutex)) == EINA_LOCK_FAIL) |
349 | return EINA_LOCK_FAIL; | 374 | return EINA_LOCK_FAIL; |
@@ -364,6 +389,7 @@ eina_rwlock_take_read(Eina_RWLock *mutex) | |||
364 | if (res == 0) | 389 | if (res == 0) |
365 | mutex->readers++; | 390 | mutex->readers++; |
366 | eina_lock_release(&(mutex->mutex)); | 391 | eina_lock_release(&(mutex->mutex)); |
392 | #endif | ||
367 | 393 | ||
368 | return EINA_LOCK_SUCCEED; | 394 | return EINA_LOCK_SUCCEED; |
369 | } | 395 | } |
@@ -371,7 +397,11 @@ eina_rwlock_take_read(Eina_RWLock *mutex) | |||
371 | static inline Eina_Lock_Result | 397 | static inline Eina_Lock_Result |
372 | eina_rwlock_take_write(Eina_RWLock *mutex) | 398 | eina_rwlock_take_write(Eina_RWLock *mutex) |
373 | { | 399 | { |
374 | DWORD res; | 400 | #if _WIN32_WINNT >= 0x0600 |
401 | AcquireSRWLockExclusive(&mutex->mutex); | ||
402 | mutex->is_read_mode = EINA_FALSE; | ||
403 | #else | ||
404 | DWORD res = 0; | ||
375 | 405 | ||
376 | if (eina_lock_take(&(mutex->mutex)) == EINA_LOCK_FAIL) | 406 | if (eina_lock_take(&(mutex->mutex)) == EINA_LOCK_FAIL) |
377 | return EINA_LOCK_FAIL; | 407 | return EINA_LOCK_FAIL; |
@@ -389,8 +419,9 @@ eina_rwlock_take_write(Eina_RWLock *mutex) | |||
389 | } | 419 | } |
390 | mutex->writers_count--; | 420 | mutex->writers_count--; |
391 | } | 421 | } |
392 | if (res == 0) mutex->writers_count = 1; | 422 | if (res == 0) mutex->writers = 1; |
393 | eina_lock_release(&(mutex->mutex)); | 423 | eina_lock_release(&(mutex->mutex)); |
424 | #endif | ||
394 | 425 | ||
395 | return EINA_LOCK_SUCCEED; | 426 | return EINA_LOCK_SUCCEED; |
396 | } | 427 | } |
@@ -398,6 +429,12 @@ eina_rwlock_take_write(Eina_RWLock *mutex) | |||
398 | static inline Eina_Lock_Result | 429 | static inline Eina_Lock_Result |
399 | eina_rwlock_release(Eina_RWLock *mutex) | 430 | eina_rwlock_release(Eina_RWLock *mutex) |
400 | { | 431 | { |
432 | #if _WIN32_WINNT >= 0x0600 | ||
433 | if (mutex->is_read_mode) | ||
434 | ReleaseSRWLockShared(&mutex->mutex); | ||
435 | else | ||
436 | ReleaseSRWLockExclusive(&mutex->mutex); | ||
437 | #else | ||
401 | if (eina_lock_take(&(mutex->mutex)) == EINA_LOCK_FAIL) | 438 | if (eina_lock_take(&(mutex->mutex)) == EINA_LOCK_FAIL) |
402 | return EINA_LOCK_FAIL; | 439 | return EINA_LOCK_FAIL; |
403 | 440 | ||
@@ -433,6 +470,7 @@ eina_rwlock_release(Eina_RWLock *mutex) | |||
433 | } | 470 | } |
434 | } | 471 | } |
435 | eina_lock_release(&(mutex->mutex)); | 472 | eina_lock_release(&(mutex->mutex)); |
473 | #endif | ||
436 | 474 | ||
437 | return EINA_LOCK_SUCCEED; | 475 | return EINA_LOCK_SUCCEED; |
438 | } | 476 | } |