ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

89 lines
2.0 KiB

  1. //
  2. // Copyright (C) 2009-2012 Artyom Beilis (Tonkikh)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. #ifndef BOOSTER_ATOMIC_COUNT_H
  9. #define BOOSTER_ATOMIC_COUNT_H
  10. #include <booster/config.h>
  11. ///
  12. /// \brief Booster library namespace. The library that implements Boost Like API
  13. /// in ABI backward compatible way
  14. ///
  15. namespace booster {
  16. ///
  17. /// \brief Atomic counter is a class that allows perform counting in thread safe way.
  18. ///
  19. /// It is mainly used for reference counting. Under Windows it uses Interlocked API, under
  20. /// other platforms it used built-in atomic operations or fails back to pthreads locking implementation.
  21. ///
  22. /// Notes:
  23. ///
  24. /// - This counter is not safe for use in process shared memory, when pthreads fall-back is used
  25. /// - Under POSIX platform pthread_mutex_t is always present in order to make sure that we can implement
  26. /// or remove pthread fall-back at any point not affecting ABI
  27. ///
  28. class BOOSTER_API atomic_counter {
  29. public:
  30. ///
  31. /// Create a counter with initial value v
  32. ///
  33. explicit atomic_counter( long v );
  34. ~atomic_counter();
  35. ///
  36. /// Increment and return the result after increment atomically
  37. ///
  38. long operator++()
  39. {
  40. return inc();
  41. }
  42. ///
  43. /// Decrement and return the result after decrement atomically
  44. ///
  45. long operator--()
  46. {
  47. return dec();
  48. }
  49. ///
  50. /// Return current value - atomically
  51. ///
  52. operator long() const
  53. {
  54. return get();
  55. }
  56. private:
  57. long inc();
  58. long dec();
  59. long get() const;
  60. atomic_counter(atomic_counter const &);
  61. atomic_counter & operator=(atomic_counter const &);
  62. mutable union {
  63. int i;
  64. unsigned ui;
  65. long l;
  66. unsigned long ul;
  67. long long ll;
  68. unsigned long long ull;
  69. } value_;
  70. // Is actually used for platforms without lock
  71. // it would not be used when atomic operations
  72. // available
  73. void *mutex_;
  74. };
  75. } // booster
  76. #endif