/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This source file is part of SableVM. * * * * See the file "LICENSE" for the copyright information and for * * the terms and conditions for copying, distribution and * * modification of this source file. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #ifndef SVM_THREAD_H #define SVM_THREAD_H #if 0 #define _svmm_debug_synchronization(env,msg,par1,par2,par3,par4) \ _svmf_printf(env, stderr, "SYNC(%d): " msg "\n", \ env->thread.id, par1, par2, par3, par4); fflush(NULL) #else #define _svmm_debug_synchronization(env,msg,par1,par2,par3,par4) {} #endif #ifdef STATISTICS svm_static void _svmf_register_event (_svmt_JNIEnv *, const char *, const char *, const char *, size_t); #define _svmm_stat_inc(name,file,func,line) env->vm->total_##name##_count++, \ _svmf_register_event(env,#name "",file,func,line); #else /* STATISTICS */ #define _svmm_stat_inc(name,file,func,line,desc) ({ 0; }) /* _svmf_printf(env, stderr, "MUTEX(%d): %s, %s, %s, %i, %s\n", \ env->thread.id, #name "", file, func, line, desc) */ #endif /* STATISTICS */ #define _svmm_mutex_init(mutex) \ pthread_mutex_init (&mutex, NULL) #define _svmm_mutex_destroy(mutex) \ pthread_mutex_destroy (&mutex) #define _svmm_mutex_lock(mutex) \ { \ pthread_mutex_t *_svmx_pmutex = &mutex; \ _svmm_stat_inc(mutex_lock,__FILE__,__FUNCTION__,__LINE__,#mutex); \ pthread_mutex_lock (_svmx_pmutex) #define _svmm_mutex_unlock() \ _svmm_stat_inc(mutex_unlock,__FILE__,__FUNCTION__,__LINE__,""); \ pthread_mutex_unlock (_svmx_pmutex); \ } #define _svmm_mutex_lock_noenv(mutex) \ { \ pthread_mutex_t *_svmx_pmutex = &mutex; \ pthread_mutex_lock (_svmx_pmutex) #define _svmm_mutex_unlock_noenv() \ pthread_mutex_unlock (_svmx_pmutex); \ } #define _svmm_mutex_lock_raw(mutex) \ ({_svmm_stat_inc(mutex_lock,__FILE__,__FUNCTION__,__LINE__,#mutex); \ pthread_mutex_lock (&mutex); }) #define _svmm_mutex_trylock(mutex) \ pthread_mutex_trylock(&mutex) #define _svmm_mutex_unlock_raw(mutex) \ ({_svmm_stat_inc(mutex_unlock,__FILE__,__FUNCTION__,__LINE__,#mutex); \ pthread_mutex_unlock(&mutex); }) #define _svmm_cond_init(cond) \ pthread_cond_init (&cond, NULL) #define _svmm_cond_destroy(cond) \ pthread_cond_destroy (&cond) #define _svmm_cond_wait(cond, mutex) \ _svmm_stat_inc(cond_wait,__FILE__,__FUNCTION__,__LINE__,#mutex ", " #cond); \ pthread_cond_wait (&cond, &mutex) #define _svmm_cond_timedwait(cond, mutex, abstime) \ ({_svmm_stat_inc(cond_timedwait,__FILE__,__FUNCTION__,__LINE__,#mutex ", " #cond); \ pthread_cond_timedwait (&cond, &mutex, &abstime); }) #define _svmm_cond_signal(cond) \ ({ _svmm_stat_inc(cond_signal,__FILE__,__FUNCTION__,__LINE__,#cond); \ pthread_cond_signal (&cond); }) #define _svmm_cond_broadcast(cond) \ _svmm_stat_inc(cond_broadcast,__FILE__,__FUNCTION__,__LINE__,#cond), \ pthread_cond_broadcast (&cond) #define _svmm_cond_broadcast_ptr(cond) \ _svmm_stat_inc(cond_broadcast,__FILE__,__FUNCTION__,__LINE__,#cond), \ pthread_cond_broadcast (cond) #define _svmm_kill(thread, signal) \ pthread_kill (thread, signal) static _svmt_JNIEnv *_svmf_get_current_env (void); #endif /* not SVM_THREAD_H */ #ifdef COMMENT jint _svmf_thread_init (void); jint _svmf_create_initial_thread (_svmt_JavaVM *vm, _svmt_JNIEnv **penv); void _svmf_cleanup_initial_thread (_svmt_JNIEnv **penv); void _svmf_set_current_env (_svmt_JNIEnv *env); jint _svmf_stack_init (_svmt_JNIEnv *env); jint _svmf_ensure_stack_capacity (_svmt_JNIEnv *env, size_t frame_size); #endif /* COMMENT */