home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / threads.h < prev    next >
C/C++ Source or Header  |  1997-11-24  |  5KB  |  151 lines

  1. /*
  2.  * @(#)threads.h    1.34 96/11/23
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. #ifndef _THREADS_H_
  24. #define _THREADS_H_
  25.  
  26. #include "oobj.h"
  27. #include "interpreter.h"
  28. #include "timeval.h"
  29. #include "monitor.h"
  30. #include "bool.h"
  31. #include "sys_api.h"
  32.  
  33. #include "java_lang_Thread.h"
  34. #include "java_lang_ThreadGroup.h"
  35.  
  36. #define MinimumPriority        java_lang_Thread_MIN_PRIORITY
  37. #define MaximumPriority        java_lang_Thread_MAX_PRIORITY
  38. #define NormalPriority        java_lang_Thread_NORM_PRIORITY
  39.  
  40. /*
  41.  * Support for thread queue
  42.  */
  43.  
  44. extern sys_mon_t *_queue_lock;
  45.  
  46. #define QUEUE_LOCK_INIT() monitorRegister(_queue_lock, "Thread queue lock")
  47. #define QUEUE_LOCK()      sysMonitorEnter(_queue_lock)
  48. #define QUEUE_LOCKED()      sysMonitorEntered(_queue_lock)
  49. #define QUEUE_UNLOCK()      sysMonitorExit(_queue_lock)
  50. #define QUEUE_NOTIFY()      sysMonitorNotify(_queue_lock)
  51. #define QUEUE_WAIT()      sysMonitorWait(_queue_lock, \
  52.                      SYS_TIMEOUT_INFINITY, FALSE)
  53.  
  54. /*
  55.  * Thread-related data structures
  56.  */
  57.  
  58. typedef struct Hjava_lang_Thread HThread;
  59. typedef struct Hjava_lang_ThreadGroup HThreadGroup;
  60. typedef struct Hjava_lang_Thread *TID;
  61.  
  62. typedef sys_thread_t ThreadPrivate;
  63.  
  64. /* Access to thread data structures */
  65. #define THREAD(tid)    ((struct Classjava_lang_Thread *) unhand(tid))
  66. #define SYSTHREAD(tid)    ((sys_thread_t *)THREAD(tid)->PrivateInfo)
  67.  
  68. #define THR_SYSTEM 0        /* System thread */
  69. #define THR_USER   1        /* User thread */
  70.  
  71. extern int ActiveThreadCount;        /* All threads */
  72. extern int UserThreadCount;        /* User threads */
  73.  
  74. /* The default Java stack size is legitimately platform-independent */
  75. #define JAVASTACKSIZE (400 * 1024)     /* Default size of a thread java stack */
  76.  
  77. extern long ProcStackSize;        /* Actual size of thread C stack */
  78. extern long JavaStackSize;        /* Actual maximum size of java stack */
  79.  
  80. extern stackp_t mainstktop;        /* Base of primordial thread stack */
  81.  
  82. /*
  83.  * External interface to threads support
  84.  */
  85.  
  86. void threadBootstrap(TID tid, stackp_t sb);
  87. int  threadCreate(TID, unsigned int, size_t, void *(*)());
  88. TID  threadSelf(void);
  89. void threadSleep(int);
  90. int  threadEnumerate(TID*, int);
  91.  
  92. void threadDumpInfo(TID, bool_t);        /* Debugging help in debug.c */
  93.  
  94. int threadPostException(TID tid, void *exc);
  95. void threadTryVMSuspend(void);
  96.  
  97. /*
  98.  * There may be certain initialization that can't be done except by the
  99.  * thread on itself, e.g. setting thread-local data in Solaris threads.
  100.  * This function is called from ThreadRT0() when the thread starts up
  101.  * to take care of such things.
  102.  */
  103. #define threadInit(tid, sb)        sysThreadInit(SYSTHREAD(tid), sb)
  104.  
  105. /*
  106.  * Exit the current thread.  This function is not expected to return.
  107.  *
  108.  * Note that we currently never stop a thread dead in its tracks, but
  109.  * rather throw an exception against it that causes it to unwind its
  110.  * stack, exit monitors, etc. and exit in a single place (ThreadRT0).
  111.  * If a thread is caused to exit precipitously by calling threadExit()
  112.  * at random places it will corrupt the runtime and at minimum will
  113.  * fail to clean the thread out of any monitors it currently holds.
  114.  */
  115. #define threadExit()            sysThreadExit()
  116.  
  117. /*
  118.  * Note that we do not check that priorities are within Java's limits down here.
  119.  * In fact, we make use of that for things like the idle and clock threads.
  120.  * This may change once we work out a portable priority model.
  121.  */
  122. #define threadSetPriority(tid, pri)    sysThreadSetPriority(SYSTHREAD(tid), pri)
  123. #define threadGetPriority(tid, prip)    sysThreadGetPriority(SYSTHREAD(tid), prip)
  124.  
  125. #define threadYield()            sysThreadYield()
  126. #define threadResume(tid)        sysThreadResume(SYSTHREAD(tid))
  127. #define threadSuspend(tid)        sysThreadSuspend(SYSTHREAD(tid))
  128.  
  129. /*
  130.  * Return information about this thread's stack.  This is used by
  131.  * Garbage Collection code that needs to inspect the stack.
  132.  *
  133.  * It is permissable to return a null stack_base for those threads
  134.  * that don't have a known stack (e.g. not allocated by the threads
  135.  * package).  It is also permissable to return a somewhat bogus
  136.  * stack_pointer for the current thread.
  137.  */
  138. #define threadStackBase(tid)        sysThreadStackBase(SYSTHREAD(tid))
  139. #define threadStackPointer(tid)        sysThreadStackPointer(SYSTHREAD(tid))
  140.  
  141. #define threadCheckStack()        sysThreadCheckStack()
  142.  
  143. /*
  144.  * Interface to thread interrupt support
  145.  */
  146. #define threadInterrupt(tid)        sysThreadInterrupt(SYSTHREAD(tid))
  147. #define threadIsInterrupted(tid, ClearInterrupted) \
  148.     sysThreadIsInterrupted(SYSTHREAD(tid), ClearInterrupted)
  149.  
  150. #endif /* !_THREADS_H_ */
  151.