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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 * As a special exception, the Free Software Foundation gives permission
23 * for additional uses of the text contained in its release of GUILE.
25 * The exception is that, if you link the GUILE library with other files
26 * to produce an executable, this does not by itself cause the
27 * resulting executable to be covered by the GNU General Public License.
28 * Your use of that executable is in no way restricted on account of
29 * linking the GUILE library code into it.
31 * This exception does not however invalidate any other reasons why
32 * the executable file might be covered by the GNU General Public License.
34 * This exception applies only to the code released by the
35 * Free Software Foundation under the name GUILE. If you copy
36 * code from other Free Software Foundation releases into a copy of
37 * GUILE, as the General Public License permits, the exception does
38 * not apply to the code that you add in this way. To avoid misleading
39 * anyone as to the status of such modified files, you must delete
40 * this exception notice from them.
42 * If you write modifications of your own for GUILE, it is your choice
43 * whether to permit this exception to apply to your modifications.
44 * If you do not wish that, delete this exception notice.
48 #include "libguile/__scm.h"
50 #define PTHREAD_KERNEL
53 /* Identify where the stack pointer can be found in a jmpbuf.
57 #if defined(__sparc_setjmp_h)
58 # define THREAD_SP machdep_data.machdep_state[2]
64 # define THREAD_SP machdep_data.machdep_state[2]
69 # define THREAD_SP machdep_data.machdep_state[0].__sp
73 # define THREAD_SP machdep_data.machdep_state[JB_SP]
76 /* ...define THREAD_SP for your architecture here...
79 #if !defined(THREAD_SP)
80 --> where is your stack pointer
?
85 /* Boost the priority of this thread so that it is the only
86 one running. PTHREAD_MAX_PRIORITY is reserved for this
89 #define SCM_THREAD_CRITICAL_SECTION_START \
90 struct sched_param param; \
93 pthread_getschedparam(pthread_self(), &policy, ¶m); \
94 previous_prio = param.prio; \
95 param.prio = PTHREAD_MAX_PRIORITY; \
96 pthread_setschedparam(pthread_self(), policy, ¶m)
98 #define SCM_THREAD_CRITICAL_SECTION_END \
99 param.prio = previous_prio; \
100 pthread_setschedparam(pthread_self(), policy, ¶m)
106 #define SCM_NO_CRITICAL_SECTION_OWNER 0
108 #define SCM_THREAD_DEFER pthread_kernel_lock++
109 #define SCM_THREAD_ALLOW pthread_kernel_lock--
111 #define SCM_THREAD_REDEFER pthread_kernel_lock++
112 #define SCM_THREAD_REALLOW_1 pthread_kernel_lock--
113 #define SCM_THREAD_REALLOW_2 \
115 scm_critical_section_owner = SCM_NO_CRITICAL_SECTION_OWNER; \
116 pthread_mutex_unlock(&scm_critical_section_mutex); \
121 #define SCM_NO_CRITICAL_SECTION_OWNER 0
123 #define SCM_THREAD_DEFER \
125 pthread_mutex_lock (&scm_critical_section_mutex); \
126 scm_critical_section_owner = pthread_self(); \
129 #define SCM_THREAD_ALLOW \
131 scm_critical_section_owner = SCM_NO_CRITICAL_SECTION_OWNER; \
132 pthread_mutex_unlock (&scm_critical_section_mutex); \
135 #define SCM_THREAD_REDEFER \
137 if ((scm_critical_section_owner != pthread_self()) || \
138 (scm_critical_section_owner == SCM_NO_CRITICAL_SECTION_OWNER)) \
140 pthread_mutex_lock(&scm_critical_section_mutex); \
141 scm_critical_section_owner = pthread_self(); \
145 #define SCM_THREAD_REALLOW_1
146 #define SCM_THREAD_REALLOW_2 \
148 scm_critical_section_owner = SCM_NO_CRITICAL_SECTION_OWNER; \
149 pthread_mutex_unlock (&scm_critical_section_mutex); \
154 #define SCM_THREAD_SWITCHING_CODE
156 #define SCM_THREAD_LOCAL_DATA (pthread_self () -> attr.arg_attr)
157 #define SCM_SET_THREAD_LOCAL_DATA(new_root) \
159 pthread_t t = pthread_self (); \
160 void *r = (new_root); \
161 pthread_attr_setcleanup (&t -> attr, NULL, r); \
162 pthreads_find_info (t) -> root = r; \
168 void scm_threads_init_mit_pthreads ();
170 typedef struct QUEUE
{
171 struct QUEUE
*flink
, *blink
;
174 extern pthread_mutex_t scm_critical_section_mutex
;
175 extern pthread_t scm_critical_section_owner
;
177 /* Key to thread specific data */
178 extern pthread_key_t info_key
;
180 struct scm_pthread_create_info_type
185 } scm_pthread_create_info
;
187 #endif /* MIT_PTHREADSH */