void tested_thread_wait_for_stop_request(tested_thread_sturct_t * tts) { IDATA status; do { hysem_set(tts->running, 1); status = hysem_wait_timed(tts->stop_request, SLEEP_TIME, 0); } while (status == TM_ERROR_TIMEOUT); }
/* * Test jthread_holds_lock(...) */ void JNICALL run_for_test_jthread_holds_lock(jvmtiEnv * jvmti_env, JNIEnv * jni_env, void *args){ tested_thread_sturct_t * tts = (tested_thread_sturct_t *) args; jobject monitor = tts->monitor; IDATA status; tts->phase = TT_PHASE_WAITING_ON_MONITOR; tested_thread_started(tts); status = jthread_monitor_enter(monitor); // Begin critical section tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_IN_CRITICAL_SECTON : TT_PHASE_ERROR); hysem_set(mon_enter, 1); tested_thread_wait_for_stop_request(tts); status = jthread_monitor_exit(monitor); // End critical section tts->phase = (status == TM_ERROR_NONE ? TT_PHASE_DEAD : TT_PHASE_ERROR); tested_thread_ended(tts); }
/** * Initializes a new thread structure. */ IDATA VMCALL hythread_struct_init(hythread_t new_thread) { char jstatus; IDATA status; assert(new_thread); jstatus = new_thread->java_status; if (!new_thread->os_handle) { // new thread, create thread primitives memset(new_thread, 0, sizeof(HyThread)); status = hysem_create(&new_thread->resume_event, 0, 1); assert(status == TM_ERROR_NONE); status = port_mutex_create(&new_thread->mutex, APR_THREAD_MUTEX_NESTED); assert(status == TM_ERROR_NONE); status = hythread_monitor_init(&new_thread->monitor, 0); assert(status == TM_ERROR_NONE); } else { // old thread, reset structure int result; hysem_t resume; osmutex_t mutex; hythread_monitor_t monitor; // release thread OS handle result = port_thread_free_handle(new_thread->os_handle); assert(0 == result); resume = new_thread->resume_event; mutex = new_thread->mutex; monitor = new_thread->monitor; // zero new thread memset(new_thread, 0, sizeof(HyThread)); new_thread->resume_event = resume; new_thread->mutex = mutex; new_thread->monitor = monitor; } assert(new_thread->os_handle == 0); new_thread->java_status = jstatus; new_thread->priority = HYTHREAD_PRIORITY_NORMAL; #ifdef ORDER new_thread->alloc_count = 0; new_thread->thread_create_count = 0; new_thread->p_tid = 0; new_thread->p_count = 0; // new_thread->isInVMRegistry = 0; #endif port_mutex_lock(&new_thread->mutex); new_thread->state = TM_THREAD_STATE_NEW; port_mutex_unlock(&new_thread->mutex); status = hysem_set(new_thread->resume_event, 0); assert(status == TM_ERROR_NONE); return TM_ERROR_NONE; }
IDATA tested_thread_wait_for_stop_request_timed(tested_thread_sturct_t * tts, I_64 sleep_time) { hysem_set(tts->running, 1); return hysem_wait_timed(tts->stop_request, sleep_time, 0); }
void tested_thread_send_stop_request(tested_thread_sturct_t * tts) { hysem_set(tts->stop_request, 1); }
void tested_thread_ended(tested_thread_sturct_t * tts) { hysem_set(tts->ended, 1); }