Tool/software: TI C/C++ Compiler
tirtos_tivac_2_10_01_38
CCS6
arm_5.1.11
I want to use a class wrapper to protect global variables to be accessed by different thread, like the following code (Note, some initiazation code is removed for simplicity):
GateMutexPri_Handle g_MutexHandle;
class MutexGateC:
{
public:
MutexGateC()
{
m_IArg = GateMutexPri_enter(g_MutexHandle);
}
~MutexGateC()
{
GateMutexPri_leave(g_MutexHandle, m_IArg);
}
private:
IArg m_IArg;
};
class HwiGateC:
{
public:
HwiGateC()
{
m_Key = Hwi_disable();
}
~HwiGateC()
{
Hwi_restore(m_Key);
}
private:
UInt m_Key;
};
Uint g_resource1;
Uint g_resource2;
void Func1(void)
{
MutexGateC m();
g_resource1++;
}
void Func2(void)
{
HwiGateC h();
g_resource2++;
}
My question, in function "Func1" and "Func2", can variable "m" and "h" be removed due to optimization, because it looks like the variables are never referenced? If it is possible, then on which optimization level? Thanks