diff options
author | Richard Kenner <kenner@gcc.gnu.org> | 1996-06-10 11:58:41 -0400 |
---|---|---|
committer | Richard Kenner <kenner@gcc.gnu.org> | 1996-06-10 11:58:41 -0400 |
commit | 1717ec59158d5250140e479fd0fa5e57bc67f4e6 (patch) | |
tree | 41baa21e6835af1de32d82ac3d7d64bd4ae2df90 /gcc | |
parent | f2433f89b4dc7b7fb0661d3d5ce50eb6c1d9777c (diff) | |
download | gcc-1717ec59158d5250140e479fd0fa5e57bc67f4e6.zip gcc-1717ec59158d5250140e479fd0fa5e57bc67f4e6.tar.gz gcc-1717ec59158d5250140e479fd0fa5e57bc67f4e6.tar.bz2 |
(__objc_thread_detach_function): Clear thread storage.
Call the thread hook function when first becoming multi-threaded.
(objc_set_thread_callback): New function.
From-SVN: r12261
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/objc/thr.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/gcc/objc/thr.c b/gcc/objc/thr.c index db7787b..5247233 100644 --- a/gcc/objc/thr.c +++ b/gcc/objc/thr.c @@ -32,10 +32,34 @@ Boston, MA 02111-1307, USA. */ */ int __objc_thread_exit_status = 0; /* Global exit status. */ +/* Flag which lets us know if we ever became multi threaded */ +int __objc_is_multi_threaded = 0; +/* The hook function called when the runtime becomes multi threaded */ +objc_thread_callback _objc_became_multi_threaded = NULL; + /***************************************************************************** * Universal Functionality */ +/* + Use this to set the hook function that will be called when the + runtime initially becomes multi threaded. + The hook function is only called once, meaning only when the + 2nd thread is spawned, not for each and every thread. + + It returns the previous hook function or NULL if there is none. + + A program outside of the runtime could set this to some function so + it can be informed; for example, the GNUstep Base Library sets it + so it can implement the NSBecomingMultiThreaded notification. + */ +objc_thread_callback objc_set_thread_callback(objc_thread_callback func) +{ + objc_thread_callback temp = _objc_became_multi_threaded; + _objc_became_multi_threaded = func; + return temp; +} + /******** * First function called in a thread, starts everything else. */ @@ -57,6 +81,18 @@ __objc_thread_detach_function(struct __objc_thread_start_state *istate) free(istate); + /* Clear out the thread local storage */ + objc_thread_set_data(NULL); + + /* Check to see if we just became multi threaded */ + if (!__objc_is_multi_threaded) { + __objc_is_multi_threaded = 1; + + /* Call the hook function */ + if (_objc_became_multi_threaded != NULL) + (*_objc_became_multi_threaded)(); + } + if ((imp = (id(*)(id, SEL, id))objc_msg_lookup(object, selector))) { (*imp)(object, selector, argument); } @@ -93,6 +129,7 @@ objc_thread_detach(SEL selector, id object, id argument) free(istate); /* Release state if failed. */ return thread_id; } + return thread_id; } |