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

  1. /*
  2.  * @(#)sysmacros_md.h    1.15 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. #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.  * Set up thread-local storage for second order monitor cache.  The
  76.  * number of words of thread-local storage must be a power of 2!
  77.  */
  78. #define SYS_TLS_MONCACHE 8 /* must be power of 2 */
  79. #define sysCurrentCacheKey(tid) (tid->cacheKey)
  80. #define sysLocalMonCache(tid, hash) (tid->monitorCache[hash])
  81.  
  82.  
  83. #define sysMemoryFlush()  __asm { lock xor    DWORD PTR 0[esp], 0 }
  84.  
  85. /*
  86.  * Intel doesn't seem to support a weak consistency model for MP
  87.  * so we define this to do nothing.
  88.  */
  89. #define sysStoreBarrier() 0
  90.  
  91. /*
  92.  * Simple, fast recursive lock for the monitor cache.
  93.  */
  94. #include "mutex_md.h"
  95.  
  96. typedef struct {
  97.     mutex_t mutex;
  98.     long entry_count;
  99.     unsigned long owner;
  100. } cache_lock_t;
  101.  
  102. /*
  103.  * We do leave the mutex locked across the whole cache lock to avoid
  104.  * the extra unlock and lock that a smaller critical region would entail.
  105.  */
  106. extern cache_lock_t _moncache_lock;
  107. #define sysCacheLockInit() {   mutexInit(&_moncache_lock.mutex);    \
  108.                    _moncache_lock.entry_count = 0;        \
  109.                    _moncache_lock.owner = 0;        \
  110.                }
  111. #define sysCacheLock()     {   mutexLock(&_moncache_lock.mutex);    \
  112.                    sysAssert(_moncache_lock.entry_count >= 0);\
  113.                    if (_moncache_lock.entry_count++ == 0) {    \
  114.                   _moncache_lock.owner = GetCurrentThreadId();\
  115.                    }                    \
  116.                }
  117. /* Should not need locking: */
  118. #define sysCacheLocked()   (_moncache_lock.owner == GetCurrentThreadId())
  119. #define sysCacheUnlock()   {   sysAssert(_moncache_lock.entry_count > 0);\
  120.                    if (--_moncache_lock.entry_count == 0) {    \
  121.                   _moncache_lock.owner = 0;        \
  122.                    }                    \
  123.                    mutexUnlock(&_moncache_lock.mutex);    \
  124.                }
  125.  
  126. #endif /*_WIN32_SYSMACROS_MD_H_*/
  127.