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

📄 tkmtx.c

📁 T-kernel 的extension源代码
💻 C
字号:
/* *---------------------------------------------------------------------- *    T-Kernel / Standard Extension * *    Copyright (C) 2006 by Ken Sakamura. All rights reserved. *    T-Kernel / Standard Extension is distributed  *      under the T-License for T-Kernel / Standard Extension. *---------------------------------------------------------------------- * *    Version:   1.00.00 *    Released by T-Engine Forum(http://www.t-engine.org) at 2006/8/11. * *---------------------------------------------------------------------- *//* *	tkmtx.c (taskcomm) * *	T-Kernel compatible mutex */#include "tcmgr.h"/* * Generate mutex *	T_CMTX *	exinf	Ignored *	mtxatr	Priority inheritance and ceiling protocols cannot be used. *		TA_NODISWAI cannot be specified *		mtxatr := (TA_TFIFO || TA_TPRI) | TA_DELEXIT *	ceilpri	Not used */EXPORT ID _tkse_cre_mtx( T_CMTX *pk_cmtx ){	T_CMTX	cmtx;	ID	id;	ER	err;	/* Parameter check */	err = ChkSpaceR(pk_cmtx, sizeof(T_CMTX));	if ( err < E_OK ) {		goto err_ret1;	}	if ( ((pk_cmtx->mtxatr & TA_CEILING) > TA_TPRI )	  || ((pk_cmtx->mtxatr & (TA_DSNAME | TA_NODISWAI) ) != 0U )) {		err = E_RSATR;		goto err_ret1;	}	cmtx = *pk_cmtx;	if ( (pk_cmtx->mtxatr & (UW)TA_DELEXIT) != 0U ) {		cmtx.exinf = GetTCinfo(TSK_SELF);		cmtx.mtxatr &= ~(UW)TA_DELEXIT;	} else {		cmtx.exinf = NULL;	}	id = tk_cre_mtx(&cmtx);	if ( id < E_OK ) {		err = id;		goto err_ret1;	}	id = toBID(O_MTX, id);	if (cmtx.exinf != NULL) {		/* Register ID for deletion at termination. */		err = tcmTkRegistObject(id);		if ( err < E_OK ) {			goto err_ret2;		}	}	return id;err_ret2:	(void)tk_del_mtx(toIID(id));err_ret1:	DEBUG_PRINT(("_tkse_cre_mtx err = %d\n", err));	return err;}/* * Delete mutex *	When the mutex generation process terminates, *	the mutex is deleted automatically. */EXPORT ER _tkse_del_mtx( ID id ){	TCINFO	*tcinfo;	T_RMTX	rmtx;	ER	err;	/* Check ID */	err = tcmTkCheckID(O_MTX, id);	if ( err < E_OK ) {		goto err_ret;	}	/* Obtain mutex information. */	err = tk_ref_mtx(toIID(id), &rmtx);	if ( err < E_OK ) {		goto err_ret;	}	tcinfo = rmtx.exinf;  /* Generation process */	/* Delete mutex */	err = tk_del_mtx(toIID(id));	if ( err < E_OK ) {		goto err_ret;	}	if ( tcinfo != NULL ) {		/* Deregister ID */		err = tcmTkDeleteObject(id, tcinfo);		if ( err < E_OK ) {			goto err_ret;		}	}	return E_OK;err_ret:	DEBUG_PRINT(("_tkse_del_mtx err = %d\n", err));	return err;}/* * Obtain lock for mutex. *	When interrupted by message handler, *	wait state is reset and E_DISWAI is returned. */EXPORT ER _tkse_loc_mtx( ID id, TMO tmout ){	ER	err;	/* Check ID */	err = tcmTkCheckID(O_MTX, id);	if ( err < E_OK ) {		goto err_ret;	}	/* Obtain lock. */	err = tk_loc_mtx(toIID(id), tmout);	if ( err < E_OK ) {		goto err_ret;	}	return E_OK;err_ret:	DEBUG_PRINT(("_tkse_loc_mtx err = %d\n", err));	return err;}/* * Unlock mutex. */EXPORT ER _tkse_unl_mtx( ID id ){	ER	err;	/* Check ID */	err = tcmTkCheckID(O_MTX, id);	if ( err < E_OK ) {		goto err_ret;	}	/* Unlock */	err = tk_unl_mtx(toIID(id));	if ( err < E_OK ) {		goto err_ret;	}	return E_OK;err_ret:	DEBUG_PRINT(("_tkse_unl_mtx err = %d\n", err));	return err;}/* * Refer to mutex state *	T_RMTX *	exinf	Always return NULL */EXPORT ER _tkse_ref_mtx( ID id, T_RMTX *pk_rmtx ){	T_RMTX	rmtx;	ER	err;	/* Parameter check */	err = ChkSpaceRW(pk_rmtx, sizeof(T_RMTX));	if ( err < E_OK ) {		goto err_ret;	}	/* Check ID */	err = tcmTkCheckID(O_MTX, id);	if ( err < E_OK ) {		goto err_ret;	}	/* Obtain mutex information. */	err = tk_ref_mtx(toIID(id), &rmtx);	if ( err < E_OK ) {		goto err_ret;	}	*pk_rmtx = rmtx;	pk_rmtx->exinf = NULL;	return E_OK;err_ret:	DEBUG_PRINT(("_tkse_ref_mtx err = %d\n", err));	return err;}

⌨️ 快捷键说明

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