atomic_counter.h
//
// Copyright (C) 2009-2012 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOSTER_ATOMIC_COUNT_H
#define BOOSTER_ATOMIC_COUNT_H
#include <booster/config.h>
namespace booster {
class BOOSTER_API atomic_counter {
public:
explicit atomic_counter( long v );
~atomic_counter();
long operator++()
{
return inc();
}
long operator--()
{
return dec();
}
operator long() const
{
return get();
}
private:
long inc();
long dec();
long get() const;
atomic_counter(atomic_counter const &);
atomic_counter & operator=(atomic_counter const &);
mutable union {
int i;
unsigned ui;
long l;
unsigned long ul;
long long ll;
unsigned long long ull;
} value_;
// Is actually used for platforms without lock
// it would not be used when atomic operations
// available
void *mutex_;
};
} // booster
#endif
booster::atomic_counter::operator++
long operator++()
Definition: atomic_counter.h:44
booster::atomic_counter::operator--
long operator--()
Definition: atomic_counter.h:51
booster::atomic_counter
Atomic counter is a class that allows perform counting in thread safe way.
Definition: atomic_counter.h:33