1 /* GNU Objective C Runtime Thread Interface
2 Copyright (C) 1996 Free Software Foundation, Inc.
3 Contributed by Galen C. Hunt (gchunt@cs.rochester.edu)
5 This file is part of GNU CC.
7 GNU CC 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 2, or (at your option) any later version.
11 GNU CC 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 You should have received a copy of the GNU General Public License along with
17 GNU CC; see the file COPYING. If not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* As a special exception, if you link this library with files compiled with
22 GCC to produce an executable, this does not cause the resulting executable
23 to be covered by the GNU General Public License. This exception does not
24 however invalidate any other reasons why the executable file might be
25 covered by the GNU General Public License. */
30 /*****************************************************************************
31 * Universal static variables:
33 int __objc_thread_exit_status = 0; /* Global exit status. */
35 /*****************************************************************************
36 * Universal Functionality
40 * First function called in a thread, starts everything else.
42 struct __objc_thread_start_state
50 __objc_thread_detach_function(struct __objc_thread_start_state *istate)
52 if (istate) { /* Is state valid? */
54 SEL selector = istate->selector;
55 id object = istate->object;
56 id argument = istate->argument;
60 if ((imp = (id(*)(id, SEL, id))objc_msg_lookup(object, selector))) {
61 (*imp)(object, selector, argument);
64 fprintf(stderr, "__objc_thread_start called with bad selector.\n");
67 fprintf(stderr, "__objc_thread_start called with NULL state.\n");
73 * Detach a new thread of execution and return its id. Returns NULL if fails.
74 * Thread is started by sending message with selector to object. Message
75 * takes a single argument.
78 objc_thread_detach(SEL selector, id object, id argument)
80 struct __objc_thread_start_state *istate; /* Initialial thread state. */
81 _objc_thread_t thread_id = NULL; /* Detached thread id. */
83 if (!(istate = (struct __objc_thread_start_state *)
84 __objc_xmalloc(sizeof(*istate)))) /* Can we allocate state? */
85 return NULL; /* No, abort. */
87 istate->selector = selector; /* Initialize the thread's */
88 istate->object = object; /* state structure. */
89 istate->argument = argument;
91 if ((thread_id = objc_thread_create((void *)__objc_thread_detach_function,
93 free(istate); /* Release state if failed. */
99 #undef objc_mutex_lock()
100 #undef objc_mutex_unlock()
103 objc_mutex_unlock_x(_objc_mutex_t mutex, const char *f, int l)
105 printf("%16.16s#%4d < unlock", f, l);
106 return objc_mutex_unlock(mutex);
110 objc_mutex_lock_x(_objc_mutex_t mutex, const char *f, int l)
112 printf("%16.16s#%4d < lock", f, l);
113 return objc_mutex_lock(mutex);