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

📄 fastlock.c

📁 uT Kernel os source code for AT91
💻 C
字号:
/* *---------------------------------------------------------------------- *    micro T-Kernel * *    Copyright (C) 2006-2007 by Ken Sakamura. All rights reserved. *    micro T-Kernel is distributed under the micro T-License. *---------------------------------------------------------------------- * *    Version:   1.00.00 *    Released by T-Engine Forum(http://www.t-engine.org) at 2007/03/26. * *---------------------------------------------------------------------- *//* *	@(#)fastlock.c (libtk) * *	High-speed exclusive control lock  *//** [BEGIN Common Definitions] */#include <basic.h>#include <tk/tkernel.h>#include <tk/util.h>#include <libstr.h>#include "libtk_config.h"/* ------------------------------------------------------------------------ *//* *	Inc	Increment cnt, in result if cnt >  0, returns positive value. *		If cnt <= 0, returns 0 or negative value. *	Dec	Decrement cnt, in result if cnt >= 0, returns positive value. *		If cnt <  0, returns 0 or negative value.  *	Increment/Decrement and evaluation of the associated result must *	be executed exclusively. */Inline INT Inc( FastLock *lock ){	UINT	imask;	INT	c;	DI(imask);	c = ++lock->cnt;	EI(imask);	return c;}Inline INT Dec( FastLock *lock ){	UINT	imask;	INT	c;	DI(imask);	c = lock->cnt--;	EI(imask);	return c;}/* ------------------------------------------------------------------------ *//** [END Common Definitions] */#ifdef USE_FUNC_LOCK/* * Lock  */EXPORT void Lock( FastLock *lock ){	if ( Inc(lock) > 0 ) {		tk_wai_sem(lock->id, 1, TMO_FEVR);	}}#endif /* USE_FUNC_LOCK */#ifdef USE_FUNC_UNLOCK/* * Lock release */EXPORT void Unlock( FastLock *lock ){	if ( Dec(lock) > 0 ) {		tk_sig_sem(lock->id, 1);	}}#endif /* USE_FUNC_UNLOCK */#ifdef USE_FUNC_CREATELOCK/* * Create high-speed lock  */EXPORT ER CreateLock( FastLock *lock, UB *name ){	T_CSEM	csem;	ER	ercd;	if ( name == NULL ) {		csem.exinf = NULL;	} else {		strncpy((char*)&csem.exinf, (char*)name, sizeof(csem.exinf));	}	csem.sematr  = TA_TPRI;	csem.isemcnt = 0;	csem.maxsem  = 1;	ercd = tk_cre_sem(&csem);	if ( ercd < E_OK ) {		return ercd;	}	lock->id = ercd;	lock->cnt = -1;	return E_OK;}#endif /* USE_FUNC_CREATELOCK */#ifdef USE_FUNC_DELETELOCK/* * Delete high-speed lock */EXPORT void DeleteLock( FastLock *lock ){	if ( lock->id > 0 ) {		tk_del_sem(lock->id);	}	lock->id = 0;}#endif /* USE_FUNC_DELETELOCK */

⌨️ 快捷键说明

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