|
1 /* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 * |
|
3 * Permission is hereby granted, free of charge, to any person obtaining a |
|
4 * copy of this software and associated documentation files (the "Software"), |
|
5 * to deal in the Software without restriction, including without limitation |
|
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|
7 * and/or sell copies of the Software, and to permit persons to whom the |
|
8 * Software is furnished to do so, subject to the following conditions: |
|
9 * |
|
10 * The above copyright notice and this permission notice shall be included |
|
11 * in all copies or substantial portions of the Software. |
|
12 * |
|
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
|
14 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|
16 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
|
17 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
|
18 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
19 * |
|
20 * Initial Contributors: |
|
21 * Nokia Corporation - initial contribution. |
|
22 * |
|
23 * Contributors: |
|
24 * |
|
25 * Description: |
|
26 * |
|
27 */ |
|
28 |
|
29 #include "common.h" |
|
30 #include "platform.h" |
|
31 |
|
32 static int dgl_lock_initialized = 0; |
|
33 static DGLES2_LOCK dgl_lock; |
|
34 |
|
35 #ifdef _WIN32 |
|
36 static void dglInitializeLock(void) |
|
37 { |
|
38 InitializeCriticalSection(&dgl_lock); |
|
39 dgl_lock_initialized = 1; |
|
40 } |
|
41 |
|
42 void dglGetLock(void) |
|
43 { |
|
44 if(!dgl_lock_initialized) |
|
45 { |
|
46 dglInitializeLock(); |
|
47 } |
|
48 EnterCriticalSection(&dgl_lock); |
|
49 } |
|
50 |
|
51 void dglReleaseLock(void) |
|
52 { |
|
53 DGLES2_ASSERT(dgl_lock_initialized); |
|
54 LeaveCriticalSection(&dgl_lock); |
|
55 } |
|
56 #else /* _WIN32 */ |
|
57 static void initializeLock() |
|
58 { |
|
59 int ret; |
|
60 |
|
61 DGLES2_ASSERT(!dgl_lock_initialized); |
|
62 |
|
63 pthread_mutexattr_t attr; |
|
64 ret = pthread_mutexattr_init(&attr); //initially not locked |
|
65 DGLES2_ASSERT(!ret); //check that there aren't any errors |
|
66 ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); //count the number of recursive locks |
|
67 DGLES2_ASSERT(!ret); //check that there aren't any errors |
|
68 ret = pthread_mutex_init(&dgl_lock, &attr); |
|
69 pthread_mutexattr_destroy(&attr); |
|
70 DGLES2_ASSERT(!ret); //check that there aren't more errors |
|
71 |
|
72 dgl_lock_initialized = 1; |
|
73 } |
|
74 |
|
75 void glesGetLock() |
|
76 { |
|
77 if(!dgl_lock_initialized) |
|
78 { |
|
79 initializeLock(); |
|
80 } |
|
81 int ret = pthread_mutex_lock(&dgl_lock); |
|
82 DGLES2_ASSERT(!ret); |
|
83 } |
|
84 |
|
85 void glesReleaseLock() |
|
86 { |
|
87 DGLES2_ASSERT(dgl_lock_initialized); |
|
88 int ret = pthread_mutex_unlock(&dgl_lock); |
|
89 DGLES2_ASSERT(!ret); |
|
90 } |
|
91 #endif |