home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 July & August / Pcwk78a98.iso / Internet / Javadraw / DATA.Z / sysmacros_md.h < prev    next >
C/C++ Source or Header  |  1997-08-30  |  4KB  |  113 lines

  1. /*
  2.  * @(#)sysmacros_md.h    1.14 97/08/04
  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. /*
  56.  * Case insensitive compare of ASCII strings
  57.  */
  58. #define sysStricmp(a, b)        stricmp(a, b)
  59.  
  60. #define sysIsAbsolute(s) \
  61.     (*(s) == '/' || *(s) == '\\' \
  62.      || (isalpha(*(s)) && *((s)+1) == ':' \
  63.          && (*((s)+2) == '\\' || *((s)+2) == '/')))
  64.  
  65. #define sysRead(fd, buf, n)    read(fd, buf, n)
  66. #define sysWrite(fd, buf, n)    write(fd, buf, n)
  67. #define sysClose(fd)        close(fd)
  68. #define sysReadDir(dirp)    readdir(dirp)
  69. #define sysCloseDir(dirp)    closedir(dirp)
  70. #define sysSeek(fd,where,whence) lseek(fd,where,whence)
  71. #define sysRename(src,dst)    rename(src,dst)
  72. #define sysRmdir(dirp)          _rmdir(dirp)
  73.  
  74. /*
  75.  * Simple, fast recursive lock for the monitor cache.
  76.  */
  77. #include "mutex_md.h"
  78.  
  79. typedef struct {
  80.     mutex_t mutex;
  81.     long entry_count;
  82.     unsigned long owner;
  83. } cache_lock_t;
  84.  
  85. /*
  86.  * We do leave the mutex locked across the whole cache lock to avoid
  87.  * the extra unlock and lock that a smaller critical region would entail.
  88.  */
  89. extern cache_lock_t _moncache_lock;
  90. #define sysCacheLockInit() {   mutexInit(&_moncache_lock.mutex);    \
  91.                    _moncache_lock.entry_count = 0;        \
  92.                    _moncache_lock.owner = 0;        \
  93.                }
  94. #define sysCacheLock()     {   mutexLock(&_moncache_lock.mutex);    \
  95.                    sysAssert(_moncache_lock.entry_count >= 0);\
  96.                    if (_moncache_lock.entry_count++ == 0) {    \
  97.                   _moncache_lock.owner = GetCurrentThreadId();\
  98.                    }                    \
  99.                }
  100. /* Should not need locking: */
  101. #define sysCacheLocked()   (_moncache_lock.owner == GetCurrentThreadId())
  102. #define sysCacheUnlock()   {   sysAssert(_moncache_lock.entry_count > 0);\
  103.                    if (--_moncache_lock.entry_count == 0) {    \
  104.                   _moncache_lock.owner = 0;        \
  105.                    }                    \
  106.                    mutexUnlock(&_moncache_lock.mutex);    \
  107.                }
  108.  
  109. /* The current JIT interface requires sysMonitorExit to be a function */
  110. #define sysMonitorExitLocked(mid)    sysMonitorExit(mid)
  111.  
  112. #endif /*_WIN32_SYSMACROS_MD_H_*/
  113.