2 * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
4 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
7 * Permission is hereby granted to use or copy this program
8 * for any purpose, provided the above notices are retained on all copies.
9 * Permission to modify the code and to distribute modified code is granted,
10 * provided the above notices are retained, and a notice that the code was
11 * modified is included with the above copyright notice.
14 * Support code for Solaris threads. Provides functionality we wish Sun
15 * had provided. Relies on some information we probably shouldn't rely on.
16 * Modified Peter C. for Solaris Posix Threads.
18 /* Boehm, September 14, 1994 4:44 pm PDT */
20 # if defined(_SOLARIS_PTHREADS)
26 # include <sys/types.h>
27 # include <sys/mman.h>
28 # include <sys/time.h>
29 # include <sys/resource.h>
30 # include <sys/stat.h>
31 # include <sys/syscall.h>
32 # include <sys/procfs.h>
35 # define _CLASSIC_XOPEN_TYPES
38 # include "solaris_threads.h"
44 pthread_cond_t GC_prom_join_cv
; /* Broadcast when any thread terminates */
45 pthread_cond_t GC_create_cv
; /* Signalled when a new undetached */
48 extern GC_bool GC_multithreaded
;
50 /* We use the allocation lock to protect thread-related data structures. */
52 /* We stop the world using /proc primitives. This makes some */
53 /* minimal assumptions about the threads implementation. */
54 /* We don't play by the rules, since the rules make this */
55 /* impossible (as of Solaris 2.3). Also note that as of */
56 /* Solaris 2.3 the various thread and lwp suspension */
57 /* primitives failed to stop threads by the time the request */
62 int GC_pthread_join(pthread_t wait_for
, void **status
)
64 return GC_thr_join((thread_t
)wait_for
, NULL
, status
);
69 GC_pthread_create(pthread_t
*new_thread
,
70 const pthread_attr_t
*attr_in
,
71 void * (*thread_execp
)(void *), void *arg
)
75 pthread_t my_new_thread
;
82 struct sched_param schedparam
;
84 (void)pthread_attr_getstacksize(attr_in
, &stack_size
);
85 (void)pthread_attr_getstackaddr(attr_in
, &stack
);
86 (void)pthread_attr_init(&attr
);
89 if (!GC_thr_initialized
) {
96 stack_size
= GC_min_stack_sz
;
98 stack_size
+= thr_min_stack();
100 stack
= (void *)GC_stack_alloc(&stack_size
);
108 my_flags
|= CLIENT_OWNS_STACK
;
110 (void)pthread_attr_setstacksize(&attr
, stack_size
);
111 (void)pthread_attr_setstackaddr(&attr
, stack
);
112 (void)pthread_attr_getscope(attr_in
, &n
);
113 (void)pthread_attr_setscope(&attr
, n
);
114 (void)pthread_attr_getschedparam(attr_in
, &schedparam
);
115 (void)pthread_attr_setschedparam(&attr
, &schedparam
);
116 (void)pthread_attr_getschedpolicy(attr_in
, &n
);
117 (void)pthread_attr_setschedpolicy(&attr
, n
);
118 (void)pthread_attr_getinheritsched(attr_in
, &n
);
119 (void)pthread_attr_setinheritsched(&attr
, n
);
121 (void)pthread_attr_getdetachstate(attr_in
, &flag
);
122 if (flag
== PTHREAD_CREATE_DETACHED
) {
123 my_flags
|= DETACHED
;
125 (void)pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_JOINABLE
);
127 * thr_create can call malloc(), which if redirected will
128 * attempt to acquire the allocation lock.
129 * Unlock here to prevent deadlock.
139 pthread_create(&my_new_thread
, &attr
, thread_execp
, arg
);
146 t
= GC_new_thread(my_new_thread
);
147 t
-> flags
= my_flags
;
148 if (!(my_flags
& DETACHED
)) cond_init(&(t
->join_cv
), USYNC_THREAD
, 0);
150 t
-> stack_size
= stack_size
;
151 if (new_thread
!= 0) *new_thread
= my_new_thread
;
152 pthread_cond_signal(&GC_create_cv
);
154 if (!(my_flags
& CLIENT_OWNS_STACK
)) {
155 GC_stack_free(stack
, stack_size
);
160 pthread_attr_destroy(&attr
);
167 int GC_no_sunOS_pthreads
;
170 # endif /* SOLARIS_THREADS */