EFL 1.7 svn doobies
[profile/ivi/eina.git] / src / include / eina_inline_lock_wince.x
1 /* EINA - EFL data type library
2  * Copyright (C) 2011 Vincent Torri
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library;
16  * if not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifndef EINA_INLINE_LOCK_WIN32_X_
20 #define EINA_INLINE_LOCK_WIN32_X_
21
22 #ifdef EINA_UNUSED
23 # undef EINA_UNUSED
24 #endif
25 #ifdef __GNUC__
26 # define EINA_UNUSED __attribute__((unused))
27 #else
28 # define EINA_UNUSED
29 #endif
30
31 #include <windows.h>
32
33 EAPI extern Eina_Bool _threads_activated;
34
35 typedef HANDLE    Eina_Lock;
36 typedef Eina_Lock Eina_RWLock;
37 typedef DWORD     Eina_TLS;
38 typedef void *    Eina_Semaphore;
39
40 static inline Eina_Bool
41 eina_lock_new(Eina_Lock *mutex)
42 {
43    Eina_Lock m;
44
45    m = CreateMutex(NULL, FALSE, NULL);
46    if (m) *mutex = m;
47    return (m != NULL);
48 }
49
50 static inline void
51 eina_lock_free(Eina_Lock *mutex)
52 {
53    CloseHandle(*mutex);
54 }
55
56 static inline Eina_Lock_Result
57 eina_lock_take(Eina_Lock *mutex)
58 {
59    DWORD res;
60
61 #ifdef EINA_HAVE_ON_OFF_THREADS
62    if (!_eina_threads_activated) return EINA_LOCK_FAIL;
63 #endif
64
65    res = WaitForSingleObject(*mutex, INFINITE);
66    if ((res == WAIT_ABANDONED) || (res == WAIT_FAILED))
67      return EINA_LOCK_FAIL;
68
69    return EINA_LOCK_SUCCEED;
70 }
71
72 static inline Eina_Lock_Result
73 eina_lock_take_try(Eina_Lock *mutex)
74 {
75    return eina_lock_take(*mutex);
76 }
77
78 static inline Eina_Lock_Result
79 eina_lock_release(Eina_Lock *mutex)
80 {
81 #ifdef EINA_HAVE_ON_OFF_THREADS
82    if (!_eina_threads_activated) return ;
83 #endif
84
85    return ReleaseMutex(*mutex) ? EINA_LOCK_SUCCEED : EINA_LOCK_FAIL;
86 }
87
88 static inline void
89 eina_lock_debug(const Eina_Lock *mutex)
90 {
91 }
92
93 static inline Eina_Bool
94 eina_condition_new(Eina_Condition *cond, Eina_Lock *mutex)
95 {
96    return EINA_FALSE;
97 }
98
99 static inline void
100 eina_condition_free(Eina_Condition *cond)
101 {
102 }
103
104 static inline Eina_Bool
105 eina_condition_wait(Eina_Condition *cond)
106 {
107    return EINA_FALSE;
108 }
109
110 static inline Eina_Bool
111 eina_condition_timedwait(Eina_Condition *cond, double t)
112 {
113    return EINA_FALSE;
114 }
115
116 static inline Eina_Bool
117 eina_condition_broadcast(Eina_Condition *cond)
118 {
119    return EINA_FALSE;
120 }
121
122 static inline Eina_Bool
123 eina_condition_signal(Eina_Condition *cond)
124 {
125    return EINA_FALSE;
126 }
127
128 static inline Eina_Bool
129 eina_rwlock_new(Eina_RWLock *mutex)
130 {
131    return eina_lock_new(mutex);
132 }
133
134 static inline void
135 eina_rwlock_free(Eina_RWLock *mutex)
136 {
137    return eina_lock_free(mutex);
138 }
139
140 static inline Eina_Lock_Result
141 eina_rwlock_take_read(Eina_RWLock *mutex)
142 {
143    return eina_lock_take(mutex);
144 }
145
146 static inline Eina_Lock_Result
147 eina_rwlock_take_write(Eina_RWLock *mutex)
148 {
149    return eina_lock_take(mutex);
150 }
151
152 static inline Eina_Lock_Result
153 eina_rwlock_release(Eina_RWLock *mutex)
154 {
155    return eina_lock_release(mutex);
156 }
157
158 static inline Eina_Bool 
159 eina_tls_new(Eina_TLS *key)
160 {
161    if (TlsAlloc() == TLS_OUT_OF_INDEXES)
162       return EINA_FALSE;
163    return EINA_TRUE;
164 }
165
166 static inline void 
167 eina_tls_free(Eina_TLS key)
168 {
169    TlsFree(key);
170 }
171
172 static inline void *
173 eina_tls_get(Eina_TLS key)
174 {
175    return (void*)TlsGetValue(key);
176 }
177
178 static inline Eina_Bool 
179 eina_tls_set(Eina_TLS key, const void *data)
180 {
181    if (TlsSetValue(key, (LPVOID)data) == 0)
182       return EINA_FALSE;
183    return EINA_TRUE;
184 }
185
186 static inline Eina_Bool
187 eina_semaphore_new(Eina_Semaphore *sem EINA_UNUSED,
188                    int count_init EINA_UNUSED)
189 {
190    return EINA_FALSE;
191 }
192
193 static inline Eina_Bool
194 eina_semaphore_free(Eina_Semaphore *sem EINA_UNUSED)
195 {
196    return EINA_FALSE;
197 }
198
199 static inline Eina_Bool
200 eina_semaphore_lock(Eina_Semaphore *sem EINA_UNUSED)
201 {
202    return EINA_FALSE;
203 }
204
205 static inline Eina_Bool
206 eina_semaphore_release(Eina_Semaphore *sem EINA_UNUSED,
207                        int count_release EINA_UNUSED)
208 {
209    return EINA_FALSE;
210 }
211
212 #endif