📄 tkmbx.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. * *---------------------------------------------------------------------- */#include "tcmgr.h"/* * Generate mail box * * Mail BOX can be used only in th same process. * */EXPORT ID _tkse_cre_mbx( T_CMBX *pk_cmbx ){ T_CMBX cmbx; ID id; ER err; /* Parameter check */ err = ChkSpaceR(pk_cmbx, sizeof(T_CMBX)); if ( err < E_OK ) { goto err_ret1; } if ( (pk_cmbx->mbxatr & (TA_DSNAME | TA_NODISWAI) )!= 0 ) { err = E_RSATR; goto err_ret1; } cmbx = *pk_cmbx; cmbx.exinf = GetTCinfo(TSK_SELF); cmbx.mbxatr &= ~(UW)TA_DELEXIT; /* Generate mail box */ id = tk_cre_mbx(&cmbx); if ( id < E_OK ) { err = id; goto err_ret1; } id = toBID(O_MBX, id); /* Register ID for deletion at termination. */ err = tcmTkRegistObject(id); if ( err < E_OK ) { goto err_ret2; } return id;err_ret2: tk_del_mbx(toIID(id));err_ret1: DEBUG_PRINT(("_tkse_cre_mbx err = %d\n", err)); return err;}/* * Delete mail box * When mail box generation process terminates, * the mail box is deleted automatically. */EXPORT ER _tkse_del_mbx( ID id ){ TCINFO *tcinfo; ER err; /* Check object ID */ err = tcmTkCheckID(O_MBX, id); if ( err < E_OK ) { goto err_ret; } /* Check register ID */ tcinfo = GetTCinfo(TSK_SELF); if ( tcinfo == NULL ) { err = E_CTX; goto err_ret; } err = tcmTkSearchObject(id, tcinfo); if ( err < E_OK ) { goto err_ret; } /* Mail box buffer */ err = tk_del_mbx(toIID(id)); if ( err < E_OK ) { goto err_ret; } /* Deregister ID */ err = tcmTkDeleteObject(id, tcinfo); if ( err < E_OK ) { goto err_ret; } return E_OK;err_ret: DEBUG_PRINT(("_tkse_del_mbx err = %d\n", err)); return err;}/* * Send to mail box */EXPORT ER _tkse_snd_mbx( ID id, T_MSG *msg){ TCINFO *tcinfo; ER err; /* Parameter check */ err = ChkSpaceR(msg, sizeof(T_MSG *)); if ( err < E_OK ) { goto err_ret; } /* Check object ID */ err = tcmTkCheckID(O_MBX, id); if ( err < E_OK ) { goto err_ret; } /* Check register ID */ tcinfo = GetTCinfo(TSK_SELF); if ( tcinfo == NULL ) { err = E_CTX; goto err_ret; } err = tcmTkSearchObject(id, tcinfo); if ( err < E_OK ) { goto err_ret; } /* Send message */ err = tk_snd_mbx(toIID(id), msg); if ( err < E_OK ) { goto err_ret; } return E_OK;err_ret: DEBUG_PRINT(("_tkse_snd_mbx err = %d\n", err)); return err;}/* * Receive from mail box */EXPORT INT _tkse_rcv_mbx( ID id, T_MSG **msg, TMO tmout ){ ER err; TCINFO *tcinfo; /* Check object ID */ err = tcmTkCheckID(O_MBX, id); if ( err < E_OK ) { goto err_ret; } /* Address check */ err = ChkSpaceRW(msg, sizeof(T_MSG **) ); if ( err < E_OK ) { goto err_ret; } /* Check register ID */ tcinfo = GetTCinfo(TSK_SELF); if ( tcinfo == NULL ) { err = E_CTX; goto err_ret; } err = tcmTkSearchObject(id, tcinfo); if ( err < E_OK ) { goto err_ret; } /* Receive message */ err = tk_rcv_mbx(toIID(id), msg, tmout);err_ret: DEBUG_PRINT(("_tkse_rcv_mbx err = %d\n", err)); return err;}/* * Refer to mail box state * T_RMBX * exinf Always return NULL */EXPORT ER _tkse_ref_mbx( ID id, T_RMBX *pk_rmbx ){ T_RMBX rmbx; ER err; /* Parameter check */ err = ChkSpaceRW(pk_rmbx, sizeof(T_RMBX)); if ( err < E_OK ) { goto err_ret; } /* Check object ID */ err = tcmTkCheckID(O_MBX, id); if ( err < E_OK ) { goto err_ret; } /* Obtain mail box information */ err = tk_ref_mbx(toIID(id), &rmbx); if ( err < E_OK ) { goto err_ret; } *pk_rmbx = rmbx; pk_rmbx->exinf = NULL; return E_OK;err_ret: DEBUG_PRINT(("_tkse_ref_mbx err = %d\n", err)); return err;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -