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.
 
 
 
 
 
 

65 lines
1.4 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh)
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. #ifndef BOOSTER_REFCOUNTED_H
  10. #define BOOSTER_REFCOUNTED_H
  11. #include <booster/atomic_counter.h>
  12. namespace booster {
  13. class refcounted;
  14. void intrusive_ptr_add_ref(refcounted *ptr);
  15. void intrusive_ptr_release(refcounted *ptr);
  16. ///
  17. /// \brief This class is used as base class for reference counted
  18. /// objects that use intrusive_ptr. Deriving from this class
  19. /// allows simple way to manage reference counting for single object
  20. ///
  21. class refcounted {
  22. public:
  23. refcounted() :
  24. refs_(0)
  25. {
  26. }
  27. virtual ~refcounted()
  28. {
  29. }
  30. private:
  31. friend void intrusive_ptr_add_ref(refcounted *);
  32. friend void intrusive_ptr_release(refcounted *);
  33. refcounted(refcounted const &other);
  34. refcounted const &operator=(refcounted const &other);
  35. atomic_counter refs_;
  36. };
  37. ///
  38. /// Increase reference count
  39. ///
  40. inline void intrusive_ptr_add_ref(refcounted *p)
  41. {
  42. ++p->refs_;
  43. }
  44. ///
  45. /// Decrease reference count, if it goes to 0, destroy the object
  46. ///
  47. inline void intrusive_ptr_release(refcounted *p)
  48. {
  49. if(p && --p->refs_ == 0)
  50. delete p;
  51. }
  52. }
  53. #endif