完全编译,无需优化
void Add(T data)
{
node<T> *pNode = new node<T>;
pNode->m_pNext = NULL;
pNode->m_data = data;
uint32_t cPushes;
uint32_t cPops;
node<T> *pTail;
while (true)
{
cPushes = m_cPushes;
cPops = m_cPops;
pTail = (node<T>*)m_pTail;
if (cPushes != m_cPushes)
continue;
if (!pTail)
if (CAS2(&m_pTail, NULL, cPushes, (uint32_t)pNode, cPushes +1))
break;
else if (CAS(&pTail->m_pNext, NULL, (uint32_t)pNode))
break;
else
CAS2(&m_pTail, (uint32_t)pTail, cPushes, (uint32_t)pTail->m_pNext, cPushes + 1);
}
CAS2(&m_pHead, NULL, cPops, (uint32_t)pNode, cPops + 1);
CAS2(&m_pTail, (uint32_t)pTail, cPushes, (uint32_t)pNode, cPushes + 1);
}
反汇编:http://pastebin.com/7EaH3whu(因为它很大而且以某种方式打破了代码标签,因此会粘贴)
如果你看一下,关于每个跳转指令的地址都会混淆
例如,如果此语句失败:&#39; if(!pTail)&#39;,而不是继续&#39;否则如果&#39;它会跳回到循环的开头(实际上,它跳转到跳转到循环开始的跳转)
答案 0 :(得分:8)
if (!pTail)
if (CAS2(&m_pTail, NULL, cPushes, (uint32_t)pNode, cPushes +1))
break;
else if (CAS(&pTail->m_pNext, NULL, (uint32_t)pNode))
break;
else
CAS2(&m_pTail, (uint32_t)pTail, cPushes, (uint32_t)pTail->m_pNext, cPushes + 1);
真的是
if (!pTail) {
if (CAS2(&m_pTail, NULL, cPushes, (uint32_t)pNode, cPushes +1)) {
break;
} else if (CAS(&pTail->m_pNext, NULL, (uint32_t)pNode)) {
break;
} else {
CAS2(&m_pTail, (uint32_t)pTail, cPushes, (uint32_t)pTail->m_pNext, cPushes + 1);
}
}
跳跃是做什么的?我打赌。