1 /* GNU Objective C Runtime Thread Implementation
2 Copyright (C) 1996, 1997, 2009 Free Software Foundation, Inc.
3 Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 3, or (at your option) any later version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
27 #include "objc/runtime.h"
29 /* Thread local storage for a single thread */
30 static void *thread_local_storage
= NULL
;
32 /* Backend initialization functions */
34 /* Initialize the threads subsystem. */
36 __objc_init_thread_system(void)
38 /* No thread support available */
42 /* Close the threads subsystem. */
44 __objc_close_thread_system(void)
46 /* No thread support available */
50 /* Backend thread functions */
52 /* Create a new thread of execution. */
54 __objc_thread_detach(void (*func
)(void *arg
), void *arg
)
56 /* No thread support available */
60 /* Set the current thread's priority. */
62 __objc_thread_set_priority(int priority
)
64 /* No thread support available */
68 /* Return the current thread's priority. */
70 __objc_thread_get_priority(void)
72 return OBJC_THREAD_INTERACTIVE_PRIORITY
;
75 /* Yield our process time to another thread. */
77 __objc_thread_yield(void)
82 /* Terminate the current thread. */
84 __objc_thread_exit(void)
86 /* No thread support available */
87 /* Should we really exit the program */
88 /* exit(&__objc_thread_exit_status); */
92 /* Returns an integer value which uniquely describes a thread. */
94 __objc_thread_id(void)
96 /* No thread support, use 1. */
97 return (objc_thread_t
)1;
100 /* Sets the thread's local storage pointer. */
102 __objc_thread_set_data(void *value
)
104 thread_local_storage
= value
;
108 /* Returns the thread's local storage pointer. */
110 __objc_thread_get_data(void)
112 return thread_local_storage
;
115 /* Backend mutex functions */
117 /* Allocate a mutex. */
119 __objc_mutex_allocate(objc_mutex_t mutex
)
124 /* Deallocate a mutex. */
126 __objc_mutex_deallocate(objc_mutex_t mutex
)
131 /* Grab a lock on a mutex. */
133 __objc_mutex_lock(objc_mutex_t mutex
)
135 /* There can only be one thread, so we always get the lock */
139 /* Try to grab a lock on a mutex. */
141 __objc_mutex_trylock(objc_mutex_t mutex
)
143 /* There can only be one thread, so we always get the lock */
147 /* Unlock the mutex */
149 __objc_mutex_unlock(objc_mutex_t mutex
)
154 /* Backend condition mutex functions */
156 /* Allocate a condition. */
158 __objc_condition_allocate(objc_condition_t condition
)
163 /* Deallocate a condition. */
165 __objc_condition_deallocate(objc_condition_t condition
)
170 /* Wait on the condition */
172 __objc_condition_wait(objc_condition_t condition
, objc_mutex_t mutex
)
177 /* Wake up all threads waiting on this condition. */
179 __objc_condition_broadcast(objc_condition_t condition
)
184 /* Wake up one thread waiting on this condition. */
186 __objc_condition_signal(objc_condition_t condition
)