op_prg_mt_mutex_lock()

摘要

锁定先前创建的互斥锁。

语法

op_prg_mt_mutex_lock (mutex_ptr, option)
参数 类型 说明
mutex_ptr PrgT_Mutex * 待锁定的互斥锁。
option int 互斥锁的锁定模式。必须是详情一节所列符号常量之一(另见表 63 “Mutex Lock Options Symbolic Constants“ 第 17 页)。

返回类型

Compcode

若互斥锁加锁成功,返回 OPC_COMPCODE_SUCCESS;否则返回 OPC_COMPCODE_FAILURE。

示例

/* Evaluate reliability of beacons that are transmitted on the channel   */
/* currently used by the receiver (i.e. if the initial status is VALID). */

if (rx_state_ptr->roaming_info_ptr->enable_roaming &&
	chanmatch_status == OPC_TDA_RA_MATCH_VALID)
	{
	op_pk_nfd_access (pkptr, "Type", &rcvd_frame_type);
	if (rcvd_frame_type == WlanC_Beac)
		{
		/* Serialize the execution of AP reliability evaluation, because the     */
		/* MAC of the receiver might be reading or writing the same information. */
		op_prg_mt_mutex_lock (rx_state_ptr->roaming_info_ptr->roam_info_mutex, 0);
		wlan_ap_reliability_eval (pkptr, OPC_FALSE, rx_state_ptr->roaming_info_ptr);
		op_prg_mt_mutex_unlock (rx_state_ptr->roaming_info_ptr->roam_info_mutex);
		}
	}

详情

option 必须是以下符号常量之一:

  • OPC_MT_MUTEX_LOCK_READER——以读者模式(共享)锁定读/写互斥锁
  • OPC_MT_MUTEX_LOCK_WRITER——以写者模式(独占)锁定读/写互斥锁

在以下情况下,该操作会失败:

  • 互斥锁创建时使用了 rank 参数,且同一线程已经锁定了编号更高的互斥锁。
  • 互斥锁创建时未使用 OPC_MT_MUTEX_RECURSIVE 选项,且该线程已经锁定了该互斥锁。

更多信息参见 op_prg_mt_mutex_create() 的详情一节。

用途

提供了一种锁定特定互斥锁的方法,从而防止其他代码线程获得该互斥锁。

错误

  • 可恢复错误:互斥锁指针为空
  • 可恢复错误:互斥锁(<description>):锁定标志 OPC_MT_MUTEX_LOCK_READER 与 OPC_MT_MUTEX_LOCK_WRITER 互斥
  • 可恢复错误:互斥锁(<description>)已被该线程针对 Objid(<lock_objid>)锁定
  • 可恢复错误:等级为 <rank> 的互斥锁(<description>)不能在等级为 <locked_mutex_rank> 的互斥锁(<locked_mutex_description>)之后加锁

参考

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com