190075Sobrien/* Threads compatibility routines for libgcc2 and libobjc. */ 250397Sobrien/* Compile this one with gcc. */ 3169689Skan/* Copyright (C) 1997, 1999, 2000, 2004 Free Software Foundation, Inc. 450397Sobrien 590075SobrienThis file is part of GCC. 650397Sobrien 790075SobrienGCC is free software; you can redistribute it and/or modify it under 890075Sobrienthe terms of the GNU General Public License as published by the Free 990075SobrienSoftware Foundation; either version 2, or (at your option) any later 1090075Sobrienversion. 1150397Sobrien 1290075SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY 1390075SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or 1490075SobrienFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1590075Sobrienfor more details. 1650397Sobrien 1750397SobrienYou should have received a copy of the GNU General Public License 1890075Sobrienalong with GCC; see the file COPYING. If not, write to the Free 19169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 20169689Skan02110-1301, USA. */ 2150397Sobrien 2250397Sobrien/* As a special exception, if you link this library with other files, 2350397Sobrien some of which are compiled with GCC, to produce an executable, 2450397Sobrien this library does not by itself cause the resulting executable 2550397Sobrien to be covered by the GNU General Public License. 2650397Sobrien This exception does not however invalidate any other reasons why 2750397Sobrien the executable file might be covered by the GNU General Public License. */ 2850397Sobrien 2990075Sobrien#ifndef GCC_GTHR_SINGLE_H 3090075Sobrien#define GCC_GTHR_SINGLE_H 3150397Sobrien 3290075Sobrien/* Just provide compatibility for mutex handling. */ 3350397Sobrien 3450397Sobrientypedef int __gthread_mutex_t; 35169689Skantypedef int __gthread_recursive_mutex_t; 3650397Sobrien 3750397Sobrien#define __GTHREAD_MUTEX_INIT 0 3850397Sobrien 3990075Sobrien#ifdef __cplusplus 4090075Sobrien#define UNUSED(x) 4190075Sobrien#else 4290075Sobrien#define UNUSED(x) x __attribute__((unused)) 4390075Sobrien#endif 4490075Sobrien 4590075Sobrien#ifdef _LIBOBJC 4690075Sobrien 4790075Sobrien/* Thread local storage for a single thread */ 4890075Sobrienstatic void *thread_local_storage = NULL; 4990075Sobrien 5090075Sobrien/* Backend initialization functions */ 5190075Sobrien 5290075Sobrien/* Initialize the threads subsystem. */ 5350397Sobrienstatic inline int 54117395Skan__gthread_objc_init_thread_system (void) 5550397Sobrien{ 5690075Sobrien /* No thread support available */ 5790075Sobrien return -1; 5890075Sobrien} 5990075Sobrien 6090075Sobrien/* Close the threads subsystem. */ 6190075Sobrienstatic inline int 62117395Skan__gthread_objc_close_thread_system (void) 6390075Sobrien{ 6490075Sobrien /* No thread support available */ 6590075Sobrien return -1; 6690075Sobrien} 6790075Sobrien 6890075Sobrien/* Backend thread functions */ 6990075Sobrien 7090075Sobrien/* Create a new thread of execution. */ 7190075Sobrienstatic inline objc_thread_t 72117395Skan__gthread_objc_thread_detach (void (* func)(void *), void * UNUSED(arg)) 7390075Sobrien{ 7490075Sobrien /* No thread support available */ 7590075Sobrien return NULL; 7690075Sobrien} 7790075Sobrien 7890075Sobrien/* Set the current thread's priority. */ 7990075Sobrienstatic inline int 80117395Skan__gthread_objc_thread_set_priority (int UNUSED(priority)) 8190075Sobrien{ 8290075Sobrien /* No thread support available */ 8390075Sobrien return -1; 8490075Sobrien} 8590075Sobrien 8690075Sobrien/* Return the current thread's priority. */ 8790075Sobrienstatic inline int 88117395Skan__gthread_objc_thread_get_priority (void) 8990075Sobrien{ 9090075Sobrien return OBJC_THREAD_INTERACTIVE_PRIORITY; 9190075Sobrien} 9290075Sobrien 9390075Sobrien/* Yield our process time to another thread. */ 9490075Sobrienstatic inline void 95117395Skan__gthread_objc_thread_yield (void) 9690075Sobrien{ 9790075Sobrien return; 9890075Sobrien} 9990075Sobrien 10090075Sobrien/* Terminate the current thread. */ 10190075Sobrienstatic inline int 102117395Skan__gthread_objc_thread_exit (void) 10390075Sobrien{ 10490075Sobrien /* No thread support available */ 10590075Sobrien /* Should we really exit the program */ 106117395Skan /* exit (&__objc_thread_exit_status); */ 10790075Sobrien return -1; 10890075Sobrien} 10990075Sobrien 11090075Sobrien/* Returns an integer value which uniquely describes a thread. */ 11190075Sobrienstatic inline objc_thread_t 112117395Skan__gthread_objc_thread_id (void) 11390075Sobrien{ 11490075Sobrien /* No thread support, use 1. */ 115117395Skan return (objc_thread_t) 1; 11690075Sobrien} 11790075Sobrien 11890075Sobrien/* Sets the thread's local storage pointer. */ 11990075Sobrienstatic inline int 120117395Skan__gthread_objc_thread_set_data (void *value) 12190075Sobrien{ 12290075Sobrien thread_local_storage = value; 12350397Sobrien return 0; 12450397Sobrien} 12550397Sobrien 12690075Sobrien/* Returns the thread's local storage pointer. */ 12790075Sobrienstatic inline void * 128117395Skan__gthread_objc_thread_get_data (void) 12990075Sobrien{ 13090075Sobrien return thread_local_storage; 13190075Sobrien} 13290075Sobrien 13390075Sobrien/* Backend mutex functions */ 13490075Sobrien 13590075Sobrien/* Allocate a mutex. */ 13650397Sobrienstatic inline int 137117395Skan__gthread_objc_mutex_allocate (objc_mutex_t UNUSED(mutex)) 13850397Sobrien{ 13950397Sobrien return 0; 14050397Sobrien} 14150397Sobrien 14290075Sobrien/* Deallocate a mutex. */ 14350397Sobrienstatic inline int 144117395Skan__gthread_objc_mutex_deallocate (objc_mutex_t UNUSED(mutex)) 14550397Sobrien{ 14650397Sobrien return 0; 14750397Sobrien} 14850397Sobrien 14990075Sobrien/* Grab a lock on a mutex. */ 15050397Sobrienstatic inline int 151117395Skan__gthread_objc_mutex_lock (objc_mutex_t UNUSED(mutex)) 15250397Sobrien{ 15390075Sobrien /* There can only be one thread, so we always get the lock */ 15450397Sobrien return 0; 15550397Sobrien} 15650397Sobrien 15790075Sobrien/* Try to grab a lock on a mutex. */ 15890075Sobrienstatic inline int 159117395Skan__gthread_objc_mutex_trylock (objc_mutex_t UNUSED(mutex)) 16090075Sobrien{ 16190075Sobrien /* There can only be one thread, so we always get the lock */ 16290075Sobrien return 0; 16390075Sobrien} 16490075Sobrien 16590075Sobrien/* Unlock the mutex */ 16690075Sobrienstatic inline int 167117395Skan__gthread_objc_mutex_unlock (objc_mutex_t UNUSED(mutex)) 16890075Sobrien{ 16990075Sobrien return 0; 17090075Sobrien} 17190075Sobrien 17290075Sobrien/* Backend condition mutex functions */ 17390075Sobrien 17490075Sobrien/* Allocate a condition. */ 17590075Sobrienstatic inline int 176117395Skan__gthread_objc_condition_allocate (objc_condition_t UNUSED(condition)) 17790075Sobrien{ 17890075Sobrien return 0; 17990075Sobrien} 18090075Sobrien 18190075Sobrien/* Deallocate a condition. */ 18290075Sobrienstatic inline int 183117395Skan__gthread_objc_condition_deallocate (objc_condition_t UNUSED(condition)) 18490075Sobrien{ 18590075Sobrien return 0; 18690075Sobrien} 18790075Sobrien 18890075Sobrien/* Wait on the condition */ 18990075Sobrienstatic inline int 190117395Skan__gthread_objc_condition_wait (objc_condition_t UNUSED(condition), 191117395Skan objc_mutex_t UNUSED(mutex)) 19290075Sobrien{ 19390075Sobrien return 0; 19490075Sobrien} 19590075Sobrien 19690075Sobrien/* Wake up all threads waiting on this condition. */ 19790075Sobrienstatic inline int 198117395Skan__gthread_objc_condition_broadcast (objc_condition_t UNUSED(condition)) 19990075Sobrien{ 20090075Sobrien return 0; 20190075Sobrien} 20290075Sobrien 20390075Sobrien/* Wake up one thread waiting on this condition. */ 20490075Sobrienstatic inline int 205117395Skan__gthread_objc_condition_signal (objc_condition_t UNUSED(condition)) 20690075Sobrien{ 20790075Sobrien return 0; 20890075Sobrien} 20990075Sobrien 21090075Sobrien#else /* _LIBOBJC */ 21190075Sobrien 21290075Sobrienstatic inline int 21390075Sobrien__gthread_active_p (void) 21490075Sobrien{ 21590075Sobrien return 0; 21690075Sobrien} 21790075Sobrien 21890075Sobrienstatic inline int 21990075Sobrien__gthread_mutex_lock (__gthread_mutex_t * UNUSED(mutex)) 22090075Sobrien{ 22190075Sobrien return 0; 22290075Sobrien} 22390075Sobrien 22490075Sobrienstatic inline int 22590075Sobrien__gthread_mutex_trylock (__gthread_mutex_t * UNUSED(mutex)) 22690075Sobrien{ 22790075Sobrien return 0; 22890075Sobrien} 22990075Sobrien 23090075Sobrienstatic inline int 23190075Sobrien__gthread_mutex_unlock (__gthread_mutex_t * UNUSED(mutex)) 23290075Sobrien{ 23390075Sobrien return 0; 23490075Sobrien} 23590075Sobrien 236169689Skanstatic inline int 237169689Skan__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex) 238169689Skan{ 239169689Skan return __gthread_mutex_lock (mutex); 240169689Skan} 241169689Skan 242169689Skanstatic inline int 243169689Skan__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex) 244169689Skan{ 245169689Skan return __gthread_mutex_trylock (mutex); 246169689Skan} 247169689Skan 248169689Skanstatic inline int 249169689Skan__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex) 250169689Skan{ 251169689Skan return __gthread_mutex_unlock (mutex); 252169689Skan} 253169689Skan 25490075Sobrien#endif /* _LIBOBJC */ 25590075Sobrien 25690075Sobrien#undef UNUSED 25790075Sobrien 25890075Sobrien#endif /* ! GCC_GTHR_SINGLE_H */ 259