home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / j2sdk / files / linux / j2sdklin.bin / jdk1.3.1 / include-old / monitor.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-06  |  4.7 KB  |  151 lines

  1. /*
  2.  * @(#)monitor.h    1.58 00/02/02
  3.  *
  4.  * Copyright 1994-2000 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the proprietary information of Sun Microsystems, Inc.  
  7.  * Use is subject to license terms.
  8.  * 
  9.  */
  10.  
  11. /*
  12.  * Monitor interface
  13.  */
  14.  
  15. #ifndef _JAVASOFT_MONITOR_H_
  16. #define _JAVASOFT_MONITOR_H_
  17.  
  18. #include "sys_api.h"
  19.  
  20. /*
  21.  * Used by the monitor caching machanism to mark monitors as being
  22.  * in-use.
  23.  */
  24. #define MON_LOCAL_CACHE_REF        (1 << 0)
  25.  
  26. /*
  27.  * The monitor data structure:
  28.  *
  29.  * The use_count field counts the number of createMonitor calls yet
  30.  * unmatched by monitorExit calls; that is, it is a count of outstanding
  31.  * monitor entries of all threads regardless of whether those threads
  32.  * own the monitor or are waiting on it.
  33.  *
  34.  * Note that because the mid[] array will hold the system-specific
  35.  * sys_mon_t, it needs to start on a four-byte boundary lest the fields
  36.  * of the sys_mon_t aren't properly aligned.  Otherwise the flags field
  37.  * would be shorter than a long.
  38.  */
  39. typedef struct monitor_t {
  40.     uintptr_t         key;        /* Monitor hash key */
  41.     struct monitor_t   *next;
  42. } monitor_t, *MID;
  43.  
  44. #define monitorSizeof() (sizeof(monitor_t) + sysMonitorSizeof())
  45.  
  46. /* A macro for accessing the sys_mon_t from the monitor_t */
  47. #define sysmon(m)   ((sys_mon_t *) ((m)+1))
  48.  
  49. typedef struct reg_mon_t {
  50.     sys_mon_t *mid;
  51.     char *name;
  52.     struct reg_mon_t *next;
  53. } reg_mon_t;
  54.  
  55. /*
  56.  * Macros
  57.  */
  58. #define MID_NULL         ((MID) 0)
  59. #define TIMEOUT_INFINITY    (int2ll(-1))
  60.  
  61. /*
  62.  * Support for the monitor registry
  63.  */
  64. extern sys_mon_t *_registry_lock;
  65.  
  66. #define REGISTRY_LOCK_INIT()    monitorRegister(_registry_lock, \
  67.                         "Monitor registry")
  68. #define REGISTRY_LOCK(self)    sysMonitorEnter(self, _registry_lock)
  69. #define REGISTRY_LOCKED(self)    sysMonitorEntered(self, _registry_lock)
  70. #define REGISTRY_UNLOCK(self)    sysMonitorExit(self, _registry_lock)
  71.  
  72. /*
  73.  * External routines.
  74.  */
  75.  
  76. /*
  77.  * Synchronization interface
  78.  */
  79. void monitorInit(monitor_t *mon);
  80. void monitorDestroy(monitor_t *mon);
  81. void monitorCacheInit(void);
  82.  
  83. struct execenv;
  84.  
  85. sys_mon_t * monitorEnter2(struct execenv *, uintptr_t);
  86. int monitorExit2(struct execenv *, uintptr_t);
  87. void monitorWait2(struct execenv *, uintptr_t, int64_t);
  88. void monitorNotify2(struct execenv *, uintptr_t);
  89. void monitorNotifyAll2(struct execenv *, uintptr_t);
  90.  
  91. void monitorRegistryInit(void);
  92. void monitorRegister(sys_mon_t *, char *);
  93. void monitorUnregister(sys_mon_t *);
  94. void registeredEnumerate(void (*)(reg_mon_t *, void *), void *); 
  95.  
  96. char *lookupRegisteredMonitor(sys_thread_t *self, sys_mon_t *mid);
  97.  
  98. /*
  99.  * Random non-local locks without obviously better homes 
  100.  */
  101.  
  102. /* The system class loader lock */ 
  103. extern sys_mon_t *_sysloader_lock;
  104. #define SYSLOADER_LOCK_INIT() \
  105.     monitorRegister(_sysloader_lock, "System class loader lock")
  106. #define SYSLOADER_LOCK(self)     sysMonitorEnter(self, _sysloader_lock)
  107. #define SYSLOADER_LOCKED(self)   sysMonitorEntered(self, _sysloader_lock)
  108. #define SYSLOADER_UNLOCK(self)   sysMonitorExit(self, _sysloader_lock)
  109.  
  110. /* The class linking lock */ 
  111. extern sys_mon_t *_linkclass_lock;
  112. #define LINKCLASS_LOCK_INIT() \
  113.     monitorRegister(_linkclass_lock, "Class linking lock")
  114. #define LINKCLASS_LOCK(self)     sysMonitorEnter(self, _linkclass_lock)
  115. #define LINKCLASS_LOCKED(self)   sysMonitorEntered(self, _linkclass_lock)
  116. #define LINKCLASS_UNLOCK(self)   sysMonitorExit(self, _linkclass_lock)
  117.  
  118. /* The global class table (binclasses) lock */
  119. extern sys_mon_t *_binclass_lock;
  120. #define BINCLASS_LOCK_INIT() monitorRegister(_binclass_lock, "BinClass lock")
  121. #define BINCLASS_LOCK(self)     sysMonitorEnter(self, _binclass_lock)
  122. #define BINCLASS_LOCKED(self)    sysMonitorEntered(self, _binclass_lock)
  123. #define BINCLASS_UNLOCK(self)    sysMonitorExit(self, _binclass_lock)
  124.  
  125. /* JNI global reference locks */
  126.  
  127. extern sys_mon_t *_globalref_lock;
  128. #define GLOBALREF_LOCK_INIT() \
  129.           monitorRegister(_globalref_lock, "JNI global reference lock")
  130. #define GLOBALREF_LOCK(self)        sysMonitorEnter(self, _globalref_lock)
  131. #define GLOBALREF_LOCKED(self)        sysMonitorEntered(self, _globalref_lock)
  132. #define GLOBALREF_UNLOCK(self)        sysMonitorExit(self, _globalref_lock)
  133.  
  134. /*
  135.  * Support for thread queue
  136.  */
  137. extern sys_mon_t *_queue_lock;    /* Protects thread queue, thread count */
  138.  
  139. #define QUEUE_LOCK_INIT() monitorRegister(_queue_lock, "Thread queue lock")
  140. #define QUEUE_LOCK(self)    sysMonitorEnter(self, _queue_lock)
  141. #define QUEUE_LOCKED(self)  sysMonitorEntered(self, _queue_lock)
  142. #define QUEUE_UNLOCK(self)  sysMonitorExit(self, _queue_lock)
  143. #define QUEUE_NOTIFY(self)  sysMonitorNotify(self, _queue_lock)
  144. #define QUEUE_NOTIFYALL(self)  sysMonitorNotifyAll(self, _queue_lock)
  145. #define QUEUE_WAIT(self) sysMonitorWait(self, _queue_lock, \
  146.                     SYS_TIMEOUT_INFINITY)
  147.  
  148. extern sys_mon_t *_code_lock;
  149.  
  150. #endif /* !_JAVASOFT_MONITOR_H_ */
  151.