1 | /* |
---|
2 | * This file is part of libtrace |
---|
3 | * |
---|
4 | * Copyright (c) 2007-2015 The University of Waikato, Hamilton, |
---|
5 | * New Zealand. |
---|
6 | * |
---|
7 | * Authors: Richard Sanger |
---|
8 | * |
---|
9 | * All rights reserved. |
---|
10 | * |
---|
11 | * This code has been developed by the University of Waikato WAND |
---|
12 | * research group. For further information please see http://www.wand.net.nz/ |
---|
13 | * |
---|
14 | * libtrace is free software; you can redistribute it and/or modify |
---|
15 | * it under the terms of the GNU General Public License as published by |
---|
16 | * the Free Software Foundation; either version 2 of the License, or |
---|
17 | * (at your option) any later version. |
---|
18 | * |
---|
19 | * libtrace is distributed in the hope that it will be useful, |
---|
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
22 | * GNU General Public License for more details. |
---|
23 | * |
---|
24 | * You should have received a copy of the GNU General Public License |
---|
25 | * along with libtrace; if not, write to the Free Software |
---|
26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
27 | * |
---|
28 | * $Id$ |
---|
29 | * |
---|
30 | */ |
---|
31 | |
---|
32 | #ifdef __APPLE__ |
---|
33 | |
---|
34 | #include "pthread_spinlock.h" |
---|
35 | |
---|
36 | int pthread_spin_lock(pthread_spinlock_t *lock) { |
---|
37 | if (lock == NULL) |
---|
38 | return EINVAL; |
---|
39 | |
---|
40 | OSSpinLockLock(lock); |
---|
41 | return 0; |
---|
42 | } |
---|
43 | |
---|
44 | int pthread_spin_trylock(pthread_spinlock_t *lock) { |
---|
45 | if (lock == NULL) |
---|
46 | return EINVAL; |
---|
47 | |
---|
48 | if (OSSpinLockTry(lock)) { |
---|
49 | return 0; |
---|
50 | } else { |
---|
51 | return EBUSY; |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | int pthread_spin_unlock(pthread_spinlock_t *lock) { |
---|
56 | if (lock == NULL) |
---|
57 | return EINVAL; |
---|
58 | OSSpinLockUnlock(lock); |
---|
59 | return 0; |
---|
60 | } |
---|
61 | |
---|
62 | int pthread_spin_destroy(pthread_spinlock_t *lock) { |
---|
63 | if (*lock != 0) |
---|
64 | return EBUSY; |
---|
65 | return 0; |
---|
66 | } |
---|
67 | |
---|
68 | int pthread_spin_init(pthread_spinlock_t *lock, int pshared) { |
---|
69 | if (lock == NULL) |
---|
70 | return EINVAL; |
---|
71 | *lock = OS_SPINLOCK_INIT; |
---|
72 | (void)pshared; |
---|
73 | return 0; |
---|
74 | } |
---|
75 | |
---|
76 | #endif /* __APPLE__ */ |
---|