1999-04-07 10:01:41 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994 by Xerox Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
|
|
|
|
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted to use or copy this program
|
|
|
|
* for any purpose, provided the above notices are retained on all copies.
|
|
|
|
* Permission to modify the code and to distribute modified code is granted,
|
|
|
|
* provided the above notices are retained, and a notice that the code was
|
|
|
|
* modified is included with the above copyright notice.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Support code for Solaris threads. Provides functionality we wish Sun
|
|
|
|
* had provided. Relies on some information we probably shouldn't rely on.
|
|
|
|
* Modified Peter C. for Solaris Posix Threads.
|
|
|
|
*/
|
|
|
|
/* Boehm, September 14, 1994 4:44 pm PDT */
|
|
|
|
|
2001-10-16 11:01:40 +02:00
|
|
|
# if defined(GC_SOLARIS_PTHREADS)
|
Imported version version 6.0alpha7.
* README, README.Mac, README.OS2, README.QUICK, README.alpha,
README.amiga, README.debugging, README.dj, README.hp, README.linux,
README.rs6000, README.sgi, README.solaris2, README.uts,
README.win32, SCoptions.amiga, backptr.h, barrett_diagram,
dbg_mlc.h, gc.h, gc.man, gc_alloc.h, gc_cpp.h, gc_hdrs.h, gc_mark.h,
gc_priv.h, gc_private.h, gc_typed.h, gcconfig.h,
hpux_irix_threads.c, makefile.depend, nursery.c,
solaris_threads.h, test.c, test_cpp.cc, weakpointer.h, cord/README,
cord/SCOPTIONS.amiga, cord/SMakefile.amiga, cord/cord.h,
cord/ec.h, cord/gc.h, cord/private/cord_pos.h, include/backptr.h,
include/gc_copy_descr.h, include/gc_nursery.h: Remove obsolete/moved
files.
From-SVN: r42379
2001-05-21 10:35:14 +02:00
|
|
|
# include "private/gc_priv.h"
|
1999-04-07 10:01:41 +02:00
|
|
|
# include <pthread.h>
|
|
|
|
# include <thread.h>
|
|
|
|
# include <signal.h>
|
|
|
|
# include <fcntl.h>
|
|
|
|
# include <sys/types.h>
|
|
|
|
# include <sys/mman.h>
|
|
|
|
# include <sys/time.h>
|
|
|
|
# include <sys/resource.h>
|
|
|
|
# include <sys/stat.h>
|
|
|
|
# include <sys/syscall.h>
|
|
|
|
# include <sys/procfs.h>
|
|
|
|
# include <sys/lwp.h>
|
|
|
|
# include <sys/reg.h>
|
|
|
|
# define _CLASSIC_XOPEN_TYPES
|
|
|
|
# include <unistd.h>
|
|
|
|
# include <errno.h>
|
Imported version version 6.0alpha7.
* README, README.Mac, README.OS2, README.QUICK, README.alpha,
README.amiga, README.debugging, README.dj, README.hp, README.linux,
README.rs6000, README.sgi, README.solaris2, README.uts,
README.win32, SCoptions.amiga, backptr.h, barrett_diagram,
dbg_mlc.h, gc.h, gc.man, gc_alloc.h, gc_cpp.h, gc_hdrs.h, gc_mark.h,
gc_priv.h, gc_private.h, gc_typed.h, gcconfig.h,
hpux_irix_threads.c, makefile.depend, nursery.c,
solaris_threads.h, test.c, test_cpp.cc, weakpointer.h, cord/README,
cord/SCOPTIONS.amiga, cord/SMakefile.amiga, cord/cord.h,
cord/ec.h, cord/gc.h, cord/private/cord_pos.h, include/backptr.h,
include/gc_copy_descr.h, include/gc_nursery.h: Remove obsolete/moved
files.
From-SVN: r42379
2001-05-21 10:35:14 +02:00
|
|
|
# include "private/solaris_threads.h"
|
1999-04-07 10:01:41 +02:00
|
|
|
# include <stdio.h>
|
|
|
|
|
|
|
|
#undef pthread_join
|
|
|
|
#undef pthread_create
|
|
|
|
|
|
|
|
pthread_cond_t GC_prom_join_cv; /* Broadcast when any thread terminates */
|
|
|
|
pthread_cond_t GC_create_cv; /* Signalled when a new undetached */
|
|
|
|
/* thread starts. */
|
|
|
|
|
1999-04-07 10:01:42 +02:00
|
|
|
extern GC_bool GC_multithreaded;
|
1999-04-07 10:01:41 +02:00
|
|
|
|
|
|
|
/* We use the allocation lock to protect thread-related data structures. */
|
|
|
|
|
|
|
|
/* We stop the world using /proc primitives. This makes some */
|
|
|
|
/* minimal assumptions about the threads implementation. */
|
|
|
|
/* We don't play by the rules, since the rules make this */
|
|
|
|
/* impossible (as of Solaris 2.3). Also note that as of */
|
|
|
|
/* Solaris 2.3 the various thread and lwp suspension */
|
|
|
|
/* primitives failed to stop threads by the time the request */
|
|
|
|
/* is completed. */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int GC_pthread_join(pthread_t wait_for, void **status)
|
|
|
|
{
|
|
|
|
return GC_thr_join((thread_t)wait_for, NULL, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
GC_pthread_create(pthread_t *new_thread,
|
|
|
|
const pthread_attr_t *attr_in,
|
|
|
|
void * (*thread_execp)(void *), void *arg)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
GC_thread t;
|
|
|
|
pthread_t my_new_thread;
|
|
|
|
pthread_attr_t attr;
|
|
|
|
word my_flags = 0;
|
|
|
|
int flag;
|
2000-04-19 12:10:01 +02:00
|
|
|
void * stack = 0;
|
|
|
|
size_t stack_size = 0;
|
1999-04-07 10:01:41 +02:00
|
|
|
int n;
|
|
|
|
struct sched_param schedparam;
|
|
|
|
|
|
|
|
(void)pthread_attr_init(&attr);
|
2000-04-19 12:10:01 +02:00
|
|
|
if (attr_in != 0) {
|
|
|
|
(void)pthread_attr_getstacksize(attr_in, &stack_size);
|
|
|
|
(void)pthread_attr_getstackaddr(attr_in, &stack);
|
|
|
|
}
|
1999-04-07 10:01:41 +02:00
|
|
|
|
|
|
|
LOCK();
|
2002-02-12 05:37:57 +01:00
|
|
|
if (!GC_is_initialized) {
|
|
|
|
GC_init_inner();
|
1999-04-07 10:01:41 +02:00
|
|
|
}
|
|
|
|
GC_multithreaded++;
|
|
|
|
|
|
|
|
if (stack == 0) {
|
|
|
|
if (stack_size == 0)
|
2000-04-19 12:10:01 +02:00
|
|
|
stack_size = 1048576;
|
|
|
|
/* ^-- 1 MB (this was GC_min_stack_sz, but that
|
|
|
|
* violates the pthread_create documentation which
|
|
|
|
* says the default value if none is supplied is
|
|
|
|
* 1MB) */
|
1999-04-07 10:01:41 +02:00
|
|
|
else
|
|
|
|
stack_size += thr_min_stack();
|
|
|
|
|
|
|
|
stack = (void *)GC_stack_alloc(&stack_size);
|
|
|
|
if (stack == 0) {
|
|
|
|
GC_multithreaded--;
|
|
|
|
UNLOCK();
|
|
|
|
errno = ENOMEM;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
my_flags |= CLIENT_OWNS_STACK;
|
|
|
|
}
|
|
|
|
(void)pthread_attr_setstacksize(&attr, stack_size);
|
|
|
|
(void)pthread_attr_setstackaddr(&attr, stack);
|
2000-04-19 12:10:01 +02:00
|
|
|
if (attr_in != 0) {
|
|
|
|
(void)pthread_attr_getscope(attr_in, &n);
|
|
|
|
(void)pthread_attr_setscope(&attr, n);
|
|
|
|
(void)pthread_attr_getschedparam(attr_in, &schedparam);
|
|
|
|
(void)pthread_attr_setschedparam(&attr, &schedparam);
|
|
|
|
(void)pthread_attr_getschedpolicy(attr_in, &n);
|
|
|
|
(void)pthread_attr_setschedpolicy(&attr, n);
|
|
|
|
(void)pthread_attr_getinheritsched(attr_in, &n);
|
|
|
|
(void)pthread_attr_setinheritsched(&attr, n);
|
|
|
|
|
|
|
|
(void)pthread_attr_getdetachstate(attr_in, &flag);
|
|
|
|
if (flag == PTHREAD_CREATE_DETACHED) {
|
|
|
|
my_flags |= DETACHED;
|
|
|
|
}
|
|
|
|
(void)pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
1999-04-07 10:01:41 +02:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* thr_create can call malloc(), which if redirected will
|
|
|
|
* attempt to acquire the allocation lock.
|
|
|
|
* Unlock here to prevent deadlock.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#ifdef I386
|
|
|
|
UNLOCK();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
result =
|
|
|
|
pthread_create(&my_new_thread, &attr, thread_execp, arg);
|
|
|
|
#if 0
|
|
|
|
#ifdef I386
|
|
|
|
LOCK();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
if (result == 0) {
|
|
|
|
t = GC_new_thread(my_new_thread);
|
|
|
|
t -> flags = my_flags;
|
|
|
|
if (!(my_flags & DETACHED)) cond_init(&(t->join_cv), USYNC_THREAD, 0);
|
|
|
|
t -> stack = stack;
|
|
|
|
t -> stack_size = stack_size;
|
|
|
|
if (new_thread != 0) *new_thread = my_new_thread;
|
|
|
|
pthread_cond_signal(&GC_create_cv);
|
|
|
|
} else {
|
|
|
|
if (!(my_flags & CLIENT_OWNS_STACK)) {
|
|
|
|
GC_stack_free(stack, stack_size);
|
|
|
|
}
|
|
|
|
GC_multithreaded--;
|
|
|
|
}
|
|
|
|
UNLOCK();
|
|
|
|
pthread_attr_destroy(&attr);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
# else
|
|
|
|
|
|
|
|
#ifndef LINT
|
|
|
|
int GC_no_sunOS_pthreads;
|
|
|
|
#endif
|
|
|
|
|
2001-10-16 11:01:40 +02:00
|
|
|
# endif /* GC_SOLARIS_PTHREADS */
|
1999-04-07 10:01:41 +02:00
|
|
|
|