OSDN Git Service

Remove inclusion of source files.
[pf3gnuchains/gcc-fork.git] / gcc / objc / thr.c
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)
4
5 This file is part of GNU CC.
6
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.
10
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
14 details.
15
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.  */
20
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.  */
26
27 #include <stdlib.h>
28 #include "runtime.h"
29
30 /*****************************************************************************
31  *  Universal static variables:
32  */
33 int     __objc_thread_exit_status = 0;          /* Global exit status.      */
34
35 /*****************************************************************************
36  *  Universal Functionality
37  */
38
39 /********
40  *  First function called in a thread, starts everything else.
41  */
42 struct __objc_thread_start_state
43 {
44     SEL         selector;
45     id          object;
46     id          argument;
47 };
48
49 static volatile void
50 __objc_thread_detach_function(struct __objc_thread_start_state *istate)
51 {
52     if (istate) {                               /* Is state valid?          */
53         id      (*imp)(id,SEL,id);
54         SEL     selector = istate->selector;
55         id      object   = istate->object;
56         id      argument = istate->argument;
57
58         free(istate);
59
60         if ((imp = (id(*)(id, SEL, id))objc_msg_lookup(object, selector))) {
61             (*imp)(object, selector, argument);
62         }
63         else
64             fprintf(stderr, "__objc_thread_start called with bad selector.\n");
65     }
66     else {
67         fprintf(stderr, "__objc_thread_start called with NULL state.\n");
68     }
69     objc_thread_exit();
70 }
71
72 /********
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.
76  */
77 _objc_thread_t
78 objc_thread_detach(SEL selector, id object, id argument)
79 {
80   struct __objc_thread_start_state *istate;   /* Initialial thread state. */
81   _objc_thread_t        thread_id = NULL;     /* Detached thread id.      */
82
83   if (!(istate = (struct __objc_thread_start_state *)
84         __objc_xmalloc(sizeof(*istate))))     /* Can we allocate state?   */
85     return NULL;                              /* No, abort.               */
86
87   istate->selector = selector;                /* Initialize the thread's  */
88   istate->object = object;                    /*   state structure.       */
89   istate->argument = argument;
90
91   if ((thread_id = objc_thread_create((void *)__objc_thread_detach_function,
92                                       istate)) == NULL) {
93     free(istate);                           /* Release state if failed.   */
94     return thread_id;
95   }
96   return thread_id;
97 }
98
99 #undef objc_mutex_lock()
100 #undef objc_mutex_unlock()
101
102 int
103 objc_mutex_unlock_x(_objc_mutex_t mutex, const char *f, int l)
104 {
105     printf("%16.16s#%4d < unlock", f, l);
106     return objc_mutex_unlock(mutex);
107 }
108
109 int
110 objc_mutex_lock_x(_objc_mutex_t mutex, const char *f, int l)
111 {
112     printf("%16.16s#%4d < lock", f, l);
113     return objc_mutex_lock(mutex);
114 }
115
116 /* End of File */