home *** CD-ROM | disk | FTP | other *** search
/ SGI Cosmo Software 1997 May / SGI Cosmo Software 1997 May.iso / dist / dist6.3 / java_dev.idb / usr / java / include / monitor.h.z / monitor.h
Encoding:
C/C++ Source or Header  |  1997-05-24  |  5.1 KB  |  166 lines

  1. /*
  2.  * @(#)monitor.h    1.33 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. /*
  24.  * Monitor interface
  25.  */
  26.  
  27. #ifndef    _MONITOR_H_
  28. #define    _MONITOR_H_
  29.  
  30. #include "sys_api.h"
  31.  
  32. /*
  33.  * Used by the monitor caching machanism to mark monitors as being
  34.  * in-use.
  35.  */
  36. #define MON_IN_USE            0x1
  37.  
  38. /*
  39.  * The monitor data structure:
  40.  *
  41.  * The use_count field counts the number of createMonitor calls yet
  42.  * unmatched by monitorExit calls; that is, it is a count of outstanding
  43.  * monitor entries of all threads regardless of whether those threads
  44.  * own the monitor or are waiting on it.
  45.  *
  46.  * Note that because the mid[] array will hold the system-specific
  47.  * sys_mon_t, it needs to start on a four-byte boundary lest the fields
  48.  * of the sys_mon_t aren't properly aligned.  Otherwise the flags field
  49.  * would be shorter than a long.
  50.  */
  51. typedef struct monitor_t {
  52.     unsigned int    key;        /* Monitor hash key */
  53.     struct monitor_t   *next;
  54.     unsigned long    flags;        /* Flags used by the cache */
  55.     long        use_count;
  56.     char        mid[1];        /* The sys_mon_t */
  57. } monitor_t, *MID;
  58.  
  59. /* A macro for accessing the sys_mon_t from the monitor_t */
  60. #define sysmon(m)   (*(sys_mon_t *) m->mid)
  61.  
  62. typedef struct reg_mon_t {
  63.     sys_mon_t *mid;
  64.     char *name;
  65.     struct reg_mon_t *next;
  66. } reg_mon_t;
  67.  
  68. /*
  69.  * Macros
  70.  */
  71. #define MID_NULL         ((MID) 0)
  72. #define TIMEOUT_INFINITY    -1
  73.  
  74. /*
  75.  * Support for the monitor registry
  76.  */
  77. extern sys_mon_t *_registry_lock;
  78.  
  79. #define REGISTRY_LOCK_INIT()    monitorRegister(_registry_lock, \
  80.                         "Monitor registry")
  81. #define REGISTRY_LOCK()          sysMonitorEnter(_registry_lock)
  82. #define REGISTRY_LOCKED()    sysMonitorEntered(_registry_lock)
  83. #define REGISTRY_UNLOCK()    sysMonitorExit(_registry_lock)
  84.  
  85. /*
  86.  * External routines.
  87.  */
  88.  
  89. /*
  90.  * Synchronization interface
  91.  */
  92. void monitorInit(monitor_t *mon);
  93. void monitorCacheInit(void);
  94. void monitorEnter(unsigned int);
  95. void monitorExit(unsigned int);
  96. void monitorExit_native(unsigned int);
  97. void monitorWait(unsigned int, int);
  98. void monitorNotify(unsigned int);
  99. void monitorNotifyAll(unsigned int);
  100.  
  101. /* Registry of static monitors */
  102. extern reg_mon_t *MonitorRegistry;
  103. void awt_lock_enter(void);
  104. void awt_lock_exit(void);
  105. void awt_lock_wait(int millis);
  106. void awt_lock_notify(void);
  107. void awt_lock_notify_all(void);
  108. sys_thread_t *awt_lock_owner(void);
  109.  
  110.  
  111. void monitorRegistryInit(void);
  112. void monitorRegister(sys_mon_t *, char *);
  113. void monitorUnregister(sys_mon_t *);
  114. void registeredEnumerate(void (*)(reg_mon_t *, void *), void *); 
  115. void registeredEnumerate_unlocked(void (*)(reg_mon_t *, void *), void *); 
  116.  
  117.  
  118. /*
  119.  * Random non-local locks without obviously better homes 
  120.  */
  121.  
  122. /* The class loading lock */
  123.  
  124. extern sys_mon_t *_loadclass_lock;
  125. #define LOADCLASS_LOCK_INIT() \
  126.     monitorRegister(_loadclass_lock, "Class loading lock")
  127. #define LOADCLASS_LOCK()     sysMonitorEnter(_loadclass_lock)
  128. #define LOADCLASS_LOCKED()   sysMonitorEntered(_loadclass_lock)
  129. #define LOADCLASS_UNLOCK()   sysMonitorExit(_loadclass_lock)
  130.  
  131. /* The global class table (binclasses) lock */
  132. extern sys_mon_t *_binclass_lock;
  133. #define BINCLASS_LOCK_INIT() monitorRegister(_binclass_lock, "BinClass lock")
  134. #define BINCLASS_LOCK()         sysMonitorEnter(_binclass_lock)
  135. #define BINCLASS_LOCKED()    sysMonitorEntered(_binclass_lock)
  136. #define BINCLASS_UNLOCK()    sysMonitorExit(_binclass_lock)
  137.  
  138. /* Locks on the interned string hash table */
  139.  
  140. extern sys_mon_t *_stringhash_lock;
  141. #define STRINGHASH_INIT()    monitorRegister(_stringhash_lock, \
  142.                          "String intern lock")
  143. #define STRINGHASH_LOCK()    sysMonitorEnter(_stringhash_lock)
  144. #define STRINGHASH_LOCKED()  sysMonitorEntered(_stringhash_lock)
  145. #define STRINGHASH_UNLOCK()  sysMonitorExit(_stringhash_lock)
  146.  
  147. /* Locks on the method info (name and signature) hash table */
  148.  
  149. extern sys_mon_t *_nametypehash_lock;
  150. #define NAMETYPEHASH_INIT()   monitorRegister(_nametypehash_lock, \
  151.                           "Name and type hash table lock")
  152. #define NAMETYPEHASH_LOCK()   sysMonitorEnter(_nametypehash_lock)
  153. #define NAMETYPEHASH_LOCKED() sysMonitorEntered(_nametypehash_lock)
  154. #define NAMETYPEHASH_UNLOCK() sysMonitorExit(_nametypehash_lock)
  155.  
  156. /* JNI global reference locks */
  157.  
  158. extern sys_mon_t *_globalref_lock;
  159. #define GLOBALREF_LOCK_INIT() \
  160.           monitorRegister(_globalref_lock, "JNI global reference lock")
  161. #define GLOBALREF_LOCK()        sysMonitorEnter(_globalref_lock)
  162. #define GLOBALREF_LOCKED()        sysMonitorEntered(_globalref_lock)
  163. #define GLOBALREF_UNLOCK()        sysMonitorExit(_globalref_lock)
  164.  
  165. #endif    /* !_MONITOR_H_ */
  166.