#ifndef GCC_GTHR_VXWORKS_H
#define GCC_GTHR_VXWORKS_H
#ifdef _LIBOBJC
static void *thread_local_storage = NULL;
int
__gthread_objc_init_thread_system (void)
{
return -1;
}
int
__gthread_objc_close_thread_system (void)
{
return -1;
}
objc_thread_t
__gthread_objc_thread_detach (void (*func)(void *arg), void *arg)
{
return NULL;
}
int
__gthread_objc_thread_set_priority (int priority)
{
return -1;
}
int
__gthread_objc_thread_get_priority (void)
{
return OBJC_THREAD_INTERACTIVE_PRIORITY;
}
void
__gthread_objc_thread_yield (void)
{
return;
}
int
__gthread_objc_thread_exit (void)
{
return -1;
}
objc_thread_t
__gthread_objc_thread_id (void)
{
return (objc_thread_t) 1;
}
int
__gthread_objc_thread_set_data (void *value)
{
thread_local_storage = value;
return 0;
}
void *
__gthread_objc_thread_get_data (void)
{
return thread_local_storage;
}
int
__gthread_objc_mutex_allocate (objc_mutex_t mutex)
{
return 0;
}
int
__gthread_objc_mutex_deallocate (objc_mutex_t mutex)
{
return 0;
}
int
__gthread_objc_mutex_lock (objc_mutex_t mutex)
{
return 0;
}
int
__gthread_objc_mutex_trylock (objc_mutex_t mutex)
{
return 0;
}
int
__gthread_objc_mutex_unlock (objc_mutex_t mutex)
{
return 0;
}
int
__gthread_objc_condition_allocate (objc_condition_t condition)
{
return 0;
}
int
__gthread_objc_condition_deallocate (objc_condition_t condition)
{
return 0;
}
int
__gthread_objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex)
{
return 0;
}
int
__gthread_objc_condition_broadcast (objc_condition_t condition)
{
return 0;
}
int
__gthread_objc_condition_signal (objc_condition_t condition)
{
return 0;
}
#else
#define __GTHREADS 1
#include <vxWorks.h>
#include <semLib.h>
typedef int __gthread_key_t;
typedef char __gthread_once_t;
typedef SEM_ID __gthread_mutex_t;
#define __GTHREAD_MUTEX_INIT 0
#define __GTHREAD_ONCE_INIT 0
#ifndef REG_SAVED_REG
static inline int
__gthread_once (__gthread_once_t *once, void (*func) (void))
{
(*func)();
return 0;
}
extern __gthread_key_t eh_context_key;
static void
__ehdtor (void *pTcb)
{
int tid = (int) pTcb;
void *p = (void *) taskVarGet (tid, &eh_context_key);
if (p != (void *) -1)
{
if (p)
free (p);
taskVarSet (tid, &eh_context_key, 0);
}
}
static inline int
__gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
{
*key = 0;
taskVarInit ();
taskDeleteHookAdd (__ehdtor);
return 0;
}
#define __gthread_setspecific(key, ptr) \
(key = (int) ptr, 0)
static inline int
__gthread_key_dtor (__gthread_key_t key, void *ptr)
{
if (ptr)
return __gthread_setspecific (key, 0);
else
return 0;
}
#define __gthread_key_delete(key) \
taskVarDelete (taskIdSelf (), &key)
#define __gthread_getspecific(key) \
((key == 0) \
? ((taskVarAdd (taskIdSelf (), &key) != OK) \
? (__terminate (), (void *) 0) \
: (void *) 0) \
: (void *) key)
#endif
static inline int
__gthread_mutex_lock (__gthread_mutex_t *mutex)
{
if (*mutex == 0)
*mutex = semMCreate (SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);
return semTake (*mutex, WAIT_FOREVER);
}
static inline int
__gthread_mutex_trylock (__gthread_mutex_t *mutex)
{
if (*mutex == 0)
*mutex = semMCreate (SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);
return semTake (*mutex, NO_WAIT);
}
static inline int
__gthread_mutex_unlock (__gthread_mutex_t *mutex)
{
return semGive (*mutex);
}
#endif
#endif