home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1998 February / VPR9802A.ISO / APP_DEMO / VC / MAIN.BIN / sysmacros_md.h < prev    next >
C/C++ Source or Header  |  1997-10-27  |  3KB  |  108 lines

  1. /*
  2.  * @(#)sysmacros_md.h    1.13 97/02/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. #ifndef _WIN32_SYSMACROS_MD_H_
  24. #define _WIN32_SYSMACROS_MD_H_
  25.  
  26. #define sysMalloc    malloc
  27. #define sysFree        free
  28. #define sysCalloc     calloc
  29. #define sysRealloc    realloc
  30.  
  31. /* A macro for sneaking into a sys_mon_t to get the owner sys_thread_t */
  32. #define sysMonitorOwner(mid)   ((mid)->monitor_owner)
  33.  
  34. #ifdef DEBUG
  35. #define sysAssert(expression) {        \
  36.     if (!(expression)) {        \
  37.     DumpThreads();            \
  38.     panic("\"%s\", line %d: assertion failure\n", __FILE__, __LINE__); \
  39.     }                    \
  40. }
  41. #else
  42. #define sysAssert(expression) 0
  43. #endif
  44.  
  45. /*
  46.  * Check whether an exception occurred.  This also gives us the oppor-
  47.  * tunity to use the already-required exception check as a trap for other
  48.  * system-specific conditions.
  49.  */
  50. #define sysCheckException(ee) \
  51.     if (!exceptionOccurred(ee)) { \
  52.        continue; \
  53.     }
  54.  
  55. #define sysIsAbsolute(s) \
  56.     (*(s) == '/' || *(s) == '\\' \
  57.      || (isalpha(*(s)) && *((s)+1) == ':' \
  58.          && (*((s)+2) == '\\' || *((s)+2) == '/')))
  59.  
  60. #define sysRead(fd, buf, n)    read(fd, buf, n)
  61. #define sysWrite(fd, buf, n)    write(fd, buf, n)
  62. #define sysClose(fd)        close(fd)
  63. #define sysReadDir(dirp)    readdir(dirp)
  64. #define sysCloseDir(dirp)    closedir(dirp)
  65. #define sysSeek(fd,where,whence) lseek(fd,where,whence)
  66. #define sysRename(src,dst)    rename(src,dst)
  67. #define sysRmdir(dirp)          _rmdir(dirp)
  68.  
  69. /*
  70.  * Simple, fast recursive lock for the monitor cache.
  71.  */
  72. #include "mutex_md.h"
  73.  
  74. typedef struct {
  75.     mutex_t mutex;
  76.     long entry_count;
  77.     unsigned long owner;
  78. } cache_lock_t;
  79.  
  80. /*
  81.  * We do leave the mutex locked across the whole cache lock to avoid
  82.  * the extra unlock and lock that a smaller critical region would entail.
  83.  */
  84. extern cache_lock_t _moncache_lock;
  85. #define sysCacheLockInit() {   mutexInit(&_moncache_lock.mutex);    \
  86.                    _moncache_lock.entry_count = 0;        \
  87.                    _moncache_lock.owner = 0;        \
  88.                }
  89. #define sysCacheLock()     {   mutexLock(&_moncache_lock.mutex);    \
  90.                    sysAssert(_moncache_lock.entry_count >= 0);\
  91.                    if (_moncache_lock.entry_count++ == 0) {    \
  92.                   _moncache_lock.owner = GetCurrentThreadId();\
  93.                    }                    \
  94.                }
  95. /* Should not need locking: */
  96. #define sysCacheLocked()   (_moncache_lock.owner == GetCurrentThreadId())
  97. #define sysCacheUnlock()   {   sysAssert(_moncache_lock.entry_count > 0);\
  98.                    if (--_moncache_lock.entry_count == 0) {    \
  99.                   _moncache_lock.owner = 0;        \
  100.                    }                    \
  101.                    mutexUnlock(&_moncache_lock.mutex);    \
  102.                }
  103.  
  104. /* The current JIT interface requires sysMonitorExit to be a function */
  105. #define sysMonitorExitLocked(mid)    sysMonitorExit(mid)
  106.  
  107. #endif /*_WIN32_SYSMACROS_MD_H_*/
  108.