OpenWalnut
1.5.0dev
|
This is a simple but thread-safe counter. More...
#include <WCounter.h>
Public Member Functions | |
WCounter () | |
Constructor. More... | |
int | operator++ () |
Increase count by 1 and return the new counter value. More... | |
int | operator-- () |
Decrease count by 1 and return the new counter value. More... | |
int | operator() () const |
Get current count. More... | |
int | reset () |
Reset the counter to 0. More... | |
Private Member Functions | |
WCounter (WCounter &) | |
No copy construction. More... | |
WCounter | operator= (WCounter &) |
No copy operator. More... | |
Private Attributes | |
std::shared_mutex | m_counterMutex |
A mutex to protect the counter from concurrent updates. More... | |
int | m_counter |
The counter. More... | |
This is a simple but thread-safe counter.
Use it to handle counting between multiple threads. When used as static member, you can utilized WCounter for instance counting.
Definition at line 36 of file WCounter.h.
|
inline |
|
private |
No copy construction.
|
inline |
Get current count.
Definition at line 75 of file WCounter.h.
References m_counter, and m_counterMutex.
|
inline |
Increase count by 1 and return the new counter value.
This is threadsafe.
Definition at line 53 of file WCounter.h.
References m_counter, and m_counterMutex.
|
inline |
Decrease count by 1 and return the new counter value.
This is threadsafe.
Definition at line 64 of file WCounter.h.
References m_counter, and m_counterMutex.
|
inline |
Reset the counter to 0.
Definition at line 86 of file WCounter.h.
References m_counter, and m_counterMutex.
|
private |
The counter.
Definition at line 109 of file WCounter.h.
Referenced by operator()(), operator++(), operator--(), and reset().
|
mutableprivate |
A mutex to protect the counter from concurrent updates.
Definition at line 106 of file WCounter.h.
Referenced by operator()(), operator++(), operator--(), and reset().