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

  1. /*
  2.  * @(#)monitor.h    1.34 97/10/07
  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_LOCAL_CACHE_REF        (1 << 0)
  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.     char        mid[1];        /* The sys_mon_t */
  55. } monitor_t, *MID;
  56.  
  57. /* A macro for accessing the sys_mon_t from the monitor_t */
  58. #define sysmon(m)   (*(sys_mon_t *) m->mid)
  59.  
  60. typedef struct reg_mon_t {
  61.     sys_mon_t *mid;
  62.     char *name;
  63.     struct reg_mon_t *next;
  64. } reg_mon_t;
  65.  
  66. /*
  67.  * Macros
  68.  */
  69. #define MID_NULL         ((MID) 0)
  70. #define TIMEOUT_INFINITY    -1
  71.  
  72. /*
  73.  * Support for the monitor registry
  74.  */
  75. extern sys_mon_t *_registry_lock;
  76.  
  77. #define REGISTRY_LOCK_INIT()    monitorRegister(_registry_lock, \
  78.                         "Monitor registry")
  79. #define REGISTRY_LOCK()          sysMonitorEnter(_registry_lock)
  80. #define REGISTRY_LOCKED()    sysMonitorEntered(_registry_lock)
  81. #define REGISTRY_UNLOCK()    sysMonitorExit(_registry_lock)
  82.  
  83. /*
  84.  * External routines.
  85.  */
  86.  
  87. /*
  88.  * Synchronization interface
  89.  */
  90. void monitorInit(monitor_t *mon);
  91. void monitorCacheInit(void);
  92. void monitorEnter(unsigned int);
  93. void monitorExit(unsigned int);
  94. void monitorWait(unsigned int, int);
  95. void monitorNotify(unsigned int);
  96. void monitorNotifyAll(unsigned int);
  97.  
  98. /* Registry of static monitors */
  99. extern reg_mon_t *MonitorRegistry;
  100.  
  101. void monitorRegistryInit(void);
  102. void monitorRegister(sys_mon_t *, char *);
  103. void monitorUnregister(sys_mon_t *);
  104. void registeredEnumerate(void (*)(reg_mon_t *, void *), void *); 
  105. void registeredEnumerate_unlocked(void (*)(reg_mon_t *, void *), void *); 
  106.  
  107.  
  108. /*
  109.  * Random non-local locks without obviously better homes 
  110.  */
  111.  
  112. /* The class loading lock */
  113.  
  114. extern sys_mon_t *_loadclass_lock;
  115. #define LOADCLASS_LOCK_INIT() \
  116.     monitorRegister(_loadclass_lock, "Class loading lock")
  117. #define LOADCLASS_LOCK()     sysMonitorEnter(_loadclass_lock)
  118. #define LOADCLASS_LOCKED()   sysMonitorEntered(_loadclass_lock)
  119. #define LOADCLASS_UNLOCK()   sysMonitorExit(_loadclass_lock)
  120.  
  121. /* The global class table (binclasses) lock */
  122. extern sys_mon_t *_binclass_lock;
  123. #define BINCLASS_LOCK_INIT() monitorRegister(_binclass_lock, "BinClass lock")
  124. #define BINCLASS_LOCK()         sysMonitorEnter(_binclass_lock)
  125. #define BINCLASS_LOCKED()    sysMonitorEntered(_binclass_lock)
  126. #define BINCLASS_UNLOCK()    sysMonitorExit(_binclass_lock)
  127.  
  128. /* Locks on the interned string hash table */
  129.  
  130. extern sys_mon_t *_stringhash_lock;
  131. #define STRINGHASH_INIT()    monitorRegister(_stringhash_lock, \
  132.                          "String intern lock")
  133. #define STRINGHASH_LOCK()    sysMonitorEnter(_stringhash_lock)
  134. #define STRINGHASH_LOCKED()  sysMonitorEntered(_stringhash_lock)
  135. #define STRINGHASH_UNLOCK()  sysMonitorExit(_stringhash_lock)
  136.  
  137. /* Locks on the method info (name and signature) hash table */
  138.  
  139. extern sys_mon_t *_nametypehash_lock;
  140. #define NAMETYPEHASH_INIT()   monitorRegister(_nametypehash_lock, \
  141.                           "Name and type hash table lock")
  142. #define NAMETYPEHASH_LOCK()   sysMonitorEnter(_nametypehash_lock)
  143. #define NAMETYPEHASH_LOCKED() sysMonitorEntered(_nametypehash_lock)
  144. #define NAMETYPEHASH_UNLOCK() sysMonitorExit(_nametypehash_lock)
  145.  
  146. /* JNI global reference locks */
  147.  
  148. extern sys_mon_t *_globalref_lock;
  149. #define GLOBALREF_LOCK_INIT() \
  150.           monitorRegister(_globalref_lock, "JNI global reference lock")
  151. #define GLOBALREF_LOCK()        sysMonitorEnter(_globalref_lock)
  152. #define GLOBALREF_LOCKED()        sysMonitorEntered(_globalref_lock)
  153. #define GLOBALREF_UNLOCK()        sysMonitorExit(_globalref_lock)
  154.  
  155. #endif    /* !_MONITOR_H_ */
  156.