工具/软件:TI C/C++编译器
tirtos_tivac_2_10_01_38
CCS6
Arm 5.1
我想使用类包装来保护要由不同线程访问的全局变量,如以下代码(注意,为了简单起见,删除了一些初始化代码):
GateMutexPri句柄g_MutexHandle;
类MutexGateC:
{
公共:
MutexGateC()
{
M_IArg = GateMutexPri_Handenter(g_MutexHandle);
}
~MutexGateC()
{
GateMutexPri Leave (g_MutexHandle, m_IArg);
}
私人:
IArg m_IArg;
};
类HwiGateC:
{
公共:
HwiGateC()
{
M_Key = HWI_DISABLE();
}
~HWiGateC()
{
hwi_restore(m_Key);
}
私人:
UINT m_Key;
};
Uint g_resource1;
Uint g_resource2;
void Func1(void){
MutexGateC m();
g_resource1+;
}
作废Func2(void){
HwiGateCh();
g_resource2+;
}
我的问题是,在函数“Func1”和“Func2”中,变量“m”和“h”是否可以因优化而被删除,因为看起来变量从未被引用过? 如果可能,那么在哪个优化级别上? 谢谢