00001 /* Threads compatibility routines for libgcc2 and libobjc for VxWorks. */ 00002 /* Compile this one with gcc. */ 00003 /* Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc. 00004 Contributed by Mike Stump <mrs@wrs.com>. 00005 00006 This file is part of GCC. 00007 00008 GCC is free software; you can redistribute it and/or modify it under 00009 the terms of the GNU General Public License as published by the Free 00010 Software Foundation; either version 2, or (at your option) any later 00011 version. 00012 00013 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 00014 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00015 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00016 for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with GCC; see the file COPYING. If not, write to the Free 00020 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 00021 02111-1307, USA. */ 00022 00023 /* As a special exception, if you link this library with other files, 00024 some of which are compiled with GCC, to produce an executable, 00025 this library does not by itself cause the resulting executable 00026 to be covered by the GNU General Public License. 00027 This exception does not however invalidate any other reasons why 00028 the executable file might be covered by the GNU General Public License. */ 00029 00030 #ifndef GCC_GTHR_VXWORKS_H 00031 #define GCC_GTHR_VXWORKS_H 00032 00033 #ifdef _LIBOBJC 00034 00035 /* libobjc requires the optional pthreads component. */ 00036 #include "gthr-posix.h" 00037 00038 #else 00039 00040 #define __GTHREADS 1 00041 #define __gthread_active_p() 1 00042 00043 /* Mutexes are easy, except that they need to be initialized at runtime. */ 00044 00045 #include <semLib.h> 00046 00047 typedef SEM_ID __gthread_mutex_t; 00048 /* All VxWorks mutexes are recursive. */ 00049 typedef SEM_ID __gthread_recursive_mutex_t; 00050 #define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function 00051 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function 00052 00053 static inline void 00054 __gthread_mutex_init_function (__gthread_mutex_t *mutex) 00055 { 00056 *mutex = semMCreate (SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE); 00057 } 00058 00059 static inline int 00060 __gthread_mutex_lock (__gthread_mutex_t *mutex) 00061 { 00062 return semTake (*mutex, WAIT_FOREVER); 00063 } 00064 00065 static inline int 00066 __gthread_mutex_trylock (__gthread_mutex_t *mutex) 00067 { 00068 return semTake (*mutex, NO_WAIT); 00069 } 00070 00071 static inline int 00072 __gthread_mutex_unlock (__gthread_mutex_t *mutex) 00073 { 00074 return semGive (*mutex); 00075 } 00076 00077 static inline void 00078 __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *mutex) 00079 { 00080 __gthread_mutex_init_function (mutex); 00081 } 00082 00083 static inline int 00084 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex) 00085 { 00086 return __gthread_mutex_lock (mutex); 00087 } 00088 00089 static inline int 00090 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex) 00091 { 00092 return __gthread_mutex_trylock (mutex); 00093 } 00094 00095 static inline int 00096 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex) 00097 { 00098 return __gthread_mutex_unlock (mutex); 00099 } 00100 00101 /* pthread_once is complicated enough that it's implemented 00102 out-of-line. See config/vxlib.c. */ 00103 00104 typedef struct 00105 { 00106 volatile unsigned char busy; 00107 volatile unsigned char done; 00108 } 00109 __gthread_once_t; 00110 00111 #define __GTHREAD_ONCE_INIT { 0, 0 } 00112 00113 extern int __gthread_once (__gthread_once_t *once, void (*func)(void)); 00114 00115 /* Thread-specific data requires a great deal of effort, since VxWorks 00116 is not really set up for it. See config/vxlib.c for the gory 00117 details. All the TSD routines are sufficiently complex that they 00118 need to be implemented out of line. */ 00119 00120 typedef unsigned int __gthread_key_t; 00121 00122 extern int __gthread_key_create (__gthread_key_t *keyp, void (*dtor)(void *)); 00123 extern int __gthread_key_delete (__gthread_key_t key); 00124 00125 extern void *__gthread_getspecific (__gthread_key_t key); 00126 extern int __gthread_setspecific (__gthread_key_t key, void *ptr); 00127 00128 #endif /* not _LIBOBJC */ 00129 00130 #endif /* gthr-vxworks.h */
1.5.6