Problem: inconsistent naming style for private data members, conflicts with naming of local variables and member functions

Solution: apply and check _lower_case naming style for private data members
This commit is contained in:
Simon Giesecke
2018-05-27 11:10:39 +02:00
parent 06cfd0d8ad
commit e3c73d9881
143 changed files with 5783 additions and 4051 deletions

View File

@@ -65,60 +65,60 @@ template <typename T, int N> class yqueue_t
// Create the queue.
inline yqueue_t ()
{
begin_chunk = allocate_chunk ();
alloc_assert (begin_chunk);
begin_pos = 0;
back_chunk = NULL;
back_pos = 0;
end_chunk = begin_chunk;
end_pos = 0;
_begin_chunk = allocate_chunk ();
alloc_assert (_begin_chunk);
_begin_pos = 0;
_back_chunk = NULL;
_back_pos = 0;
_end_chunk = _begin_chunk;
_end_pos = 0;
}
// Destroy the queue.
inline ~yqueue_t ()
{
while (true) {
if (begin_chunk == end_chunk) {
free (begin_chunk);
if (_begin_chunk == _end_chunk) {
free (_begin_chunk);
break;
}
chunk_t *o = begin_chunk;
begin_chunk = begin_chunk->next;
chunk_t *o = _begin_chunk;
_begin_chunk = _begin_chunk->next;
free (o);
}
chunk_t *sc = spare_chunk.xchg (NULL);
chunk_t *sc = _spare_chunk.xchg (NULL);
free (sc);
}
// Returns reference to the front element of the queue.
// If the queue is empty, behaviour is undefined.
inline T &front () { return begin_chunk->values[begin_pos]; }
inline T &front () { return _begin_chunk->values[_begin_pos]; }
// Returns reference to the back element of the queue.
// If the queue is empty, behaviour is undefined.
inline T &back () { return back_chunk->values[back_pos]; }
inline T &back () { return _back_chunk->values[_back_pos]; }
// Adds an element to the back end of the queue.
inline void push ()
{
back_chunk = end_chunk;
back_pos = end_pos;
_back_chunk = _end_chunk;
_back_pos = _end_pos;
if (++end_pos != N)
if (++_end_pos != N)
return;
chunk_t *sc = spare_chunk.xchg (NULL);
chunk_t *sc = _spare_chunk.xchg (NULL);
if (sc) {
end_chunk->next = sc;
sc->prev = end_chunk;
_end_chunk->next = sc;
sc->prev = _end_chunk;
} else {
end_chunk->next = allocate_chunk ();
alloc_assert (end_chunk->next);
end_chunk->next->prev = end_chunk;
_end_chunk->next = allocate_chunk ();
alloc_assert (_end_chunk->next);
_end_chunk->next->prev = _end_chunk;
}
end_chunk = end_chunk->next;
end_pos = 0;
_end_chunk = _end_chunk->next;
_end_pos = 0;
}
// Removes element from the back end of the queue. In other words
@@ -131,40 +131,40 @@ template <typename T, int N> class yqueue_t
inline void unpush ()
{
// First, move 'back' one position backwards.
if (back_pos)
--back_pos;
if (_back_pos)
--_back_pos;
else {
back_pos = N - 1;
back_chunk = back_chunk->prev;
_back_pos = N - 1;
_back_chunk = _back_chunk->prev;
}
// Now, move 'end' position backwards. Note that obsolete end chunk
// is not used as a spare chunk. The analysis shows that doing so
// would require free and atomic operation per chunk deallocated
// instead of a simple free.
if (end_pos)
--end_pos;
if (_end_pos)
--_end_pos;
else {
end_pos = N - 1;
end_chunk = end_chunk->prev;
free (end_chunk->next);
end_chunk->next = NULL;
_end_pos = N - 1;
_end_chunk = _end_chunk->prev;
free (_end_chunk->next);
_end_chunk->next = NULL;
}
}
// Removes an element from the front end of the queue.
inline void pop ()
{
if (++begin_pos == N) {
chunk_t *o = begin_chunk;
begin_chunk = begin_chunk->next;
begin_chunk->prev = NULL;
begin_pos = 0;
if (++_begin_pos == N) {
chunk_t *o = _begin_chunk;
_begin_chunk = _begin_chunk->next;
_begin_chunk->prev = NULL;
_begin_pos = 0;
// 'o' has been more recently used than spare_chunk,
// 'o' has been more recently used than _spare_chunk,
// so for cache reasons we'll get rid of the spare and
// use 'o' as the spare.
chunk_t *cs = spare_chunk.xchg (o);
chunk_t *cs = _spare_chunk.xchg (o);
free (cs);
}
}
@@ -194,17 +194,17 @@ template <typename T, int N> class yqueue_t
// while begin & end positions are always valid. Begin position is
// accessed exclusively be queue reader (front/pop), while back and
// end positions are accessed exclusively by queue writer (back/push).
chunk_t *begin_chunk;
int begin_pos;
chunk_t *back_chunk;
int back_pos;
chunk_t *end_chunk;
int end_pos;
chunk_t *_begin_chunk;
int _begin_pos;
chunk_t *_back_chunk;
int _back_pos;
chunk_t *_end_chunk;
int _end_pos;
// People are likely to produce and consume at similar rates. In
// this scenario holding onto the most recently freed chunk saves
// us from having to call malloc/free.
atomic_ptr_t<chunk_t> spare_chunk;
atomic_ptr_t<chunk_t> _spare_chunk;
// Disable copying of yqueue.
yqueue_t (const yqueue_t &);