14 #include "mm/memory.h"
15 #include "native/native.h"
16 #include "native/include/java_lang_Object.h"
17 #include "native/include/java_lang_Throwable.h"
18 #include "native/include/java_lang_Thread.h"
19 #include "native/include/java_lang_ThreadGroup.h"
20 #include "native/include/java_lang_VMThread.h"
21 #include "threads/native/threads.h"
22 #include "toolbox/avl.h"
23 #include "toolbox/logging.h"
24 #include "vm/builtin.h"
25 #include "vm/exceptions.h"
26 #include "vm/global.h"
27 #include "vm/loader.h"
28 #include "vm/tables.h"
29 #include "vm/jit/asmpart.h"
32 #include <semaphore.h>
34 #if !defined(__DARWIN__)
35 #if defined(__LINUX__)
36 #define GC_LINUX_THREADS
37 #elif defined(__MIPS__)
38 #define GC_IRIX_THREADS
40 #include "boehm-gc/include/gc.h"
45 /* We need this for older MacOSX (10.1.x) */
48 pthread_mutex_t mutex;
51 } pthread_mutex_rec_t;
53 static void pthread_mutex_init_rec(pthread_mutex_rec_t *m)
55 pthread_mutex_init(&m->mutex, NULL);
59 static void pthread_mutex_destroy_rec(pthread_mutex_rec_t *m)
61 pthread_mutex_destroy(&m->mutex);
64 static void pthread_mutex_lock_rec(pthread_mutex_rec_t *m)
69 pthread_mutex_lock(&m->mutex);
70 m->owner = pthread_self();
74 if (m->owner != pthread_self())
75 pthread_mutex_lock(&m->mutex);
84 static void pthread_mutex_unlock_rec(pthread_mutex_rec_t *m)
87 pthread_mutex_unlock(&m->mutex);
92 #define pthread_mutex_lock_rec pthread_mutex_lock
93 #define pthread_mutex_unlock_rec pthread_mutex_unlock
94 #define pthread_mutex_rec_t pthread_mutex_t
98 static void setPriority(pthread_t tid, int priority)
100 struct sched_param schedp;
103 pthread_getschedparam(tid, &policy, &schedp);
104 schedp.sched_priority = priority;
105 pthread_setschedparam(tid, policy, &schedp);
108 #include "machine-instr.h"
110 static struct avl_table *criticaltree;
111 static threadobject *mainthreadobj;
113 #ifndef HAVE___THREAD
114 pthread_key_t tkey_threadinfo;
116 __thread threadobject *threadobj;
119 static pthread_mutex_rec_t compiler_mutex;
120 static pthread_mutex_rec_t tablelock;
124 pthread_mutex_lock_rec(&compiler_mutex);
127 void compiler_unlock()
129 pthread_mutex_unlock_rec(&compiler_mutex);
134 pthread_mutex_lock_rec(&tablelock);
139 pthread_mutex_unlock_rec(&tablelock);
142 static int criticalcompare(const void *pa, const void *pb, void *param)
144 const threadcritnode *na = pa;
145 const threadcritnode *nb = pb;
147 if (na->mcodebegin < nb->mcodebegin)
149 if (na->mcodebegin > nb->mcodebegin)
154 static const threadcritnode *findcritical(u1 *mcodeptr)
156 struct avl_node *n = criticaltree->avl_root;
157 const threadcritnode *m = NULL;
162 const threadcritnode *d = n->avl_data;
163 if (mcodeptr == d->mcodebegin)
165 if (mcodeptr < d->mcodebegin) {
171 if (n->avl_link[1]) {
180 void thread_registercritical(threadcritnode *n)
182 avl_insert(criticaltree, n);
185 u1 *thread_checkcritical(u1 *mcodeptr)
187 const threadcritnode *n = findcritical(mcodeptr);
188 return (n && mcodeptr < n->mcodeend && mcodeptr > n->mcodebegin) ? n->mcoderestart : NULL;
191 static void thread_addstaticcritical()
193 threadcritnode *n = &asm_criticalsections;
195 while (n->mcodebegin)
196 thread_registercritical(n++);
199 static pthread_mutex_t threadlistlock;
201 static pthread_mutex_t stopworldlock;
202 volatile int stopworldwhere;
204 static sem_t suspend_ack;
205 #if defined(__MIPS__)
206 static pthread_mutex_t suspend_ack_lock = PTHREAD_MUTEX_INITIALIZER;
207 static pthread_cond_t suspend_cond = PTHREAD_COND_INITIALIZER;
211 * where - 1 from within GC
214 void lock_stopworld(int where)
216 pthread_mutex_lock(&stopworldlock);
217 stopworldwhere = where;
220 void unlock_stopworld()
223 pthread_mutex_unlock(&stopworldlock);
226 #if !defined(__DARWIN__)
227 /* Caller must hold threadlistlock */
228 static int cast_sendsignals(int sig, int count)
231 threadobject *tobj = mainthreadobj;
232 nativethread *infoself = THREADINFO;
237 tobj = tobj->info.next;
238 } while (tobj != mainthreadobj);
241 nativethread *info = &tobj->info;
242 if (info != infoself)
243 pthread_kill(info->tid, sig);
244 tobj = tobj->info.next;
245 } while (tobj != mainthreadobj);
252 static void cast_darwinstop()
254 threadobject *tobj = mainthreadobj;
255 nativethread *infoself = THREADINFO;
258 nativethread *info = &tobj->info;
259 if (info != infoself)
261 thread_state_flavor_t flavor = PPC_THREAD_STATE;
262 mach_msg_type_number_t thread_state_count = PPC_THREAD_STATE_COUNT;
263 ppc_thread_state_t thread_state;
264 mach_port_t thread = info->mach_thread;
267 r = thread_suspend(thread);
268 if (r != KERN_SUCCESS)
269 panic("thread_suspend failed");
271 r = thread_get_state(thread, flavor,
272 (natural_t*)&thread_state, &thread_state_count);
273 if (r != KERN_SUCCESS)
274 panic("thread_get_state failed");
276 thread_restartcriticalsection(&thread_state);
278 r = thread_set_state(thread, flavor,
279 (natural_t*)&thread_state, thread_state_count);
280 if (r != KERN_SUCCESS)
281 panic("thread_set_state failed");
283 tobj = tobj->info.next;
284 } while (tobj != mainthreadobj);
287 static void cast_darwinresume()
289 threadobject *tobj = mainthreadobj;
290 nativethread *infoself = THREADINFO;
293 nativethread *info = &tobj->info;
294 if (info != infoself)
296 mach_port_t thread = info->mach_thread;
299 r = thread_resume(thread);
300 if (r != KERN_SUCCESS)
301 panic("thread_resume failed");
303 tobj = tobj->info.next;
304 } while (tobj != mainthreadobj);
309 #if defined(__MIPS__)
310 static void cast_irixresume()
312 pthread_mutex_lock(&suspend_ack_lock);
313 pthread_cond_broadcast(&suspend_cond);
314 pthread_mutex_unlock(&suspend_ack_lock);
318 void cast_stopworld()
322 pthread_mutex_lock(&threadlistlock);
323 #if defined(__DARWIN__)
326 count = cast_sendsignals(GC_signum1(), 0);
327 for (i=0; i<count; i++)
328 sem_wait(&suspend_ack);
330 pthread_mutex_unlock(&threadlistlock);
333 void cast_startworld()
335 pthread_mutex_lock(&threadlistlock);
336 #if defined(__DARWIN__)
338 #elif defined(__MIPS__)
341 cast_sendsignals(GC_signum2(), -1);
343 pthread_mutex_unlock(&threadlistlock);
347 #if !defined(__DARWIN__)
348 static void sigsuspend_handler(ucontext_t *ctx)
353 thread_restartcriticalsection(ctx);
355 /* Do as Boehm does. On IRIX a condition variable is used for wake-up
356 (not POSIX async-safe). */
357 #if defined(__IRIX__)
358 pthread_mutex_lock(&suspend_ack_lock);
359 sem_post(&suspend_ack);
360 pthread_cond_wait(&suspend_cond, &suspend_ack_lock);
361 pthread_mutex_unlock(&suspend_ack_lock);
363 sem_post(&suspend_ack);
367 sigdelset(&sigs, sig);
372 int cacao_suspendhandler(ucontext_t *ctx)
374 if (stopworldwhere != 2)
377 sigsuspend_handler(ctx);
382 static void setthreadobject(threadobject *thread)
384 #if !defined(HAVE___THREAD)
385 pthread_setspecific(tkey_threadinfo, thread);
391 static monitorLockRecord *dummyLR;
393 static void initPools();
396 * Initialize threads.
402 pthread_mutexattr_t mutexattr;
403 pthread_mutexattr_init(&mutexattr);
404 pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
405 pthread_mutex_init(&compiler_mutex, &mutexattr);
406 pthread_mutex_init(&tablelock, &mutexattr);
407 pthread_mutexattr_destroy(&mutexattr);
409 pthread_mutex_init_rec(&compiler_mutex);
410 pthread_mutex_init_rec(&tablelock);
413 pthread_mutex_init(&threadlistlock, NULL);
414 pthread_mutex_init(&stopworldlock, NULL);
416 /* Allocate something so the garbage collector's signal handlers are */
418 heap_allocate(1, false, NULL);
420 mainthreadobj = NEW(threadobject);
421 mainthreadobj->info.tid = pthread_self();
422 #if !defined(HAVE___THREAD)
423 pthread_key_create(&tkey_threadinfo, NULL);
425 setthreadobject(mainthreadobj);
428 criticaltree = avl_create(criticalcompare, NULL, NULL);
429 thread_addstaticcritical();
430 sem_init(&suspend_ack, 0, 0);
432 /* Every newly created object's monitorPtr points here so we save a check
434 dummyLR = NEW(monitorLockRecord);
436 dummyLR->ownerThread = NULL;
437 dummyLR->waiting = false;
440 static pthread_attr_t threadattr;
442 static void freeLockRecordPools(lockRecordPool *);
445 initThreads(u1 *stackbottom)
447 classinfo *threadclass;
448 classinfo *threadgroupclass;
449 java_lang_String *threadname;
450 java_lang_Thread *mainthread;
451 java_lang_ThreadGroup *threadgroup;
452 threadobject *tempthread = mainthreadobj;
455 threadclass = class_new(utf_new_char("java/lang/VMThread"));
456 class_load(threadclass);
457 class_link(threadclass);
460 throw_exception_exit();
462 freeLockRecordPools(mainthreadobj->ee.lrpool);
463 /* This is kinda tricky, we grow the java.lang.Thread object so we can keep
464 * the execution environment there. No Thread object must have been created
465 * at an earlier time */
466 threadclass->instancesize = sizeof(threadobject);
468 /* Create a VMThread */
469 mainthreadobj = (threadobject *) builtin_new(threadclass);
472 throw_exception_exit();
474 FREE(tempthread, threadobject);
475 initThread(&mainthreadobj->o);
477 setthreadobject(mainthreadobj);
480 mainthreadobj->info.next = mainthreadobj;
481 mainthreadobj->info.prev = mainthreadobj;
483 threadname = javastring_new(utf_new_char("main"));
485 /* Allocate and init ThreadGroup */
486 threadgroupclass = class_new(utf_new_char("java/lang/ThreadGroup"));
488 (java_lang_ThreadGroup *) native_new_and_init(threadgroupclass);
491 throw_exception_exit();
493 /* Create a Thread */
494 threadclass = class_new(utf_new_char("java/lang/Thread"));
495 mainthread = (java_lang_Thread*) builtin_new(threadclass);
496 mainthreadobj->o.thread = mainthread;
499 throw_exception_exit();
501 /* Call Thread constructor */
502 method = class_resolveclassmethod(threadclass,
503 utf_new_char("<init>"),
504 utf_new_char("(Ljava/lang/VMThread;Ljava/lang/String;IZ)V"),
509 throw_exception_exit();
511 asm_calljavafunction(method, mainthread, mainthreadobj, threadname, (void*) 5);
513 throw_exception_exit();
515 mainthread->group = threadgroup;
516 /* XXX This is a hack because the fourth argument was omitted */
517 mainthread->daemon = false;
519 /* Add mainthread to ThreadGroup */
520 method = class_resolveclassmethod(threadgroupclass,
521 utf_new_char("addThread"),
522 utf_new_char("(Ljava/lang/Thread;)V"),
527 throw_exception_exit();
529 asm_calljavafunction(method, threadgroup, mainthread, NULL, NULL);
531 throw_exception_exit();
533 setPriority(pthread_self(), 5);
535 pthread_attr_init(&threadattr);
536 pthread_attr_setdetachstate(&threadattr, PTHREAD_CREATE_DETACHED);
539 void initThread(java_lang_VMThread *t)
541 threadobject *thread = (threadobject*) t;
542 nativethread *info = &thread->info;
543 info->tid = pthread_self();
544 /* TODO destroy all those things */
545 pthread_mutex_init(&info->joinMutex, NULL);
546 pthread_cond_init(&info->joinCond, NULL);
548 pthread_mutex_init(&thread->waitLock, NULL);
549 pthread_cond_init(&thread->waitCond, NULL);
550 thread->interrupted = false;
551 thread->signaled = false;
552 thread->isSleeping = false;
555 static void initThreadLocks(threadobject *);
558 threadobject *thread;
562 static void *threadstartup(void *t)
564 startupinfo *startup = t;
565 threadobject *thread = startup->thread;
566 sem_t *psem = startup->psem;
567 nativethread *info = &thread->info;
572 #if defined(__DARWIN__)
573 info->mach_thread = mach_thread_self();
575 setthreadobject(thread);
577 pthread_mutex_lock(&threadlistlock);
578 info->prev = mainthreadobj;
579 info->next = tnext = mainthreadobj->info.next;
580 mainthreadobj->info.next = thread;
581 tnext->info.prev = thread;
582 pthread_mutex_unlock(&threadlistlock);
584 initThreadLocks(thread);
589 setPriority(info->tid, thread->o.thread->priority);
592 /* Find the run()V method and call it */
593 method = class_resolveclassmethod(thread->o.header.vftbl->class,
596 thread->o.header.vftbl->class,
599 /* if method != NULL, we had not exception */
601 asm_calljavafunction(method, thread, NULL, NULL, NULL);
607 /* Allow lock record pools to be used by other threads. They cannot be
608 * deleted so we'd better not waste them. */
609 freeLockRecordPools(thread->ee.lrpool);
611 pthread_mutex_lock(&threadlistlock);
612 info->next->info.prev = info->prev;
613 info->prev->info.next = info->next;
614 pthread_mutex_unlock(&threadlistlock);
616 pthread_mutex_lock(&info->joinMutex);
618 pthread_mutex_unlock(&info->joinMutex);
619 pthread_cond_broadcast(&info->joinCond);
624 void startThread(thread *t)
626 nativethread *info = &((threadobject*) t->vmThread)->info;
630 startup.thread = (threadobject*) t->vmThread;
633 sem_init(&sem, 0, 0);
635 if (pthread_create(&info->tid, &threadattr, threadstartup, &startup))
636 panic("pthread_create failed");
638 /* Wait here until the thread has entered itself into the thread list */
643 /* At the end of the program, we wait for all running non-daemon threads to die
646 static threadobject *findNonDaemon(threadobject *thread)
648 while (thread != mainthreadobj) {
649 if (!thread->o.thread->daemon)
651 thread = thread->info.prev;
657 void joinAllThreads()
659 threadobject *thread;
660 pthread_mutex_lock(&threadlistlock);
661 while ((thread = findNonDaemon(mainthreadobj->info.prev)) != NULL) {
662 nativethread *info = &thread->info;
663 pthread_mutex_lock(&info->joinMutex);
664 pthread_mutex_unlock(&threadlistlock);
666 pthread_cond_wait(&info->joinCond, &info->joinMutex);
667 pthread_mutex_unlock(&info->joinMutex);
668 pthread_mutex_lock(&threadlistlock);
670 pthread_mutex_unlock(&threadlistlock);
673 static void initLockRecord(monitorLockRecord *r, threadobject *t)
680 r->incharge = (monitorLockRecord *) &dummyLR;
682 sem_init(&r->queueSem, 0, 0);
683 pthread_mutex_init(&r->resolveLock, NULL);
684 pthread_cond_init(&r->resolveWait, NULL);
687 /* No lock record must ever be destroyed because there may still be references
690 static void destroyLockRecord(monitorLockRecord *r)
692 sem_destroy(&r->queueSem);
693 pthread_mutex_destroy(&r->resolveLock);
694 pthread_cond_destroy(&r->resolveWait);
700 initThreadLocks(mainthreadobj);
703 static void initThreadLocks(threadobject *thread)
705 thread->ee.firstLR = NULL;
706 thread->ee.lrpool = NULL;
707 thread->ee.numlr = 0;
710 static lockRecordPool *allocNewLockRecordPool(threadobject *thread, int size)
712 lockRecordPool *p = mem_alloc(sizeof(lockRecordPoolHeader) + sizeof(monitorLockRecord) * size);
715 p->header.size = size;
716 for (i=0; i<size; i++) {
717 initLockRecord(&p->lr[i], thread);
718 p->lr[i].nextFree = &p->lr[i+1];
720 p->lr[i-1].nextFree = NULL;
724 #define INITIALLOCKRECORDS 8
726 static pthread_mutex_t pool_lock;
727 static lockRecordPool *global_pool;
729 static void initPools()
731 pthread_mutex_init(&pool_lock, NULL);
734 static lockRecordPool *allocLockRecordPool(threadobject *t, int size)
736 pthread_mutex_lock(&pool_lock);
739 lockRecordPool *pool = global_pool;
740 global_pool = pool->header.next;
741 pthread_mutex_unlock(&pool_lock);
743 for (i=0; i < pool->header.size; i++)
744 pool->lr[i].ownerThread = t;
748 pthread_mutex_unlock(&pool_lock);
750 return allocNewLockRecordPool(t, size);
753 static void freeLockRecordPools(lockRecordPool *pool)
755 lockRecordPoolHeader *last;
756 pthread_mutex_lock(&pool_lock);
757 last = &pool->header;
759 last = &last->next->header;
760 last->next = global_pool;
762 pthread_mutex_unlock(&pool_lock);
765 static monitorLockRecord *allocLockRecordSimple(threadobject *t)
767 monitorLockRecord *r = t->ee.firstLR;
770 int poolsize = t->ee.numlr ? t->ee.numlr * 2 : INITIALLOCKRECORDS;
771 lockRecordPool *pool = allocLockRecordPool(t, poolsize);
772 pool->header.next = t->ee.lrpool;
775 t->ee.numlr += pool->header.size;
778 t->ee.firstLR = r->nextFree;
782 static inline void recycleLockRecord(threadobject *t, monitorLockRecord *r)
784 r->nextFree = t->ee.firstLR;
788 void initObjectLock(java_objectheader *o)
790 o->monitorPtr = dummyLR;
793 static void queueOnLockRecord(monitorLockRecord *lr, java_objectheader *o)
795 atomic_add(&lr->queuers, 1);
796 MEMORY_BARRIER_AFTER_ATOMIC();
798 sem_wait(&lr->queueSem);
799 atomic_add(&lr->queuers, -1);
802 static void freeLockRecord(monitorLockRecord *lr)
809 sem_post(&lr->queueSem);
812 static inline void handleWaiter(monitorLockRecord *mlr, monitorLockRecord *lr)
818 monitorLockRecord *monitorEnter(threadobject *t, java_objectheader *o)
821 monitorLockRecord *lr = o->monitorPtr;
823 monitorLockRecord *nlr, *mlr = allocLockRecordSimple(t);
829 handleWaiter(mlr, lr);
833 if (lr->ownerThread != t)
835 MEMORY_BARRIER_BEFORE_ATOMIC();
836 nlr = (void*) compare_and_swap((long*) &o->monitorPtr, (long) lr, (long) mlr);
839 if (mlr == lr || lr->o != o) {
840 handleWaiter(mlr, lr);
844 queueOnLockRecord(lr, o);
845 handleWaiter(mlr, lr);
849 recycleLockRecord(t, mlr);
850 queueOnLockRecord(nlr, o);
852 if (lr->ownerThread == t) {
856 queueOnLockRecord(lr, o);
861 static void wakeWaiters(monitorLockRecord *lr)
866 sem_post(&lr->queueSem);
871 #define GRAB_LR(lr,t) \
872 if (lr->ownerThread != t) { \
876 #define CHECK_MONITORSTATE(lr,t,mo,a) \
877 if (lr->o != mo || lr->ownerThread != t) { \
878 *exceptionptr = new_exception(string_java_lang_IllegalMonitorStateException); \
882 bool monitorExit(threadobject *t, java_objectheader *o)
884 monitorLockRecord *lr = o->monitorPtr;
886 CHECK_MONITORSTATE(lr, t, o, return false);
887 if (lr->lockCount > 1) {
892 monitorLockRecord *wlr = lr->waiter;
893 if (o->monitorPtr != lr ||
894 (void*) compare_and_swap((long*) &o->monitorPtr, (long) lr, (long) wlr) != lr)
896 monitorLockRecord *nlr = o->monitorPtr;
898 STORE_ORDER_BARRIER();
904 recycleLockRecord(t, lr);
908 static void removeFromWaiters(monitorLockRecord *lr, monitorLockRecord *wlr)
911 if (lr->waiter == wlr) {
912 lr->waiter = wlr->waiter;
919 static inline bool timespec_less(const struct timespec *tv1, const struct timespec *tv2)
921 return tv1->tv_sec < tv2->tv_sec || (tv1->tv_sec == tv2->tv_sec && tv1->tv_nsec < tv2->tv_nsec);
924 static bool timeIsEarlier(const struct timespec *tv)
926 struct timeval tvnow;
927 struct timespec tsnow;
928 gettimeofday(&tvnow, NULL);
929 tsnow.tv_sec = tvnow.tv_sec;
930 tsnow.tv_nsec = tvnow.tv_usec * 1000;
931 return timespec_less(&tsnow, tv);
934 bool waitWithTimeout(threadobject *t, monitorLockRecord *lr, struct timespec *wakeupTime)
938 pthread_mutex_lock(&t->waitLock);
939 t->isSleeping = true;
940 if (wakeupTime->tv_sec || wakeupTime->tv_nsec)
941 while (!t->interrupted && !t->signaled && timeIsEarlier(wakeupTime))
942 pthread_cond_timedwait(&t->waitCond, &t->waitLock, wakeupTime);
944 while (!t->interrupted && !t->signaled)
945 pthread_cond_wait(&t->waitCond, &t->waitLock);
946 wasinterrupted = t->interrupted;
947 t->interrupted = false;
949 t->isSleeping = false;
950 pthread_mutex_unlock(&t->waitLock);
951 return wasinterrupted;
954 static void calcAbsoluteTime(struct timespec *tm, s8 millis, s4 nanos)
956 if (millis || nanos) {
959 gettimeofday(&tv, NULL);
960 tv.tv_sec += millis / 1000;
962 nsec = tv.tv_usec * 1000 + (s4) millis * 1000000 + nanos;
963 tm->tv_sec = tv.tv_sec + nsec / 1000000000;
964 tm->tv_nsec = nsec % 1000000000;
971 void monitorWait(threadobject *t, java_objectheader *o, s8 millis, s4 nanos)
974 struct timespec wakeupTime;
975 monitorLockRecord *mlr, *lr = o->monitorPtr;
977 CHECK_MONITORSTATE(lr, t, o, return);
979 calcAbsoluteTime(&wakeupTime, millis, nanos);
982 wakeWaiters(lr->waiter);
984 STORE_ORDER_BARRIER();
986 wasinterrupted = waitWithTimeout(t, lr, &wakeupTime);
987 mlr = monitorEnter(t, o);
988 removeFromWaiters(mlr, lr);
989 mlr->lockCount = lr->lockCount;
993 recycleLockRecord(t, lr);
996 *exceptionptr = new_exception(string_java_lang_InterruptedException);
999 static void notifyOneOrAll(threadobject *t, java_objectheader *o, bool one)
1001 monitorLockRecord *lr = o->monitorPtr;
1003 CHECK_MONITORSTATE(lr, t, o, return);
1005 threadobject *wthread;
1006 monitorLockRecord *wlr = lr->waiter;
1009 wthread = wlr->ownerThread;
1010 pthread_mutex_lock(&wthread->waitLock);
1011 if (wthread->isSleeping)
1012 pthread_cond_signal(&wthread->waitCond);
1013 wthread->signaled = true;
1014 pthread_mutex_unlock(&wthread->waitLock);
1019 bool threadHoldsLock(threadobject *t, java_objectheader *o)
1021 monitorLockRecord *lr = o->monitorPtr;
1023 return lr->o == o && lr->ownerThread == t;
1026 void interruptThread(java_lang_VMThread *thread)
1028 threadobject *t = (threadobject*) thread;
1030 t->interrupted = true;
1031 pthread_mutex_lock(&t->waitLock);
1033 pthread_cond_signal(&t->waitCond);
1034 pthread_mutex_unlock(&t->waitLock);
1037 bool interruptedThread()
1039 threadobject *t = (threadobject*) THREADOBJECT;
1040 bool intr = t->interrupted;
1041 t->interrupted = false;
1045 bool isInterruptedThread(java_lang_VMThread *thread)
1047 threadobject *t = (threadobject*) thread;
1048 return t->interrupted;
1051 void sleepThread(s8 millis, s4 nanos)
1053 bool wasinterrupted;
1054 threadobject *t = (threadobject*) THREADOBJECT;
1055 monitorLockRecord *lr;
1056 struct timespec wakeupTime;
1057 calcAbsoluteTime(&wakeupTime, millis, nanos);
1059 lr = allocLockRecordSimple(t);
1060 wasinterrupted = waitWithTimeout(t, lr, &wakeupTime);
1061 recycleLockRecord(t, lr);
1064 *exceptionptr = new_exception(string_java_lang_InterruptedException);
1072 void setPriorityThread(thread *t, s4 priority)
1074 nativethread *info = &((threadobject*) t->vmThread)->info;
1075 setPriority(info->tid, priority);
1078 void wait_cond_for_object(java_objectheader *o, s8 time, s4 nanos)
1080 threadobject *t = (threadobject*) THREADOBJECT;
1081 monitorWait(t, o, time, nanos);
1084 void signal_cond_for_object(java_objectheader *o)
1086 threadobject *t = (threadobject*) THREADOBJECT;
1087 notifyOneOrAll(t, o, true);
1090 void broadcast_cond_for_object(java_objectheader *o)
1092 threadobject *t = (threadobject*) THREADOBJECT;
1093 notifyOneOrAll(t, o, false);
1098 * These are local overrides for various environment variables in Emacs.
1099 * Please do not remove this and leave it at the end of the file, where
1100 * Emacs will automagically detect them.
1101 * ---------------------------------------------------------------------
1104 * indent-tabs-mode: t