⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mutex_md.h

📁 《移动Agent技术》一书的所有章节源代码。
💻 H
字号:
/*
 * @(#)mutex_md.h	1.9 96/11/23
 *
 * 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
 *
 */

/*
 * Win32 implementation of mutexes. Here we use critical sections as
 * our mutexes. We could have used mutexes, but mutexes are heavier
 * weight than critical sections. Mutexes and critical sections are
 * semantically identical, the only difference being that mutexes
 * can operate between processes (i.e. address spaces).
 *
 * It's worth noting that the Win32 functions supporting critical
 * sections do not provide any error information whatsoever (i.e.
 * all critical section routines return (void)).
 */

#ifndef	_WIN32_MUTEX_MD_H_
#define	_WIN32_MUTEX_MD_H_

#ifdef IBM_OS2								                            /*ibm*/

#include <javaos2.h>
#include <builtin.h>
#include <spinlock_md.h>

typedef QUICKSEM mutex_t;

#define mutexInit(x) ((WinMtxInit(x) == 0) ? SYS_OK : SYS_NORESOURCE)
#define mutexDestroy(x)
int mutexLock(mutex_t *);
#ifdef FASTMUTEX
int mutexLock0(mutex_t *);
#define mutexLock(x) (DQTCpfn ? WinMtxRequest((x),SEM_INDEFINITE_WAIT) \
                              : mutexLock0(x))
#endif
#define mutexUnlock(x)  WinMtxRelease(x)
#define mutexLocked(x) ((x)->Owner \
                      == _getTIBvalue(offsetof(TIB, tib_ordinal)))

#else									                                /*ibm*/

#include <windows.h>

#if defined(IBM_WIN32_RAM_SEMS)                                         /*ibm.7334*/
extern void __stdcall FastEnterCriticalSection(CRITICAL_SECTION*);
extern void __stdcall FastLeaveCriticalSection(CRITICAL_SECTION*);
extern int SPIN_Locks;                           
#endif                                                                  /*ibm.7334*/

typedef CRITICAL_SECTION mutex_t;

#define mutexInit(m)	InitializeCriticalSection(m)
#define mutexDestroy(m)	DeleteCriticalSection(m)
#if defined(IBM_WIN32_RAM_SEMS)                                         /*ibm.7334*/
#define mutexLock(m) {	                        \
	if (SPIN_Locks) FastEnterCriticalSection(m); \
	else EnterCriticalSection(m);               \
	}
#define mutexUnlock(m) {	                    \
	if (SPIN_Locks) FastLeaveCriticalSection(m); \
	else LeaveCriticalSection(m);               \
	}
#else                                                                  /*ibm.7334*/
#define mutexLock(m)	EnterCriticalSection(m)
#define mutexUnlock(m)	LeaveCriticalSection(m)
#endif                                                                 /*ibm.7334*/

#endif                                                                 /*ibm*/

#endif	/* !_WIN32_MUTEX_MD_H_ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -