标签:boost lockfree boost.lockfree
Boost Lockfree
flyfish 2014-9-30
为了最大限度的挖掘并行编程的性能考虑使用与锁无关的数据结构来编程bool CAS(int* p,int nOld,int nNew)
{
bool bRet=false;
if (*p == nOld)
{
*p=nNew;
bRet=true;
}
return bRet;
}
template <class T>
class tagged_ptr
{
public:
typedef std::size_t tag_t;
protected:
T * ptr;
tag_t tag;
};#if defined (__x86_64__) || defined (_M_X64)
class tagged_ptr
{
typedef boost::uint64_t compressed_ptr_t;
public:
typedef boost::uint16_t tag_t;
private:
union cast_unit
{
compressed_ptr_t value;
tag_t tag[4];
};
static const int tag_index = 3;
static const compressed_ptr_t ptr_mask = 0xffffffffffffUL; //(1L<<48L)-1;
......
}
#else
#error unsupported platform
#endif标签:boost lockfree boost.lockfree
原文地址:http://blog.csdn.net/flyfish1986/article/details/39695305