cwSpScQueueTmpl.h : Change operation such that get() ony returns empty records.
This commit is contained in:
parent
48ebcc89c7
commit
85d7098061
@ -21,13 +21,8 @@ namespace cw
|
|||||||
mem::release(_aV);
|
mem::release(_aV);
|
||||||
}
|
}
|
||||||
|
|
||||||
T* get()
|
|
||||||
{
|
|
||||||
unsigned wi = _wi.load( std::memory_order_relaxed );
|
|
||||||
return _aV + wi;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc_t publish()
|
T* get()
|
||||||
{
|
{
|
||||||
unsigned ri = _ri.load( std::memory_order_acquire );
|
unsigned ri = _ri.load( std::memory_order_acquire );
|
||||||
unsigned wi = _wi.load( std::memory_order_relaxed ); // _wi is written in this thread
|
unsigned wi = _wi.load( std::memory_order_relaxed ); // _wi is written in this thread
|
||||||
@ -38,14 +33,20 @@ namespace cw
|
|||||||
// there must always be at least one empty element because
|
// there must always be at least one empty element because
|
||||||
// wi can never be advanced to equal ri.
|
// wi can never be advanced to equal ri.
|
||||||
if( n >= _aN-1 )
|
if( n >= _aN-1 )
|
||||||
return kBufTooSmallRC;
|
return nullptr;
|
||||||
|
|
||||||
|
return _aV + wi;
|
||||||
|
}
|
||||||
|
|
||||||
|
void publish()
|
||||||
|
{
|
||||||
|
unsigned wi = _wi.load( std::memory_order_relaxed ); // _wi is written in this thread
|
||||||
|
|
||||||
wi = (wi+1) % _aN;
|
wi = (wi+1) % _aN;
|
||||||
|
|
||||||
// advance the write position
|
// advance the write position
|
||||||
_wi.store( wi, std::memory_order_release );
|
_wi.store( wi, std::memory_order_release );
|
||||||
|
|
||||||
return kOkRC;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
T* pop()
|
T* pop()
|
||||||
|
Loading…
Reference in New Issue
Block a user