6 /* Copyright (C) 1996 Free Software Foundation, Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this software; see the file COPYING. If not, write to
20 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21 * Boston, MA 02111-1307 USA
23 * As a special exception, the Free Software Foundation gives permission
24 * for additional uses of the text contained in its release of GUILE.
26 * The exception is that, if you link the GUILE library with other files
27 * to produce an executable, this does not by itself cause the
28 * resulting executable to be covered by the GNU General Public License.
29 * Your use of that executable is in no way restricted on account of
30 * linking the GUILE library code into it.
32 * This exception does not however invalidate any other reasons why
33 * the executable file might be covered by the GNU General Public License.
35 * This exception applies only to the code released by the
36 * Free Software Foundation under the name GUILE. If you copy
37 * code from other Free Software Foundation releases into a copy of
38 * GUILE, as the General Public License permits, the exception does
39 * not apply to the code that you add in this way. To avoid misleading
40 * anyone as to the status of such modified files, you must delete
41 * this exception notice from them.
43 * If you write modifications of your own for GUILE, it is your choice
44 * whether to permit this exception to apply to your modifications.
45 * If you do not wish that, delete this exception notice. */
47 /* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
48 gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
51 #include "libguile/__scm.h"
53 #define PTHREAD_KERNEL
56 /* Identify where the stack pointer can be found in a jmpbuf.
60 #if defined(__sparc_setjmp_h)
61 # define THREAD_SP machdep_data.machdep_state[2]
67 # define THREAD_SP machdep_data.machdep_state[2]
72 # define THREAD_SP machdep_data.machdep_state[0].__sp
76 # define THREAD_SP machdep_data.machdep_state[JB_SP]
79 /* ...define THREAD_SP for your architecture here...
82 #if !defined(THREAD_SP)
83 --> where is your stack pointer
?
88 /* Boost the priority of this thread so that it is the only
89 one running. PTHREAD_MAX_PRIORITY is reserved for this
92 #define SCM_THREAD_CRITICAL_SECTION_START \
93 struct sched_param param; \
96 pthread_getschedparam(pthread_self(), &policy, ¶m); \
97 previous_prio = param.prio; \
98 param.prio = PTHREAD_MAX_PRIORITY; \
99 pthread_setschedparam(pthread_self(), policy, ¶m)
101 #define SCM_THREAD_CRITICAL_SECTION_END \
102 param.prio = previous_prio; \
103 pthread_setschedparam(pthread_self(), policy, ¶m)
109 #define SCM_NO_CRITICAL_SECTION_OWNER 0
111 #define SCM_THREAD_DEFER pthread_kernel_lock++
112 #define SCM_THREAD_ALLOW pthread_kernel_lock--
114 #define SCM_THREAD_REDEFER pthread_kernel_lock++
115 #define SCM_THREAD_REALLOW_1 pthread_kernel_lock--
116 #define SCM_THREAD_REALLOW_2 \
118 scm_critical_section_owner = SCM_NO_CRITICAL_SECTION_OWNER; \
119 pthread_mutex_unlock(&scm_critical_section_mutex); \
124 #define SCM_NO_CRITICAL_SECTION_OWNER 0
126 #define SCM_THREAD_DEFER \
128 pthread_mutex_lock (&scm_critical_section_mutex); \
129 scm_critical_section_owner = pthread_self(); \
132 #define SCM_THREAD_ALLOW \
134 scm_critical_section_owner = SCM_NO_CRITICAL_SECTION_OWNER; \
135 pthread_mutex_unlock (&scm_critical_section_mutex); \
138 #define SCM_THREAD_REDEFER \
140 if ((scm_critical_section_owner != pthread_self()) || \
141 (scm_critical_section_owner == SCM_NO_CRITICAL_SECTION_OWNER)) \
143 pthread_mutex_lock(&scm_critical_section_mutex); \
144 scm_critical_section_owner = pthread_self(); \
148 #define SCM_THREAD_REALLOW_1
149 #define SCM_THREAD_REALLOW_2 \
151 scm_critical_section_owner = SCM_NO_CRITICAL_SECTION_OWNER; \
152 pthread_mutex_unlock (&scm_critical_section_mutex); \
157 #define SCM_THREAD_SWITCHING_CODE
159 #define SCM_THREAD_LOCAL_DATA (pthread_self () -> attr.arg_attr)
160 #define SCM_SET_THREAD_LOCAL_DATA(new_root) \
162 pthread_t t = pthread_self (); \
163 void *r = (new_root); \
164 pthread_attr_setcleanup (&t -> attr, NULL, r); \
165 pthreads_find_info (t) -> root = r; \
171 void scm_threads_init_mit_pthreads ();
173 typedef struct QUEUE
{
174 struct QUEUE
*flink
, *blink
;
177 extern pthread_mutex_t scm_critical_section_mutex
;
178 extern pthread_t scm_critical_section_owner
;
180 /* Key to thread specific data */
181 extern pthread_key_t info_key
;
183 struct scm_pthread_create_info_type
188 } scm_pthread_create_info
;
190 #endif /* MIT_PTHREADSH */