/usr/include/osl/misc/atomicCounter.h is in libosl-dev 0.6.0-3.
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112  | /* atomicCounter.h
 */
#ifndef OSL_ATOMICCOUNTER_H
#define OSL_ATOMICCOUNTER_H
#include "osl/config.h"
#ifdef USE_TBB_ATOMIC
#  include <tbb/atomic.h>
#else
#  include "osl/misc/lightMutex.h"
#endif
#include <algorithm>
namespace osl
{
  namespace misc
  {
    template <class Counter>
    struct IncrementLock
    {
      Counter& counter;
      explicit IncrementLock(Counter& c) : counter(c) 
      {
	counter.inc();
      }
      ~IncrementLock() 
      {
	counter.dec();
      }
    };
#ifdef USE_TBB_ATOMIC
    class AtomicCounter
    {
      tbb::atomic<int> count;
    public:
      explicit AtomicCounter(int count_=0) {
	this->count=count_;
      }
      void inc(){
	count.fetch_and_increment();
      }
      void inc(int value){
	count.fetch_and_add(value);
      }
      int valueAndinc(){
	return count.fetch_and_increment();
      }
      void dec(){
	count.fetch_and_decrement();
      }
      void max(int val){
	int x=count;
	if(x<val){
	  int oldx;
	  while((oldx=count.compare_and_swap(val,x))!=x){
	    x=oldx;
	    if(x>=val) break;
	  }
	}
      }
      int value() const{ 
	return count; 
      }
      void setValue(int value) { 
	count = value; 
      }
      typedef IncrementLock<AtomicCounter> IncLock;
    };
#else
    class AtomicCounter
    {
      typedef LightMutex Mutex;
      mutable Mutex m;
      int count;
    public:
      explicit AtomicCounter(int count=0) :count(count){}
      void inc(){
	SCOPED_LOCK(lk,m);
	count++;
      }
      int valueAndinc(){
	SCOPED_LOCK(lk,m);
	return count++;
      }
      void dec(){
	SCOPED_LOCK(lk,m);
	count--;
      }
      void max(int val){
	SCOPED_LOCK(lk,m);
	count=std::max(count,val);
      }
      int value() const{ 
	SCOPED_LOCK(lk,m);
	return count; 
      }
      void setValue(int value) { 
	SCOPED_LOCK(lk,m);
	count = value; 
      }
      typedef IncrementLock<AtomicCounter> IncLock;
    };
#endif
  }
  using misc::AtomicCounter;
}
#endif /* OSL_ATOMICCOUNTER_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
 |