home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / jdk113 / root / opt / jdk-1.1.3 / include / unixware / sysmacros_md.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-19  |  4.7 KB  |  147 lines

  1. /*
  2.  * @(#)sysmacros_md.h    1.19 97/07/29
  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. #ifndef _SOLARIS_SYSMACROS_MD_H_
  24. #define _SOLARIS_SYSMACROS_MD_H_
  25.  
  26. /*
  27.  * Because these are used directly as function ptrs, just redefine the name
  28.  */
  29. #define sysMalloc    malloc
  30. #define sysFree        free
  31. #define sysCalloc    calloc
  32. #define sysRealloc    realloc
  33.  
  34. /* A macro for sneaking into a sys_mon_t to get the owner sys_thread_t */
  35. #define sysMonitorOwner(mid)   ((mid)->monitor_owner)
  36.  
  37. #ifdef DEBUG
  38. extern void DumpThreads(void);
  39. void panic (const char *, ...);
  40. #define sysAssert(expression) {        \
  41.     if (!(expression)) {        \
  42.     DumpThreads();            \
  43.     panic("\"%s\", line %d: assertion failure\n", __FILE__, __LINE__); \
  44.     }                    \
  45. }
  46. #else
  47. #define sysAssert(expression) 0
  48. #endif
  49.  
  50. /*
  51.  * Check whether an exception occurred.  This also gives us the oppor-
  52.  * tunity to use the already-required exception check as a trap for other
  53.  * system-specific conditions.
  54.  */
  55. #define sysCheckException(ee) \
  56.     if (!exceptionOccurred(ee)) { \
  57.        continue; \
  58.     }
  59.  
  60. /*
  61.  * File system macros
  62.  */
  63. #define sysOpen(_path, _oflag, _mode)    open(_path, _oflag, _mode)
  64. #define sysRead(_fd, _buf, _n)        read(_fd, _buf, _n)
  65. #define sysWrite(_fd, _buf, _n)        write(_fd, _buf, _n)
  66. #define sysClose(_fd)            close(_fd)
  67. #define sysAccess(_path, _mode)        access(_path, _mode)
  68. #define sysStat(_path, _buf)        stat(_path, _buf)
  69. #define sysMkdir(_path, _mode)        mkdir(_path, _mode)
  70. #define sysUnlink(_path)        unlink(_path)
  71. #define sysIsAbsolute(_path)        (*(_path) == '/')
  72. #define sysCloseDir(_dir)        closedir(_dir)
  73. #define sysOpenDir(_path)        opendir(_path)
  74. #define sysRmdir(_dir)                  remove(_dir)
  75. #define sysNativePath(path)            (path) 
  76. #define sysSeek(fd, offset, whence)    lseek(fd, offset, whence)
  77. #define sysRename(s, d)            rename(s, d)
  78.  
  79. /*
  80.  * Simple, fast recursive lock for the monitor cache.
  81.  *
  82.  * This is threads package specific, whereas sysmacros.h is not, but
  83.  * could be simplified if sysmacros.h ever specializes.
  84.  * 
  85.  * The includes for threads package-specific files are ugly here because
  86.  * this file goes into javah, which doesn't otherwise include from those
  87.  * directories.
  88.  *
  89.  * Let's face it...we need threads package-specific sys include files.
  90.  */
  91. #ifndef NATIVE
  92.  
  93. #include "../green_threads/include/schedule.h"
  94. #define sysCacheLockInit()     /* A no-op */
  95. #define sysCacheLock()        SCHED_LOCK()
  96. #define sysCacheLocked()    SCHED_LOCKED()
  97. #define sysCacheUnlock()    SCHED_UNLOCK()
  98.  
  99. /* Override the extern in sys_api.h with something faster */
  100. #define sysThreadSelf()        greenThreadSelf()
  101.  
  102. #else
  103.  
  104. #include "../native_threads/include/mutex_md.h"
  105.  
  106. typedef struct {
  107.     mutex_t mutex;
  108.     long entry_count;
  109.     sys_thread_t *owner;
  110. } cache_lock_t;
  111.  
  112. /*
  113.  * We do leave the mutex locked across the whole cache lock to avoid
  114.  * the extra unlock and lock that a smaller critical region would entail.
  115.  */
  116. extern cache_lock_t _moncache_lock;
  117. #define sysCacheLockInit() {   mutexInit(&_moncache_lock.mutex);    \
  118.                    _moncache_lock.entry_count = 0;        \
  119.                    _moncache_lock.owner = 0;        \
  120.                }
  121. #define sysCacheLock()     {   mutexLock(&_moncache_lock.mutex);    \
  122.                    sysAssert(_moncache_lock.entry_count >= 0);\
  123.                    if (_moncache_lock.entry_count++ == 0) {    \
  124.                   _moncache_lock.owner = sysThreadSelf();\
  125.                    }                    \
  126.                }
  127. /* Should not need locking: */
  128. #define sysCacheLocked()   (_moncache_lock.owner == sysThreadSelf())
  129. #define sysCacheUnlock()   {   sysAssert(_moncache_lock.entry_count > 0);\
  130.                    if (--_moncache_lock.entry_count == 0) {    \
  131.                   _moncache_lock.owner = 0;        \
  132.                    }                    \
  133.                    mutexUnlock(&_moncache_lock.mutex);    \
  134.                }
  135.  
  136. /* The current JIT interface requires sysMonitorExit to be a function */
  137. #define sysMonitorExitLocked(mid)    sysMonitorExit(mid)
  138.  
  139. /* For probing hot monitors using TNF */
  140. #if (defined(SOLARIS2) && defined(NATIVE) && defined(DEBUG))
  141. #define sysMonitorExitLocked_probed(mid, key)   sysMonitorExit_probed(mid, key)
  142. #endif
  143.  
  144. #endif /* NATIVE */
  145.  
  146. #endif /*_SOLARIS_SYSMACROS_MD_H_*/
  147.