op_prg_mt_global_lock()
摘要
锁定全局互斥锁。
语法
op_prg_mt_global_lock ()
| 参数 | 类型 | 说明 |
|---|---|---|
| 无参数 |
返回类型
Compcode
若全局互斥锁加锁成功,返回 OPC_COMPCODE_SUCCESS;否则返回 OPC_COMPCODE_FAILURE。
示例
/* Unless it is already done, initialize the receiver */
/* channel's state information. */
if (op_ima_obj_state_get (rx_obid) == OPC_NIL)
{
/* Channel state information doesn't exist. Lock */
/* the global mutex before continuing. */
op_prg_mt_global_lock ();
/* Check again, because another thread may have */
/* already set up the state information. */
if (op_ima_obj_state_get (rx_obid) == OPC_NIL)
{
/* Create and set the initial state information */
/* for the receiver channel. */
rxch_state_ptr = (DraT_Rxch_State_Info *)
op_prg_mem_alloc (sizeof (DraT_Rxch_State_Info));
rxch_state_ptr->signal_lock = OPC_FALSE;
op_ima_obj_state_set (rx_obid, rxch_state_ptr);
}
/* Unlock the global mutex. */
op_prg_mt_global_unlock ();
}
详情
无。
用途
提供了一种锁定全局互斥锁的方法。全局互斥锁是一个内置互斥锁,具有尽可能高的等级(rank),在不希望或无法创建专用互斥锁时可供模型代码使用。
错误
- 可恢复错误:互斥锁指针为空
- 可恢复错误:互斥锁(
prg_global_mutex):锁定标志OPC_MT_MUTEX_LOCK_READER与OPC_MT_MUTEX_LOCK_WRITER互斥 - 可恢复错误:互斥锁(
prg_global_mutex)已被该线程针对 Objid(<lock_objid>)锁定 - 可恢复错误:等级为
<rank>的互斥锁(prg_global_mutex)不能在等级为<locked_mutex_rank>的互斥锁(<locked_mutex_description>)之后加锁
参考
- 使用内核过程 op_prg_mt_global_unlock() 解锁全局互斥锁
- 使用内核过程 op_prg_mt_mutex_lock() 锁定特定互斥锁