// posix-threads.cc - interface between libjava and POSIX threads.
-/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2004 Free Software Foundation
This file is part of libgcj.
#include <signal.h>
#include <errno.h>
#include <limits.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h> // To test for _POSIX_THREAD_PRIORITY_SCHEDULING
+#endif
#include <gcj/cni.h>
#include <jvm.h>
#include <java/lang/System.h>
#include <java/lang/Long.h>
#include <java/lang/OutOfMemoryError.h>
+#include <java/lang/InternalError.h>
// This is used to implement thread startup.
struct starter
mu->owner = self;
mu->count = count;
- // If we were interrupted, or if a timeout occured, remove ourself from
+ // If we were interrupted, or if a timeout occurred, remove ourself from
// the cv wait list now. (If we were notified normally, notify() will have
// already taken care of this)
if (r == ETIMEDOUT || interrupted)
int
_Jv_CondNotify (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu)
{
- if (_Jv_PthreadCheckMonitor (mu))
+ if (_Jv_MutexCheckMonitor (mu))
return _JV_NOT_OWNER;
_Jv_Thread_t *target;
int
_Jv_CondNotifyAll (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu)
{
- if (_Jv_PthreadCheckMonitor (mu))
+ if (_Jv_MutexCheckMonitor (mu))
return _JV_NOT_OWNER;
_Jv_Thread_t *target;
void
_Jv_ThreadSetPriority (_Jv_Thread_t *data, jint prio)
{
+#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
if (data->flags & FLAG_START)
{
struct sched_param param;
param.sched_priority = prio;
pthread_setschedparam (data->thread, SCHED_RR, ¶m);
}
+#endif
+}
+
+static void
+block_sigchld()
+{
+ sigset_t mask;
+ sigemptyset (&mask);
+ sigaddset (&mask, SIGCHLD);
+ int c = pthread_sigmask (SIG_BLOCK, &mask, NULL);
+ if (c != 0)
+ throw new java::lang::InternalError (JvNewStringUTF (strerror (c)));
}
void
_Jv_self_cache[current_index].high_sp_bits = BAD_HIGH_SP_VALUE;
}
# endif
+ // Block SIGCHLD which is used in natPosixProcess.cc.
+ block_sigchld();
}
void
return;
data->flags |= FLAG_START;
+ // Block SIGCHLD which is used in natPosixProcess.cc.
+ // The current mask is inherited by the child thread.
+ block_sigchld();
+
param.sched_priority = thread->getPriority();
pthread_attr_init (&attr);
#if defined(SLOW_PTHREAD_SELF)
-// Support for pthread_self() lookup cache.
+#include "sysdep/locks.h"
+// Support for pthread_self() lookup cache.
volatile self_cache_entry _Jv_self_cache[SELF_CACHE_SIZE];
-
_Jv_ThreadId_t
_Jv_ThreadSelf_out_of_line(volatile self_cache_entry *sce, size_t high_sp_bits)
{
pthread_t self = pthread_self();
- // The ordering between the following writes matters.
- // On Alpha, we probably need a memory barrier in the middle.
sce -> high_sp_bits = high_sp_bits;
+ write_barrier();
sce -> self = self;
return self;
}