#if defined(ENABLE_JVMTI)
# include "native/jvmti/jvmti.h"
# include "native/jvmti/cacaodbg.h"
+# include "threads/mutex.h"
#endif
#include "vm/vm.h"
(void) vm_createjvm(&vm, (void *) &env, vm_args);
#if defined(ENABLE_JVMTI)
- pthread_mutex_init(&dbgcomlock,NULL);
+ mutex_init(&dbgcomlock);
if (jvmti) jvmti_set_phase(JVMTI_PHASE_START);
#endif
## src/mm/Makefile.am
##
-## Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
-## C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-## E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-## J. Wenninger, Institut f. Computersprachen - TU Wien
+## Copyright (C) 1996-2005, 2006, 2007, 2008
+## CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
##
## This file is part of CACAO.
##
#include "vm/jit/asmpart.h"
#include "vm/stringlocal.h"
#include "toolbox/logging.h"
+#include "threads/mutex.h"
#include "threads/thread.h"
#include <sys/types.h>
void jvmti_set_system_breakpoint(int sysbrk, bool mode) {
struct brkpts *jvmtibrkpt;
- pthread_mutex_lock(&dbgcomlock);
+ mutex_lock(&dbgcomlock);
jvmtibrkpt = &dbgcom->jvmtibrkpt;
assert (sysbrk < BEGINUSERBRK);
/* add breakpoint*/
if (jvmtibrkpt->brk[sysbrk].count > 0) {
jvmtibrkpt->brk[sysbrk].count++;
- pthread_mutex_unlock(&dbgcomlock);
+ mutex_unlock(&dbgcomlock);
return;
}
dbgcom->addbrkpt = true;
} else {
/* avoid negative counter values */
if (jvmtibrkpt->brk[sysbrk].count > 0) jvmtibrkpt->brk[sysbrk].count--;
- pthread_mutex_unlock(&dbgcomlock);
+ mutex_unlock(&dbgcomlock);
return;
}
}
- pthread_mutex_unlock(&dbgcomlock);
+ mutex_unlock(&dbgcomlock);
/* call cacaodbgserver */
__asm__ ("setsysbrkpt:");
TRAP;
void jvmti_add_breakpoint(void* addr, jmethodID method, jlocation location) {
struct brkpts *jvmtibrkpt;
- pthread_mutex_lock(&dbgcomlock);
+ mutex_lock(&dbgcomlock);
jvmtibrkpt = &dbgcom->jvmtibrkpt;;
if (jvmtibrkpt->size == jvmtibrkpt->num)
/* todo: set breakpoint */
/* jvmtibrkpt.brk[jvmtibrkpt.num].orig = */
jvmtibrkpt->num++;
- pthread_mutex_unlock(&dbgcomlock);
+ mutex_unlock(&dbgcomlock);
fprintf (stderr,"add brk done\n");
}
*******************************************************************************/
void jvmti_cacaodbgserver_quit(){
- pthread_mutex_lock(&dbgcomlock);
+ mutex_lock(&dbgcomlock);
dbgcom->running--;
if (dbgcom->running == 0) {
__asm__ ("cacaodbgserver_quit:");
wait(NULL);
dbgcom = NULL;
}
- pthread_mutex_unlock(&dbgcomlock);
+ mutex_unlock(&dbgcomlock);
}
pid_t dbgserver;
/* start new cacaodbgserver if needed*/
- pthread_mutex_lock(&dbgcomlock);
+ mutex_lock(&dbgcomlock);
if (dbgcom == NULL) {
dbgcom = heap_allocate(sizeof(cacaodbgcommunication),true,NULL);
dbgcom->running = 1;
}
}
}
- pthread_mutex_unlock(&dbgcomlock);
+ mutex_unlock(&dbgcomlock);
/* let cacaodbgserver get ready */
sleep(1);
} else {
dbgcom->running++;
- pthread_mutex_unlock(&dbgcomlock);
+ mutex_unlock(&dbgcomlock);
}
}
#ifndef _CACAODBG_H
#define _CACAODBG_H
+#include "threads/mutex.h"
#include "threads/thread.h"
#include "native/jvmti/jvmti.h"
#include "native/include/java_lang_String.h"
bool jvmti; /* jvmti agent */
-extern pthread_mutex_t dbgcomlock;
+extern mutex_t dbgcomlock;
jvmtiEnv* jvmti_new_environment();
void jvmti_set_phase(jvmtiPhase p);
#include "vm/options.h"
#include "vm/stringlocal.h"
#include "mm/memory.h"
+#include "threads/mutex.h"
#include "threads/thread.h"
#include "threads/lock-common.h"
#include "vm/exceptions.h"
typedef struct _environment environment;
static environment *envs=NULL;
-pthread_mutex_t dbgcomlock;
+mutex_t dbgcomlock;
extern const struct JNIInvokeInterface _Jv_JNIInvokeInterface;
om=MNEW(java_objectheader*,size);
- pthread_mutex_lock(&lock_global_pool_lock);
+ mutex_lock(&lock_global_pool_lock);
lrp=lock_global_pool;
/* iterate over all lock record pools */
lrp=lrp->header.next;
}
- pthread_mutex_unlock(&lock_global_pool_lock);
+ mutex_unlock(&lock_global_pool_lock);
*owned_monitors_ptr =
heap_allocate(sizeof(java_objectheader*) * i, true, NULL);
#if defined(ENABLE_THREADS)
- pthread_mutex_lock(&lock_global_pool_lock);
+ mutex_lock(&lock_global_pool_lock);
lrp=lock_global_pool;
lrp=lrp->header.next;
}
- pthread_mutex_unlock(&lock_global_pool_lock);
+ mutex_unlock(&lock_global_pool_lock);
#endif
critical.c \
critical.h \
lock-common.h \
+ mutex.h \
threadlist.c \
threadlist.h \
thread.c \
--- /dev/null
+/* src/threads/mutex.h - machine independent mutual exclusion functions
+
+ Copyright (C) 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+*/
+
+
+#ifndef _MUTEX_H
+#define _MUTEX_H
+
+#include "config.h"
+
+#if defined(ENABLE_THREADS)
+# include "threads/posix/mutex-posix.h"
+#endif
+
+
+#endif /* _MUTEX_H */
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
libposix_la_SOURCES = \
lock.c \
lock.h \
+ mutex-posix.h \
threadlist-posix.c \
thread-posix.c \
thread-posix.h
## c-basic-offset: 4
## tab-width: 8
## compile-command: "automake --add-missing"
-## End:
\ No newline at end of file
+## End:
#include <pthread.h>
-extern pthread_mutex_t _cas_lock;
-extern pthread_mutex_t _mb_lock;
+#include "threads/mutex.h"
+
+
+extern mutex_t _cas_lock;
+extern mutex_t _mb_lock;
static inline long compare_and_swap(volatile long *p, long oldval, long newval)
{
long ret;
- pthread_mutex_lock(&_cas_lock);
+ mutex_lock(&_cas_lock);
/* do the compare-and-swap */
if (oldval == ret)
*p = newval;
- pthread_mutex_unlock(&_cas_lock);
+ mutex_unlock(&_cas_lock);
return ret;
}
-#define MEMORY_BARRIER() (pthread_mutex_lock(&_mb_lock), \
- pthread_mutex_unlock(&_mb_lock))
+#define MEMORY_BARRIER() (mutex_lock(&_mb_lock), \
+ mutex_unlock(&_mb_lock))
#define STORE_ORDER_BARRIER() MEMORY_BARRIER()
#define MEMORY_BARRIER_AFTER_ATOMIC() /* nothing */
#include "native/llni.h"
#include "threads/lock-common.h"
+#include "threads/mutex.h"
#include "threads/threadlist.h"
#include "threads/thread.h"
static lock_record_t *lock_record_new(void)
{
- int result;
lock_record_t *lr;
/* allocate the data structure on the C heap */
/* initialize the mutex */
- result = pthread_mutex_init(&(lr->mutex), NULL);
- if (result != 0)
- vm_abort_errnum(result, "lock_record_new: pthread_mutex_init failed");
+ mutex_init(&(lr->mutex));
DEBUGLOCKS(("[lock_record_new : lr=%p]", (void *) lr));
static void lock_record_free(lock_record_t *lr)
{
- int result;
-
DEBUGLOCKS(("[lock_record_free : lr=%p]", (void *) lr));
/* Destroy the mutex. */
- result = pthread_mutex_destroy(&(lr->mutex));
- if (result != 0)
- vm_abort_errnum(result, "lock_record_free: pthread_mutex_destroy failed");
+ mutex_destroy(&(lr->mutex));
#if defined(ENABLE_GC_CACAO)
/* unregister the lock object reference with the GC */
static void lock_hashtable_init(void)
{
- pthread_mutex_init(&(lock_hashtable.mutex), NULL);
+ mutex_init(&(lock_hashtable.mutex));
lock_hashtable.size = LOCK_INITIAL_HASHTABLE_SIZE;
lock_hashtable.entries = 0;
/* lock the hashtable */
- pthread_mutex_lock(&(lock_hashtable.mutex));
+ mutex_lock(&(lock_hashtable.mutex));
/* search the hashtable for cleared references */
/* unlock the hashtable */
- pthread_mutex_unlock(&(lock_hashtable.mutex));
+ mutex_unlock(&(lock_hashtable.mutex));
}
#endif
/* lock the hashtable */
- pthread_mutex_lock(&(lock_hashtable.mutex));
+ mutex_lock(&(lock_hashtable.mutex));
/* lookup the lock record in the hashtable */
/* unlock the hashtable */
- pthread_mutex_unlock(&(lock_hashtable.mutex));
+ mutex_unlock(&(lock_hashtable.mutex));
/* return the new lock record */
/* lock the hashtable */
- pthread_mutex_lock(&(lock_hashtable.mutex));
+ mutex_lock(&(lock_hashtable.mutex));
/* get lock record */
/* unlock the hashtable */
- pthread_mutex_unlock(&(lock_hashtable.mutex));
+ mutex_unlock(&(lock_hashtable.mutex));
/* free the lock record */
static inline void lock_record_enter(threadobject *t, lock_record_t *lr)
{
- pthread_mutex_lock(&(lr->mutex));
+ mutex_lock(&(lr->mutex));
lr->owner = t;
}
static inline void lock_record_exit(threadobject *t, lock_record_t *lr)
{
lr->owner = NULL;
- pthread_mutex_unlock(&(lr->mutex));
+ mutex_unlock(&(lr->mutex));
}
/* failure, TODO: add statistics */
return;
- pthread_mutex_lock(&t_other->flc_lock);
+ mutex_lock(&t_other->flc_lock);
old_flc = t_other->flc_bit;
t_other->flc_bit = true;
else
t_other->flc_bit = old_flc;
- pthread_mutex_unlock(&t_other->flc_lock);
+ mutex_unlock(&t_other->flc_lock);
}
static void notify_flc_waiters(threadobject *t, java_handle_t *o)
{
threadobject *current;
- pthread_mutex_lock(&t->flc_lock);
+ mutex_lock(&t->flc_lock);
current = t->flc_list;
while (current)
t->flc_list = NULL;
t->flc_bit = false;
- pthread_mutex_unlock(&t->flc_lock);
+ mutex_unlock(&t->flc_lock);
}
/* lock_monitor_enter **********************************************************
/* unlock this lock record */
lr->owner = NULL;
- pthread_mutex_unlock(&(lr->mutex));
+ mutex_unlock(&(lr->mutex));
return true;
}
/* Enter the wait-mutex. */
- pthread_mutex_lock(&(waitingthread->waitmutex));
+ mutex_lock(&(waitingthread->waitmutex));
DEBUGLOCKS(("[lock_record_notify: lr=%p, t=%p, waitingthread=%p, sleeping=%d, one=%d]",
lr, t, waitingthread, waitingthread->sleeping, one));
/* Leave the wait-mutex. */
- pthread_mutex_unlock(&(waitingthread->waitmutex));
+ mutex_unlock(&(waitingthread->waitmutex));
/* if we should only wake one, we are done */
#include "native/llni.h"
+#include "threads/mutex.h"
+
#include "toolbox/list.h"
#include "vm/global.h"
java_object_t *object; /* object for which this lock is */
struct threadobject *owner; /* current owner of this monitor */
s4 count; /* recursive lock count */
- pthread_mutex_t mutex; /* mutex for synchronizing */
+ mutex_t mutex; /* mutex for synchronizing */
list_t *waiters; /* list of threads waiting */
lock_record_t *hashlink; /* next record in hash chain */
};
*******************************************************************************/
struct lock_hashtable_t {
- pthread_mutex_t mutex; /* mutex for synch. access to the table */
+ mutex_t mutex; /* mutex for synch. access to the table */
u4 size; /* number of slots */
u4 entries; /* current number of entries */
lock_record_t **ptr; /* the table of slots, uses ext. chain. */
--- /dev/null
+/* src/threads/posix/mutex-posix.h - POSIX mutual exclusion functions
+
+ Copyright (C) 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+ This file is part of CACAO.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+*/
+
+
+#ifndef _MUTEX_POSIX_H
+#define _MUTEX_POSIX_H
+
+#include "config.h"
+
+#include <pthread.h>
+
+#include "vm/vm.h"
+
+
+/* POSIX mutex object *********************************************************/
+
+typedef pthread_mutex_t mutex_t;
+
+
+/* static mutex initializer ***************************************************/
+
+#define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+
+
+/* inline functions ***********************************************************/
+
+/* mutex_init ******************************************************************
+
+ Initializes the given mutex object and checks for errors.
+
+ ARGUMENTS:
+ mutex ... POSIX mutex object
+
+*******************************************************************************/
+
+inline static void mutex_init(mutex_t *mutex)
+{
+ int result;
+
+ result = pthread_mutex_init(mutex, NULL);
+
+ if (result != 0)
+ vm_abort_errnum(result, "mutex_init: pthread_mutex_init failed");
+}
+
+
+/* mutex_lock ******************************************************************
+
+ Locks the given mutex object and checks for errors. If the mutex is
+ already locked by another thread, the calling thread is suspended until
+ the mutex is unlocked.
+
+ If the mutex is already locked by the calling thread, the same applies,
+ thus effectively causing the calling thread to deadlock. (This is because
+ we use "fast" pthread mutexes without error checking.)
+
+ ARGUMENTS:
+ mutex ... POSIX mutex object
+
+*******************************************************************************/
+
+inline static void mutex_lock(mutex_t *mutex)
+{
+ int result;
+
+ result = pthread_mutex_lock(mutex);
+
+ if (result != 0)
+ vm_abort_errnum(result, "mutex_lock: pthread_mutex_lock failed");
+}
+
+
+/* mutex_unlock ****************************************************************
+
+ Unlocks the given mutex object and checks for errors. The mutex is
+ assumed to be locked and owned by the calling thread.
+
+ ARGUMENTS:
+ mutex ... POSIX mutex object
+
+*******************************************************************************/
+
+inline static void mutex_unlock(mutex_t *mutex)
+{
+ int result;
+
+ result = pthread_mutex_unlock(mutex);
+
+ if (result != 0)
+ vm_abort_errnum(result, "mutex_unlock: pthread_mutex_unlock failed");
+}
+
+
+/* mutex_destroy ***************************************************************
+
+ Destroys the given mutex object and checks for errors.
+
+ ARGUMENTS:
+ mutex ... POSIX mutex object
+
+*******************************************************************************/
+
+inline static void mutex_destroy(mutex_t *mutex)
+{
+ int result;
+
+ result = pthread_mutex_destroy(mutex);
+
+ if (result != 0)
+ vm_abort_errnum(result, "mutex_destroy: pthread_mutex_destroy failed");
+}
+
+
+#endif /* _MUTEX_POSIX_H */
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
#endif
#include "threads/lock-common.h"
+#include "threads/mutex.h"
#include "threads/threadlist.h"
#include "threads/thread.h"
sem->value = value;
- if (pthread_mutex_init(&sem->mutex, NULL) < 0)
- return -1;
+ mutex_init(&sem->mutex, NULL)
if (pthread_cond_init(&sem->cond, NULL) < 0)
return -1;
static int sem_post(sem_t *sem)
{
- if (pthread_mutex_lock(&sem->mutex) < 0)
- return -1;
+ mutex_lock(&sem->mutex)
sem->value++;
if (pthread_cond_signal(&sem->cond) < 0) {
- pthread_mutex_unlock(&sem->mutex);
+ mutex_unlock(&sem->mutex);
return -1;
}
- if (pthread_mutex_unlock(&sem->mutex) < 0)
- return -1;
+ mutex_unlock(&sem->mutex)
return 0;
}
static int sem_wait(sem_t *sem)
{
- if (pthread_mutex_lock(&sem->mutex) < 0)
- return -1;
+ mutex_lock(&sem->mutex)
while (sem->value == 0) {
pthread_cond_wait(&sem->cond, &sem->mutex);
sem->value--;
- if (pthread_mutex_unlock(&sem->mutex) < 0)
- return -1;
+ mutex_unlock(&sem->mutex)
return 0;
}
if (pthread_cond_destroy(&sem->cond) < 0)
return -1;
- if (pthread_mutex_destroy(&sem->mutex) < 0)
- return -1;
+ mutex_destroy(&sem->mutex)
return 0;
}
#endif
/* global mutex for stop-the-world */
-static pthread_mutex_t stopworldlock;
+static mutex_t stopworldlock;
#if defined(ENABLE_GC_CACAO)
/* global mutex for the GC */
-static pthread_mutex_t mutex_gc;
+static mutex_t mutex_gc;
#endif
/* global mutex and condition for joining threads on exit */
-static pthread_mutex_t mutex_join;
+static mutex_t mutex_join;
static pthread_cond_t cond_join;
/* XXX We disable that whole bunch of code until we have the exact-GC
/* semaphore used for acknowleding thread suspension */
static sem_t suspend_ack;
#if defined(__IRIX__)
-static pthread_mutex_t suspend_ack_lock = PTHREAD_MUTEX_INITIALIZER;
+static mutex_t suspend_ack_lock = MUTEX_INITIALIZER;
static pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER;
#endif
/* mutexes used by the fake atomic instructions */
#if defined(USE_FAKE_ATOMIC_INSTRUCTIONS)
-pthread_mutex_t _cas_lock = PTHREAD_MUTEX_INITIALIZER;
-pthread_mutex_t _mb_lock = PTHREAD_MUTEX_INITIALIZER;
+mutex_t _cas_lock = MUTEX_INITIALIZER;
+mutex_t _mb_lock = MUTEX_INITIALIZER;
#endif
void lock_stopworld(int where)
{
- pthread_mutex_lock(&stopworldlock);
+ mutex_lock(&stopworldlock);
/* stopworldwhere = where; */
}
void unlock_stopworld(void)
{
/* stopworldwhere = 0; */
- pthread_mutex_unlock(&stopworldlock);
+ mutex_unlock(&stopworldlock);
}
/* XXX We disable that whole bunch of code until we have the exact-GC
#if defined(__IRIX__)
static void threads_cast_irixresume(void)
{
- pthread_mutex_lock(&suspend_ack_lock);
+ mutex_lock(&suspend_ack_lock);
pthread_cond_broadcast(&suspend_cond);
- pthread_mutex_unlock(&suspend_ack_lock);
+ mutex_unlock(&suspend_ack_lock);
}
#endif
/* Do as Boehm does. On IRIX a condition variable is used for wake-up
(not POSIX async-safe). */
#if defined(__IRIX__)
- pthread_mutex_lock(&suspend_ack_lock);
+ mutex_lock(&suspend_ack_lock);
threads_sem_post(&suspend_ack);
pthread_cond_wait(&suspend_cond, &suspend_ack_lock);
- pthread_mutex_unlock(&suspend_ack_lock);
+ mutex_unlock(&suspend_ack_lock);
#elif defined(__CYGWIN__)
/* TODO */
assert(0);
/* initialize the mutex and the condition */
- result = pthread_mutex_init(&t->flc_lock, NULL);
- if (result != 0)
- vm_abort_errnum(result, "threads_impl_thread_new: pthread_mutex_init failed");
+ mutex_init(&t->flc_lock);
result = pthread_cond_init(&t->flc_cond, NULL);
if (result != 0)
vm_abort_errnum(result, "threads_impl_thread_new: pthread_cond_init failed");
- result = pthread_mutex_init(&(t->waitmutex), NULL);
- if (result != 0)
- vm_abort_errnum(result, "threads_impl_thread_new: pthread_mutex_init failed");
+ mutex_init(&(t->waitmutex));
result = pthread_cond_init(&(t->waitcond), NULL);
if (result != 0)
vm_abort_errnum(result, "threads_impl_thread_new: pthread_cond_init failed");
- result = pthread_mutex_init(&(t->suspendmutex), NULL);
- if (result != 0)
- vm_abort_errnum(result, "threads_impl_thread_new: pthread_mutex_init failed");
+ mutex_init(&(t->suspendmutex));
result = pthread_cond_init(&(t->suspendcond), NULL);
if (result != 0)
/* Destroy the mutex and the condition. */
- result = pthread_mutex_destroy(&(t->flc_lock));
-
- if (result != 0)
- vm_abort_errnum(result, "threads_impl_thread_free: pthread_mutex_destroy failed");
+ mutex_destroy(&(t->flc_lock));
result = pthread_cond_destroy(&(t->flc_cond));
if (result != 0)
vm_abort_errnum(result, "threads_impl_thread_free: pthread_cond_destroy failed");
- result = pthread_mutex_destroy(&(t->waitmutex));
-
- if (result != 0)
- vm_abort_errnum(result, "threads_impl_thread_free: pthread_mutex_destroy failed");
+ mutex_destroy(&(t->waitmutex));
result = pthread_cond_destroy(&(t->waitcond));
if (result != 0)
vm_abort_errnum(result, "threads_impl_thread_free: pthread_cond_destroy failed");
- result = pthread_mutex_destroy(&(t->suspendmutex));
-
- if (result != 0)
- vm_abort_errnum(result, "threads_impl_thread_free: pthread_mutex_destroy failed");
+ mutex_destroy(&(t->suspendmutex));
result = pthread_cond_destroy(&(t->suspendcond));
{
int result;
- result = pthread_mutex_init(&stopworldlock, NULL);
- if (result != 0)
- vm_abort_errnum(result, "threads_impl_preinit: pthread_mutex_init failed");
+ mutex_init(&stopworldlock);
/* initialize exit mutex and condition (on exit we join all
threads) */
- result = pthread_mutex_init(&mutex_join, NULL);
- if (result != 0)
- vm_abort_errnum(result, "threads_impl_preinit: pthread_mutex_init failed");
+ mutex_init(&mutex_join);
result = pthread_cond_init(&cond_join, NULL);
if (result != 0)
#if defined(ENABLE_GC_CACAO)
/* initialize the GC mutext */
- result = pthread_mutex_init(&mutex_gc, NULL);
- if (result != 0)
- vm_abort_errnum(result, "threads_impl_preinit: pthread_mutex_init failed");
+ mutex_init(&mutex_gc);
#endif
#if !defined(HAVE___THREAD)
#if defined(ENABLE_GC_CACAO)
void threads_mutex_gc_lock(void)
{
- int result;
-
- result = pthread_mutex_lock(&mutex_gc);
-
- if (result != 0)
- vm_abort_errnum(result, "threads_mutex_gc_lock: pthread_mutex_lock failed");
+ mutex_lock(&mutex_gc);
}
#endif
#if defined(ENABLE_GC_CACAO)
void threads_mutex_gc_unlock(void)
{
- int result;
-
- result = pthread_mutex_unlock(&mutex_gc);
-
- if (result != 0)
- vm_abort_errnum(result, "threads_mutex_gc_unlock: pthread_mutex_unlock failed");
+ mutex_unlock(&mutex_gc);
}
#endif
void threads_mutex_join_lock(void)
{
- int result;
-
- result = pthread_mutex_lock(&mutex_join);
-
- if (result != 0)
- vm_abort_errnum(result, "threads_mutex_join_lock: pthread_mutex_lock failed");
+ mutex_lock(&mutex_join);
}
void threads_mutex_join_unlock(void)
{
- int result;
-
- result = pthread_mutex_unlock(&mutex_join);
-
- if (result != 0)
- vm_abort_errnum(result, "threads_mutex_join_unlock: pthread_mutex_unlock failed");
+ mutex_unlock(&mutex_join);
}
bool threads_suspend_thread(threadobject *thread, s4 reason)
{
/* acquire the suspendmutex */
- if (pthread_mutex_lock(&(thread->suspendmutex)) != 0)
- vm_abort("threads_suspend_thread: pthread_mutex_lock failed: %s",
- strerror(errno));
+ mutex_lock(&(thread->suspendmutex));
if (thread->suspended) {
- pthread_mutex_unlock(&(thread->suspendmutex));
+ mutex_unlock(&(thread->suspendmutex));
return false;
}
/* TODO: free dump memory */
/* release the suspendmutex */
- if (pthread_mutex_unlock(&(thread->suspendmutex)) != 0)
- vm_abort("threads_suspend_ack: pthread_mutex_unlock failed: %s",
- strerror(errno));
+ mutex_unlock(&(thread->suspendmutex));
}
bool threads_resume_thread(threadobject *thread)
{
/* acquire the suspendmutex */
- if (pthread_mutex_lock(&(thread->suspendmutex)) != 0)
- vm_abort("threads_resume_ack: pthread_mutex_unlock failed: %s",
- strerror(errno));
+ mutex_lock(&(thread->suspendmutex));
if (!thread->suspended) {
- pthread_mutex_unlock(&(thread->suspendmutex));
+ mutex_unlock(&(thread->suspendmutex));
return false;
}
pthread_cond_broadcast(&(thread->suspendcond));
/* release the suspendmutex */
- pthread_mutex_unlock(&(thread->suspendmutex));
+ mutex_unlock(&(thread->suspendmutex));
return true;
}
{
/* acquire the waitmutex */
- pthread_mutex_lock(&t->waitmutex);
+ mutex_lock(&t->waitmutex);
/* mark us as sleeping */
/* release the waitmutex */
- pthread_mutex_unlock(&t->waitmutex);
+ mutex_unlock(&t->waitmutex);
}
/* Signal the thread a "waitcond" and tell it that it has been
interrupted. */
- pthread_mutex_lock(&thread->waitmutex);
+ mutex_lock(&thread->waitmutex);
DEBUGTHREADS("interrupted", thread);
thread->interrupted = true;
- pthread_mutex_unlock(&thread->waitmutex);
+ mutex_unlock(&thread->waitmutex);
}
thread = THREADOBJECT;
- pthread_mutex_lock(&thread->waitmutex);
+ mutex_lock(&thread->waitmutex);
/* get interrupted flag */
thread->interrupted = false;
- pthread_mutex_unlock(&thread->waitmutex);
+ mutex_unlock(&thread->waitmutex);
return intr;
}
#include "native/localref.h"
+#include "threads/mutex.h"
+
#include "threads/posix/lock.h"
#include "vm/global.h"
# include <mach/mach.h>
typedef struct {
- pthread_mutex_t mutex;
+ mutex_t mutex;
pthread_cond_t cond;
int value;
} sem_t;
struct threadobject *flc_list; /* FLC list head for this thread */
struct threadobject *flc_next; /* next pointer for FLC list */
java_handle_t *flc_object;
- pthread_mutex_t flc_lock; /* controlling access to these fields */
+ mutex_t flc_lock; /* controlling access to these fields */
pthread_cond_t flc_cond;
/* these are used for the wait/notify implementation */
- pthread_mutex_t waitmutex;
+ mutex_t waitmutex;
pthread_cond_t waitcond;
- pthread_mutex_t suspendmutex; /* lock before suspending this thread */
+ mutex_t suspendmutex; /* lock before suspending this thread */
pthread_cond_t suspendcond; /* notify to resume this thread */
bool interrupted;
#include "config.h"
-#include <pthread.h>
+#include "threads/mutex.h"
#include "vm/vm.h"
/* global variables ***********************************************************/
/* global mutex for the thread list */
-static pthread_mutex_t threadlist_mutex;
+static mutex_t threadlist_mutex;
/* threadlist_impl_init ********************************************************
void threadlist_impl_init(void)
{
- int result;
-
TRACESUBSYSTEMINITIALIZATION("threadlist_impl_init");
/* Initialize the thread list mutex. */
- result = pthread_mutex_init(&threadlist_mutex, NULL);
-
- if (result != 0)
- vm_abort_errnum(result, "threadlist_impl_init: pthread_mutex_init failed");
+ mutex_init(&threadlist_mutex);
}
void threadlist_lock(void)
{
- int result;
-
- result = pthread_mutex_lock(&threadlist_mutex);
-
- if (result != 0)
- vm_abort_errnum(result, "threads_list_lock: pthread_mutex_lock failed");
+ mutex_lock(&threadlist_mutex);
}
void threadlist_unlock(void)
{
- int result;
-
- result = pthread_mutex_unlock(&threadlist_mutex);
-
- if (result != 0)
- vm_abort_errnum(result, "threadlist_unlock: pthread_mutex_unlock failed");
+ mutex_unlock(&threadlist_mutex);
}
#include "native/vm/nativevm.h"
#include "threads/lock-common.h"
+#include "threads/mutex.h"
#include "threads/threadlist.h"
#include "threads/thread.h"
#if defined(ENABLE_JVMTI)
/* terminate cacaodbgserver */
if (dbgcom!=NULL) {
- pthread_mutex_lock(&dbgcomlock);
+ mutex_lock(&dbgcomlock);
dbgcom->running=1;
- pthread_mutex_unlock(&dbgcomlock);
+ mutex_unlock(&dbgcomlock);
jvmti_cacaodbgserver_quit();
}
#endif