/usr/include/cppdb/atomic_counter.h is in libcppdb-dev 0.3.1+dfsg-3build1.
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | ///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2010-2011 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// 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)
//
// or (at your opinion) under:
//
// The MIT License
// (See accompanying file MIT.txt or a copy at
// http://www.opensource.org/licenses/mit-license.php)
//
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPDB_ATOMIC_COUNT_H
#define CPPDB_ATOMIC_COUNT_H
#include <cppdb/defs.h>
namespace cppdb {
///
/// \brief Atomic counter is a class that allows perform counting in thread safe way.
///
/// It is mainly used for reference counting. Under Windows it uses Interlocked API, under
/// other platforms it used built-in atomic operations or fails back to pthreads locking implementation.
///
/// Notes:
///
/// - This counter is not safe for use in process shared memory, when pthreads fall-back is used
/// - Under POSIX platform pthread_mutex_t is always present in order to make sure that we can implement
/// or remove pthread fall-back at any point not affecting ABI
///
class CPPDB_API atomic_counter {
public:
///
/// Create a counter with initial value v
///
explicit atomic_counter( long v);
~atomic_counter();
///
/// Increment and return the result after increment atomically
///
long operator++()
{
return inc();
}
///
/// Decrement and return the result after decrement atomically
///
long operator--()
{
return dec();
}
///
/// Return current value - atomically
///
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_;
};
} // cppdb
#endif
|