source: lib/pthread_spinlock.c @ c63bcdf

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivelibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since c63bcdf was c63bcdf, checked in by Richard Sanger <rsangerarj@…>, 6 years ago

Add pthread_spinlock so we can build on Apple's

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[c63bcdf]1/*
2 * This file is part of libtrace
3 *
4 * Copyright (c) 2007,2008,2009,2010 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#ifndef __PTHREAD_SPINLOCK_H
33#define __PTHREAD_SPINLOCK_H
34
35#ifdef __APPLE__
36
37#include "pthread_spinlock.h"
38
39typedef OSSpinLock pthread_spinlock_t;
40
41int pthread_spin_lock(pthread_spinlock_t *lock) {
42        if (lock == NULL)
43                return EINVAL;
44
45        OSSpinLockLock(lock);
46        return 0;
47}
48
49int pthread_spin_trylock(pthread_spinlock_t *lock) {
50        if (lock == NULL)
51                return EINVAL;
52
53        if (OSSpinLockTry(lock)) {
54                return 0;
55        } else {
56                return EBUSY;
57        }
58}
59
60int pthread_spin_unlock(pthread_spinlock_t *lock) {
61        if (lock == NULL)
62                return EINVAL;
63        OSSpinLockUnlock(lock);
64        return 0;
65}
66
67int pthread_spin_destroy(pthread_spinlock_t *lock) {
68        if (*lock != 0)
69                return EBUSY;
70        return 0;
71}
72
73int pthread_spin_init(pthread_spinlock_t *lock, int pshared) {
74        if (lock == NULL)
75                return EINVAL;
76        *lock = OS_SPINLOCK_INIT;
77        return 0;
78}
79
80#endif /* __APPLE__ */
81#endif /* __PTHREAD_SPINLOCK_H */
Note: See TracBrowser for help on using the repository browser.