⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thread-internal.h

📁 kaffe Java 解释器语言,源码,Java的子集系统,开放源代码
💻 H
字号:
/* * thread-impl.h - pthread based ThreadInterface implementation * * Copyright (c) 1998 *      Transvirtual Technologies, Inc.  All rights reserved. * * See the file "license.terms" for information on usage and redistribution * of this file. */#ifndef __thread_internal_h#define __thread_internal_h#include <pthread.h>#include <semaphore.h>#include "gtypes.h"#include "threadData.h"#if !defined(STACKREDZONE)#define STACKREDZONE    8192#endif/* For jthread_get_status */#define THREAD_SUSPENDED	0#define THREAD_RUNNING		1#define THREAD_DEAD		2/* suspend states (these are exclusive) */typedef enum {  SS_PENDING_SUSPEND =  0x01,  /* suspend signal has been sent, but not handled */  SS_SUSPENDED       =  0x02,  /* suspend signal has been handled */  SS_PENDING_RESUME  =  0x04   /* resume signal  has been sent */} suspend_state_t;/* blocking states (might be accumulative) */typedef enum {  BS_THREAD          =  0x01,  /* blocked on tLock (thread system internal) */  BS_MUTEX           =  0x02,  /* blocked on a external mutex lock */  BS_CV              =  0x04,  /* blocked on a external convar wait */  BS_CV_TO           =  0x08   /* blocked on a external convar timeout wait */} block_state_t;/* * 'jthread' is our link between native and Java thread objects. * It also serves as a container for our pthread extensions (namely * enumeration, and inter-thread suspend) */typedef struct _jthread {  threadData		data;  /* these are our links to the native pthread implementation */  pthread_t             tid;  pthread_attr_t        attr;  /* wether this is a daemon thread */  int			daemon;  /* convars and mutexes aren't useful in signal handlers, semaphores are */  sem_t                 sem;  /* the following fields hold our extensions */  int                   active;         /* are we in our user thread function 'func'? */  suspend_state_t       suspendState;   /* are we suspended for a critSection?  */  block_state_t         blockState;     /* are we in a Lwait or Llock (can handle signals)? */  void                  (*func)(void*);  /* this kicks off the user thread func */  void                  *stackMin;  void                  *stackCur;      /* just useful if blocked or suspended */  void                  *stackMax;  struct _jthread	*next;} *jthread_t;extern pthread_key_t   ntKey;/** * Returns the current native thread. * */static inline          jthread_t jthread_current(void)      {  return (jthread_t)pthread_getspecific(ntKey);}/** * Attaches the calling thread to the vm. * * @param daemon wether the thread is to be treated as a daemon thread * */bool jthread_attach_current_thread (bool daemon);void jthread_sleep (jlong timeout);/** * Disable stopping the calling thread. * * Needed to avoid stopping a thread while it holds a lock. */static inlinevoid jthread_disable_stop(void){}/** * Enable stopping the calling thread. * * Needed to avoid stopping a thread while it holds a lock. */static inlinevoid jthread_enable_stop(void){}/**  * Stop a thread. *  * @param tid the thread to stop. */static inlinevoid jthread_stop(jthread_t tid){}/** * Interrupt a thread. *  * @param tid the thread to interrupt */void jthread_interrupt(jthread_t tid);/** * Register a function to be called when the vm exits. *  * @param func the func to execute. */static inlinevoid jthread_atexit(void (* func)(void)){}/** * Dump some information about a thread to stderr. * * @param tid the thread whose info is to be dumped. */static inlinevoid jthread_dumpthreadinfo(jthread_t tid){}/** * Return the java.lang.Thread instance attached to a thread * * @param tid the native thread whose corresponding java thread *            is to be returned. * @return the java.lang.Thread instance. */static inlinethreadData *jthread_get_data(jthread_t tid){        return (&tid->data);}/** * Test whether an address is on the stack of the calling thread. * * @param p the address to check * * @return true if address is on the stack * * Needed for locking and for exception handling. */static inlinebool jthread_on_current_stack(void* p){  jthread_t nt = jthread_current();  if (nt == 0 || (p > nt->stackMin && p < nt->stackMax)) {	return (true);  }  else {	return (false);  }}/** * Check for room on stack. * * @param left number of bytes that are needed * * @return true if @left bytes are free, otherwise false  * * Needed by intrp in order to implement stack overflow checking. */static inlinebool jthread_stackcheck(int left){	int rc;#if defined(STACK_GROWS_UP)        rc = jthread_on_current_stack((char*)&rc + left);#else        rc = jthread_on_current_stack((char*)&rc - left);#endif	return (rc);}/** * Extract the range of the stack that's in use. *  * @param tid the thread whose stack is to be examined * @param from storage for the address of the start address * @param len storage for the size of the used range * * @return true if successful, otherwise false * * Needed by the garbage collector. */static inlinebool jthread_extract_stack(jthread_t tid, void** from, unsigned* len){  if (tid->active == 0) {    return false;  }  assert(tid->suspendState == SS_SUSPENDED);#if defined(STACK_GROWS_UP)  *from = tid->stackMin;  *len = tid->stackCur - tid->stackMin;#else  *from = tid->stackCur;  *len = tid->stackMax - tid->stackCur;#endif  return true;}/** * Returns the upper bound of the stack of the calling thread. * * Needed by support.c in order to implement stack overflow checking.  */static inlinevoid* jthread_stacklimit(void){  jthread_t nt = jthread_current();#if defined(STACK_GROWS_UP)  return (nt->stackMax - STACKREDZONE);#else  return (nt->stackMin + STACKREDZONE);#endif}/* * Get the current stack limit. * Adapted from kaffe/kaffevm/systems/unix-jthreads/jthread.h */static inline void jthread_relaxstack(int yes){	if( yes )	{#if defined(STACK_GROWS_UP)		jthread_current()->stackMax += STACKREDZONE;#else		jthread_current()->stackMin -= STACKREDZONE;#endif	}	else	{#if defined(STACK_GROWS_UP)		jthread_current()->stackMax -= STACKREDZONE;#else		jthread_current()->stackMin += STACKREDZONE;#endif	}}/** * yield. * */static inlinevoid jthread_yield (void){  sched_yield();}/** * Acquire a spin lock. * */static inlinevoid jthread_spinon(int dummy){}/** * Release a spin lock. * */static inlinevoid jthread_spinoff(int dummy){}struct _exceptionFrame;typedef void (*exchandler_t)(struct _exceptionFrame*);/** * Initialize handlers for null pointer accesses and div by zero         * */             void jthread_initexceptions(exchandler_t _nullHandler,			    exchandler_t _floatingHandler);/** * Initialize the thread subsystem. * */void jthread_init(int preemptive,                	/* preemptive scheduling */		  int maxpr,                     	/* maximum priority */		  int minpr,                     	/* minimum priority */		  void *(*_allocator)(size_t),   	/* memory allocator */		  void (*_deallocator)(void*),    	/* memory deallocator */		  void *(*_reallocator)(void*,size_t),  /* memory reallocator */		  void (*_destructor1)(void*),		/* called when a thread exits */		  void (*_onstop)(void),		/* called when a thread is stopped */		  void (*_ondeadlock)(void));		/* called when we detect deadlock *//** * Bind the main thread of the vm to a java.lang.Thread instance. * */jthread_t jthread_createfirst(size_t, unsigned char, void*);/** * Create a new native thread. * */jthread_t jthread_create (unsigned char pri, void* func, int daemon,			  void* jlThread, size_t threadStackSize );/** * Set the priority of a native thread. * */void jthread_setpriority (jthread_t thread, jint prio);/** * Called by thread.c when a thread is finished.  *  */void jthread_exit ( void );/** * Destroys the a native thread. * * @param thread the thread to destroy. * * Called when finalizing a java.lang.Thread instance. */void jthread_destroy (jthread_t thread);/** * Suspends all threads but the calling one.  * * Currently needed by the garbage collector. */void jthread_suspendall (void);/** * Unsuspends all threads but the calling one.  * * Currently needed by the garbage collector. */void jthread_unsuspendall (void);/** * Call a function once for each active thread. * */void jthread_walkLiveThreads (void(*)(jthread_t));/** * Return thread status */int jthread_get_status (jthread_t thread);/** * Specify the blocking state of a file descriptor */void jthread_set_blocking (int fd, int blocking);static inline voidjthread_suspend(jthread_t jt, void *suspender){	/* TODO */}static inline voidjthread_resume(jthread_t jt, void *suspender){	/* TODO */}static inline jthread_tjthread_from_data(threadData *td, void *suspender){	/* TODO */	return NULL;}static inlinejlong jthread_get_usage(jthread_t jt){	/* TODO */	return 0;}static inlineint jthread_is_interrupted(jthread_t jt){	/* TODO */	return 0;}static inlineint jthread_on_mutex(jthread_t jt){	/* TODO */	return 0;}static inlineint jthread_on_condvar(jthread_t jt){	/* TODO */	return 0;}#endif /* __thread_impl_h */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -