home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / solaris2 / jdk / include / threads.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-30  |  4.4 KB  |  133 lines

  1. /*
  2.  * @(#)threads.h    1.27 95/09/01  
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. #ifndef _THREADS_H_
  21. #define _THREADS_H_
  22.  
  23. #include <oobj.h>
  24. #include <interpreter.h>
  25. #include <timeval.h>
  26. /* #include <threads_md.h> */
  27. #include <monitor.h>
  28. #include <bool.h>
  29. #include <sys_api.h>
  30.  
  31. #include <java_lang_Thread.h>
  32. #include <java_lang_ThreadGroup.h>
  33.  
  34. #define MinimumPriority        java_lang_Thread_MIN_PRIORITY
  35. #define MaximumPriority        java_lang_Thread_MAX_PRIORITY
  36. #define NormalPriority        java_lang_Thread_NORM_PRIORITY
  37.  
  38. /*
  39.  * Support for thread queue
  40.  */
  41.  
  42. extern sys_mon_t *_queue_lock;
  43.  
  44. #define QUEUE_LOCK_INIT() monitorRegister(_queue_lock, "Thread queue lock")
  45. #define QUEUE_LOCK()      sysMonitorEnter(_queue_lock)
  46. #define QUEUE_LOCKED()      sysMonitorEntered(_queue_lock)
  47. #define QUEUE_UNLOCK()      sysMonitorExit(_queue_lock)
  48. #define QUEUE_NOTIFY()      sysMonitorNotify(_queue_lock)
  49. #define QUEUE_WAIT()      sysMonitorWait(_queue_lock, SYS_TIMEOUT_INFINITY)
  50.  
  51. /*
  52.  * Thread-related data structures
  53.  */
  54.  
  55. typedef struct Hjava_lang_Thread HThread;
  56. typedef struct Hjava_lang_ThreadGroup HThreadGroup;
  57. typedef struct Hjava_lang_Thread *TID;
  58.  
  59. typedef sys_thread_t ThreadPrivate;
  60.  
  61. /* Access to thread data structures */
  62. #define THREAD(tid)    ((struct Classjava_lang_Thread *) unhand(tid))
  63. #define SYSTHREAD(tid)    ((sys_thread_t *)THREAD(tid)->PrivateInfo)
  64.  
  65. #define THR_SYSTEM 0        /* System thread */
  66. #define THR_USER   1        /* User thread */
  67.  
  68. extern int ActiveThreadCount;        /* All threads */
  69. extern int UserThreadCount;        /* User threads */
  70.  
  71. /* The default Java stack size is legitimately platform-independent */
  72. #define JAVASTACKSIZE (400 * 1024)     /* Default size of a thread java stack */
  73.  
  74. extern long ProcStackSize;        /* Actual size of thread C stack */
  75. extern long JavaStackSize;        /* Actual maximum size of java stack */
  76.  
  77. extern stackp_t mainstktop;        /* Base of primordial thread stack */
  78.  
  79. /*
  80.  * External interface to threads support
  81.  */
  82.  
  83. void threadBootstrap(TID tid, stackp_t sb);
  84. int  threadCreate(TID, unsigned int, size_t, void *(*)());
  85. TID  threadSelf(void);
  86. void threadSleep(int);
  87. int  threadEnumerate(TID*, int);
  88.  
  89. void threadDumpInfo(TID, bool_t);        /* Debugging help in debug.c */
  90.  
  91. int threadPostException(TID tid, void *exc);
  92.  
  93. /*
  94.  * There may be certain initialization that can't be done except by the
  95.  * thread on itself, e.g. setting thread-local data in Solaris threads.
  96.  * This function is called from ThreadRT0() when the thread starts up
  97.  * to take care of such things.
  98.  */
  99. #define threadInit(tid, sb)        sysThreadInit(SYSTHREAD(tid), sb)
  100.  
  101. /*
  102.  * Exit the current thread.  This function is not expected to return.
  103.  */
  104. #define threadExit()            sysThreadExit()
  105.  
  106. /*
  107.  * Note that we do not check that priorities are within Java's limits down here.
  108.  * In fact, we make use of that for things like the idle and clock threads.
  109.  * This may change once we work out a portable priority model.
  110.  */
  111. #define threadSetPriority(tid, pri)    sysThreadSetPriority(SYSTHREAD(tid), pri)
  112. #define threadGetPriority(tid, prip)    sysThreadGetPriority(SYSTHREAD(tid), prip)
  113.  
  114. #define threadYield()            sysThreadYield()
  115. #define threadResume(tid)        sysThreadResume(SYSTHREAD(tid))
  116. #define threadSuspend(tid)        sysThreadSuspend(SYSTHREAD(tid))
  117.  
  118. /*
  119.  * Return information about this thread's stack.  This is used by
  120.  * Garbage Collection code that needs to inspect the stack.
  121.  *
  122.  * It is permissable to return a null stack_base for those threads
  123.  * that don't have a known stack (e.g. not allocated by the threads
  124.  * package).  It is also permissable to return a somewhat bogus
  125.  * stack_pointer for the current thread.
  126.  */
  127. #define threadStackBase(tid)        sysThreadStackBase(SYSTHREAD(tid))
  128. #define threadStackPointer(tid)        sysThreadStackPointer(SYSTHREAD(tid))
  129.  
  130. #define threadCheckStack()        sysThreadCheckStack()
  131.  
  132. #endif /* !_THREADS_H_ */
  133.