home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Main.bin / monitor.h < prev    next >
C/C++ Source or Header  |  1998-09-15  |  5KB  |  148 lines

  1. /*
  2.  * @(#)monitor.h    1.35 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. /*
  16.  * Monitor interface
  17.  */
  18.  
  19. #ifndef    _MONITOR_H_
  20. #define    _MONITOR_H_
  21.  
  22. #include "sys_api.h"
  23.  
  24. /*
  25.  * Used by the monitor caching machanism to mark monitors as being
  26.  * in-use.
  27.  */
  28. #define MON_LOCAL_CACHE_REF        (1 << 0)
  29.  
  30. /*
  31.  * The monitor data structure:
  32.  *
  33.  * The use_count field counts the number of createMonitor calls yet
  34.  * unmatched by monitorExit calls; that is, it is a count of outstanding
  35.  * monitor entries of all threads regardless of whether those threads
  36.  * own the monitor or are waiting on it.
  37.  *
  38.  * Note that because the mid[] array will hold the system-specific
  39.  * sys_mon_t, it needs to start on a four-byte boundary lest the fields
  40.  * of the sys_mon_t aren't properly aligned.  Otherwise the flags field
  41.  * would be shorter than a long.
  42.  */
  43. typedef struct monitor_t {
  44.     unsigned int    key;        /* Monitor hash key */
  45.     struct monitor_t   *next;
  46.     char        mid[1];        /* The sys_mon_t */
  47. } monitor_t, *MID;
  48.  
  49. /* A macro for accessing the sys_mon_t from the monitor_t */
  50. #define sysmon(m)   (*(sys_mon_t *) m->mid)
  51.  
  52. typedef struct reg_mon_t {
  53.     sys_mon_t *mid;
  54.     char *name;
  55.     struct reg_mon_t *next;
  56. } reg_mon_t;
  57.  
  58. /*
  59.  * Macros
  60.  */
  61. #define MID_NULL         ((MID) 0)
  62. #define TIMEOUT_INFINITY    -1
  63.  
  64. /*
  65.  * Support for the monitor registry
  66.  */
  67. extern sys_mon_t *_registry_lock;
  68.  
  69. #define REGISTRY_LOCK_INIT()    monitorRegister(_registry_lock, \
  70.                         "Monitor registry")
  71. #define REGISTRY_LOCK()          sysMonitorEnter(_registry_lock)
  72. #define REGISTRY_LOCKED()    sysMonitorEntered(_registry_lock)
  73. #define REGISTRY_UNLOCK()    sysMonitorExit(_registry_lock)
  74.  
  75. /*
  76.  * External routines.
  77.  */
  78.  
  79. /*
  80.  * Synchronization interface
  81.  */
  82. void monitorInit(monitor_t *mon);
  83. void monitorCacheInit(void);
  84. void monitorEnter(unsigned int);
  85. void monitorExit(unsigned int);
  86. void monitorWait(unsigned int, int);
  87. void monitorNotify(unsigned int);
  88. void monitorNotifyAll(unsigned int);
  89.  
  90. /* Registry of static monitors */
  91. extern reg_mon_t *MonitorRegistry;
  92.  
  93. void monitorRegistryInit(void);
  94. void monitorRegister(sys_mon_t *, char *);
  95. void monitorUnregister(sys_mon_t *);
  96. void registeredEnumerate(void (*)(reg_mon_t *, void *), void *); 
  97. void registeredEnumerate_unlocked(void (*)(reg_mon_t *, void *), void *); 
  98.  
  99.  
  100. /*
  101.  * Random non-local locks without obviously better homes 
  102.  */
  103.  
  104. /* The class loading lock */
  105.  
  106. extern sys_mon_t *_loadclass_lock;
  107. #define LOADCLASS_LOCK_INIT() \
  108.     monitorRegister(_loadclass_lock, "Class loading lock")
  109. #define LOADCLASS_LOCK()     sysMonitorEnter(_loadclass_lock)
  110. #define LOADCLASS_LOCKED()   sysMonitorEntered(_loadclass_lock)
  111. #define LOADCLASS_UNLOCK()   sysMonitorExit(_loadclass_lock)
  112.  
  113. /* The global class table (binclasses) lock */
  114. extern sys_mon_t *_binclass_lock;
  115. #define BINCLASS_LOCK_INIT() monitorRegister(_binclass_lock, "BinClass lock")
  116. #define BINCLASS_LOCK()         sysMonitorEnter(_binclass_lock)
  117. #define BINCLASS_LOCKED()    sysMonitorEntered(_binclass_lock)
  118. #define BINCLASS_UNLOCK()    sysMonitorExit(_binclass_lock)
  119.  
  120. /* Locks on the interned string hash table */
  121.  
  122. extern sys_mon_t *_stringhash_lock;
  123. #define STRINGHASH_INIT()    monitorRegister(_stringhash_lock, \
  124.                          "String intern lock")
  125. #define STRINGHASH_LOCK()    sysMonitorEnter(_stringhash_lock)
  126. #define STRINGHASH_LOCKED()  sysMonitorEntered(_stringhash_lock)
  127. #define STRINGHASH_UNLOCK()  sysMonitorExit(_stringhash_lock)
  128.  
  129. /* Locks on the method info (name and signature) hash table */
  130.  
  131. extern sys_mon_t *_nametypehash_lock;
  132. #define NAMETYPEHASH_INIT()   monitorRegister(_nametypehash_lock, \
  133.                           "Name and type hash table lock")
  134. #define NAMETYPEHASH_LOCK()   sysMonitorEnter(_nametypehash_lock)
  135. #define NAMETYPEHASH_LOCKED() sysMonitorEntered(_nametypehash_lock)
  136. #define NAMETYPEHASH_UNLOCK() sysMonitorExit(_nametypehash_lock)
  137.  
  138. /* JNI global reference locks */
  139.  
  140. extern sys_mon_t *_globalref_lock;
  141. #define GLOBALREF_LOCK_INIT() \
  142.           monitorRegister(_globalref_lock, "JNI global reference lock")
  143. #define GLOBALREF_LOCK()        sysMonitorEnter(_globalref_lock)
  144. #define GLOBALREF_LOCKED()        sysMonitorEntered(_globalref_lock)
  145. #define GLOBALREF_UNLOCK()        sysMonitorExit(_globalref_lock)
  146.  
  147. #endif    /* !_MONITOR_H_ */
  148.