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.
 
 
 
 
 
 

46 lines
735 B

  1. #ifndef CPPCMS_REFCOUNTED_H
  2. #define CPPCMS_REFCOUNTED_H
  3. #include "atomic_counter.h"
  4. namespace cppcms {
  5. class refcounted;
  6. void intrusive_ptr_add_ref(refcounted *ptr);
  7. void intrusive_ptr_release(refcounted *ptr);
  8. class refcounted {
  9. public:
  10. refcounted() :
  11. refs_(0)
  12. {
  13. }
  14. virtual ~refcounted()
  15. {
  16. }
  17. private:
  18. friend void intrusive_ptr_add_ref(refcounted *);
  19. friend void intrusive_ptr_release(refcounted *);
  20. refcounted(refcounted const &other);
  21. refcounted const &operator=(refcounted const &other);
  22. atomic_counter refs_;
  23. };
  24. inline void intrusive_ptr_add_ref(refcounted *p)
  25. {
  26. ++p->refs_;
  27. }
  28. inline void intrusive_ptr_release(refcounted *p)
  29. {
  30. if(p && --p->refs_ == 0)
  31. delete p;
  32. }
  33. }
  34. #endif