1 /*
2 * Copyright 2012-2013 Michael Steinert
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23 #include "threads.h"
24
25 #include <stdlib.h>
26
pthread_self(void)27 DWORD pthread_self(void) { return GetCurrentThreadId(); }
28
pthread_mutex_init(pthread_mutex_t * mutex,void * attr)29 int pthread_mutex_init(pthread_mutex_t *mutex, void *attr) {
30 if (!mutex) {
31 return 1;
32 }
33 InitializeSRWLock(mutex);
34 return 0;
35 }
36
pthread_mutex_lock(pthread_mutex_t * mutex)37 int pthread_mutex_lock(pthread_mutex_t *mutex) {
38 if (!mutex) {
39 return 1;
40 }
41 AcquireSRWLockExclusive(mutex);
42 return 0;
43 }
44
pthread_mutex_unlock(pthread_mutex_t * mutex)45 int pthread_mutex_unlock(pthread_mutex_t *mutex) {
46 if (!mutex) {
47 return 1;
48 }
49 ReleaseSRWLockExclusive(mutex);
50 return 0;
51 }
52
pthread_mutex_destroy(pthread_mutex_t * mutex)53 int pthread_mutex_destroy(pthread_mutex_t *mutex) {
54 /* SRW's do not require destruction. */
55 return 0;
56 }
57