home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1998 February / VPR9802A.ISO / APP_DEMO / VC / MAIN.BIN / monitor.h < prev    next >
C/C++ Source or Header  |  1997-10-27  |  5KB  |  158 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 monitorWait(unsigned int, int);
  97. void monitorNotify(unsigned int);
  98. void monitorNotifyAll(unsigned int);
  99.  
  100. /* Registry of static monitors */
  101. extern reg_mon_t *MonitorRegistry;
  102.  
  103. void monitorRegistryInit(void);
  104. void monitorRegister(sys_mon_t *, char *);
  105. void monitorUnregister(sys_mon_t *);
  106. void registeredEnumerate(void (*)(reg_mon_t *, void *), void *); 
  107. void registeredEnumerate_unlocked(void (*)(reg_mon_t *, void *), void *); 
  108.  
  109.  
  110. /*
  111.  * Random non-local locks without obviously better homes 
  112.  */
  113.  
  114. /* The class loading lock */
  115.  
  116. extern sys_mon_t *_loadclass_lock;
  117. #define LOADCLASS_LOCK_INIT() \
  118.     monitorRegister(_loadclass_lock, "Class loading lock")
  119. #define LOADCLASS_LOCK()     sysMonitorEnter(_loadclass_lock)
  120. #define LOADCLASS_LOCKED()   sysMonitorEntered(_loadclass_lock)
  121. #define LOADCLASS_UNLOCK()   sysMonitorExit(_loadclass_lock)
  122.  
  123. /* The global class table (binclasses) lock */
  124. extern sys_mon_t *_binclass_lock;
  125. #define BINCLASS_LOCK_INIT() monitorRegister(_binclass_lock, "BinClass lock")
  126. #define BINCLASS_LOCK()         sysMonitorEnter(_binclass_lock)
  127. #define BINCLASS_LOCKED()    sysMonitorEntered(_binclass_lock)
  128. #define BINCLASS_UNLOCK()    sysMonitorExit(_binclass_lock)
  129.  
  130. /* Locks on the interned string hash table */
  131.  
  132. extern sys_mon_t *_stringhash_lock;
  133. #define STRINGHASH_INIT()    monitorRegister(_stringhash_lock, \
  134.                          "String intern lock")
  135. #define STRINGHASH_LOCK()    sysMonitorEnter(_stringhash_lock)
  136. #define STRINGHASH_LOCKED()  sysMonitorEntered(_stringhash_lock)
  137. #define STRINGHASH_UNLOCK()  sysMonitorExit(_stringhash_lock)
  138.  
  139. /* Locks on the method info (name and signature) hash table */
  140.  
  141. extern sys_mon_t *_nametypehash_lock;
  142. #define NAMETYPEHASH_INIT()   monitorRegister(_nametypehash_lock, \
  143.                           "Name and type hash table lock")
  144. #define NAMETYPEHASH_LOCK()   sysMonitorEnter(_nametypehash_lock)
  145. #define NAMETYPEHASH_LOCKED() sysMonitorEntered(_nametypehash_lock)
  146. #define NAMETYPEHASH_UNLOCK() sysMonitorExit(_nametypehash_lock)
  147.  
  148. /* JNI global reference locks */
  149.  
  150. extern sys_mon_t *_globalref_lock;
  151. #define GLOBALREF_LOCK_INIT() \
  152.           monitorRegister(_globalref_lock, "JNI global reference lock")
  153. #define GLOBALREF_LOCK()        sysMonitorEnter(_globalref_lock)
  154. #define GLOBALREF_LOCKED()        sysMonitorEntered(_globalref_lock)
  155. #define GLOBALREF_UNLOCK()        sysMonitorExit(_globalref_lock)
  156.  
  157. #endif    /* !_MONITOR_H_ */
  158.