/usr/include/osl/misc/atomicCounter.h is in libosl-dev 0.8.0-1.4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | /* atomicCounter.h
*/
#ifndef OSL_ATOMICCOUNTER_H
#define OSL_ATOMICCOUNTER_H
#include "osl/config.h"
#include <atomic>
#include <algorithm>
namespace osl
{
namespace misc
{
template <class Counter>
struct IncrementLock
{
Counter& counter;
explicit IncrementLock(Counter& c) : counter(c)
{
counter.inc();
}
~IncrementLock()
{
counter.dec();
}
IncrementLock(const IncrementLock&) = delete;
IncrementLock& operator=(const IncrementLock&) = delete;
};
class AtomicCounter
{
std::atomic<int> count;
public:
explicit AtomicCounter(int count_=0) {
this->count=count_;
}
void inc(){
count.fetch_add(1);
}
void inc(int value){
count.fetch_add(value);
}
int valueAndinc(){
return count.fetch_add(1);
}
void dec(){
count.fetch_sub(1);
}
void max(int val){
int x=count;
if(x<val){
while(! count.compare_exchange_weak(x,val) && x<val)
;
}
}
int value() const{
return count;
}
void setValue(int value) {
count = value;
}
typedef IncrementLock<AtomicCounter> IncLock;
};
}
using misc::AtomicCounter;
}
#endif /* OSL_ATOMICCOUNTER_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
|