1/* 2Copyright (c) 2001 Wolfram Gloger 3Copyright (c) 2006 Cavium networks 4 5Permission to use, copy, modify, distribute, and sell this software 6and its documentation for any purpose is hereby granted without fee, 7provided that (i) the above copyright notices and this permission 8notice appear in all copies of the software and related documentation, 9and (ii) the name of Wolfram Gloger may not be used in any advertising 10or publicity relating to the software. 11 12THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 13EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 14WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 15 16IN NO EVENT SHALL WOLFRAM GLOGER BE LIABLE FOR ANY SPECIAL, 17INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY 18DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 19WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY 20OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 21PERFORMANCE OF THIS SOFTWARE. 22*/ 23 24/* $Id: thread-m.h 30481 2007-12-05 21:46:59Z rfranz $ 25 One out of _LIBC, USE_PTHREADS, USE_THR or USE_SPROC should be 26 defined, otherwise the token NO_THREADS and dummy implementations 27 of the macros will be defined. */ 28 29#ifndef _THREAD_M_H 30#define _THREAD_M_H 31 32#undef thread_atfork_static 33 34 35#undef NO_THREADS /* No threads, provide dummy macros */ 36 37typedef int thread_id; 38 39/* The mutex functions used to do absolutely nothing, i.e. lock, 40 trylock and unlock would always just return 0. However, even 41 without any concurrently active threads, a mutex can be used 42 legitimately as an `in use' flag. To make the code that is 43 protected by a mutex async-signal safe, these macros would have to 44 be based on atomic test-and-set operations, for example. */ 45#ifdef __OCTEON__ 46typedef cvmx_spinlock_t mutex_t; 47#define MUTEX_INITIALIZER CMVX_SPINLOCK_UNLOCKED_VAL 48#define mutex_init(m) cvmx_spinlock_init(m) 49#define mutex_lock(m) cvmx_spinlock_lock(m) 50#define mutex_trylock(m) (cvmx_spinlock_trylock(m)) 51#define mutex_unlock(m) cvmx_spinlock_unlock(m) 52#else 53 54typedef int mutex_t; 55 56#define MUTEX_INITIALIZER 0 57#define mutex_init(m) (*(m) = 0) 58#define mutex_lock(m) ((*(m) = 1), 0) 59#define mutex_trylock(m) (*(m) ? 1 : ((*(m) = 1), 0)) 60#define mutex_unlock(m) (*(m) = 0) 61#endif 62 63 64 65typedef void *tsd_key_t; 66#define tsd_key_create(key, destr) do {} while(0) 67#define tsd_setspecific(key, data) ((key) = (data)) 68#define tsd_getspecific(key, vptr) (vptr = (key)) 69 70#define thread_atfork(prepare, parent, child) do {} while(0) 71 72 73#endif /* !defined(_THREAD_M_H) */ 74