sysmacros_md.h
来自「《移动Agent技术》一书的所有章节源代码。」· C头文件 代码 · 共 188 行
H
188 行
/*
* @(#)sysmacros_md.h 1.15 97/10/07
*
* Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the confidential and proprietary information of Sun
* Microsystems, Inc. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Sun.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
* THIS SOFTWARE OR ITS DERIVATIVES.
*
* CopyrightVersion 1.1_beta
*
*/
#ifndef _WIN32_SYSMACROS_MD_H_
#define _WIN32_SYSMACROS_MD_H_
#define sysMalloc malloc
#define sysFree free
#define sysCalloc calloc
#define sysRealloc realloc
/* A macro for sneaking into a sys_mon_t to get the owner sys_thread_t */
#define sysMonitorOwner(mid) ((mid)->monitor_owner)
#ifdef DEBUG
#ifdef IBM_OS2 /*ibm*/
#define sysAssert(expression) \
((expression) ? 0 : \
(DumpThreads(), \
panic("\"%s\", line %d: assertion failure\n", __FILE__, __LINE__), \
0))
#else /*ibm*/
#define sysAssert(expression) { \
if (!(expression)) { \
DumpThreads(); \
panic("\"%s\", line %d: assertion failure\n", __FILE__, __LINE__); \
} \
}
#endif /*ibm*/
#else
#define sysAssert(expression) 0
#endif
/*
* Check whether an exception occurred. This also gives us the oppor-
* tunity to use the already-required exception check as a trap for other
* system-specific conditions.
*/
#define sysCheckException(ee) \
if (!exceptionOccurred(ee)) { \
continue; \
}
/*
* Case insensitive compare of ASCII strings
*/
#define sysStricmp(a, b) stricmp(a, b)
#define sysIsAbsolute(s) \
(*(s) == '/' || *(s) == '\\' \
|| (isalpha(*(s)) && *((s)+1) == ':' \
&& (*((s)+2) == '\\' || *((s)+2) == '/')))
#define sysRead(fd, buf, n) read(fd, buf, n)
#define sysWrite(fd, buf, n) write(fd, buf, n)
#define sysClose(fd) close(fd)
#define sysReadDir(dirp) readdir(dirp)
#define sysCloseDir(dirp) closedir(dirp)
#define sysSeek(fd,where,whence) lseek(fd,where,whence)
/*
* Set up thread-local storage for second order monitor cache. The
* number of words of thread-local storage must be a power of 2!
*/
#define SYS_TLS_MONCACHE 8 /* must be power of 2 */
#define sysCurrentCacheKey(tid) (tid->cacheKey)
#define sysLocalMonCache(tid, hash) (tid->monitorCache[hash])
#ifdef IBM_OS2 /*ibm*/
#include <builtin.h>
#define sysMemoryFlush() {int a; __lxchg(&a, 0);}
#else /*ibm*/
#define sysMemoryFlush() __asm { lock xor DWORD PTR 0[esp], 0 }
#endif /*ibm*/
#if defined(JMS_TRL) && defined(IBM_ALLOC_CACHE) /*ibm.5331*/
/*
* Perform an or assignment, *addr |= bit, atomically. Perhaps, no need
* to yield, since it does not iterate more than 32 times.
*
* [TODO] Dynamically check whether it is an SMP, and, if it is not an
* SMP, replace the lock instruction with the nop instructions (DONE on OS/2).
*/
#ifdef IBM_OS2 /*ibm*/
extern void _Optlink AtomicSetBit(unsigned, unsigned);
#define sysAtomicSetBit(addr, bit) AtomicSetBit((unsigned)addr, (unsigned)bit)
#else /*ibm*/
#define sysAtomicSetBit(addr, bit) if (1){ \
__asm mov eax, addr \
__asm mov edx, bit \
__asm lock or [eax], edx \
} else
#endif /*ibm*/
#endif /*ibm.5331*/
/*
* Intel doesn't seem to support a weak consistency model for MP
* so we define this to do nothing.
*/
#define sysStoreBarrier() 0
#ifdef IBM_OS2 /*ibm*/
#define sysThreadSelf() quickThreadSelf()
#define quickThreadGetBackPtr(x) ((x)->cookie)
#define sysThreadGetBackPtr(x) quickThreadGetBackPtr(x)
#define THREADSELF() \
(quickThreadSelf() ? ((TID)quickThreadGetBackPtr(quickThreadSelf())) : 0)
#endif /*ibm*/
/*
* Simple, fast recursive lock for the monitor cache.
*/
#include "mutex_md.h"
#ifdef MON_FLAT /*ibm.5421*/
extern sys_mon_t *_moncache_lock;
#else /*ibm.5421*/
#ifdef IBM_OS2 /*ibm*/
typedef spinlock_t cache_lock_t;
/* No assert checks */
extern cache_lock_t _moncache_lock;
#define sysCacheLockInit()
#define sysCacheLock() spinLock(&_moncache_lock)
#define sysCacheLocked() spinLocked(&_moncache_lock)
#define sysCacheUnlock() spinUnlock(&_moncache_lock)
#else /*ibm*/
typedef struct {
mutex_t mutex;
long entry_count;
unsigned long owner;
} cache_lock_t;
/*
* We do leave the mutex locked across the whole cache lock to avoid
* the extra unlock and lock that a smaller critical region would entail.
*/
extern cache_lock_t _moncache_lock;
#define sysCacheLockInit() { mutexInit(&_moncache_lock.mutex); \
_moncache_lock.entry_count = 0; \
_moncache_lock.owner = 0; \
}
#define sysCacheLock() { mutexLock(&_moncache_lock.mutex); \
sysAssert(_moncache_lock.entry_count >= 0);\
if (_moncache_lock.entry_count++ == 0) { \
_moncache_lock.owner = GetCurrentThreadId();\
} \
}
/* Should not need locking: */
#define sysCacheLocked() (_moncache_lock.owner == GetCurrentThreadId())
#define sysCacheUnlock() { sysAssert(_moncache_lock.entry_count > 0);\
if (--_moncache_lock.entry_count == 0) { \
_moncache_lock.owner = 0; \
} \
mutexUnlock(&_moncache_lock.mutex); \
}
#endif /*ibm*/
#endif /*ibm.5421*/
#ifdef JIT_WAY /*ibm.5331*/
/* The current JIT interface requires sysMonitorExit to be a function *//*ibm.5344*/
#define sysMonitorExitLocked(mid) sysMonitorExit(mid) /*ibm.5344*/
#include "threads_md.h"
#define sysThreadsInitialized() ThreadsInitialized
#endif /* JIT_WAY */ /*ibm.5331*/
#endif /*_WIN32_SYSMACROS_MD_H_*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?