interprocess_sync.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef __INTERPROCESS_SYNC_H__
  15. #define __INTERPROCESS_SYNC_H__
  16. #include <string>
  17. namespace isc {
  18. namespace util {
  19. class InterprocessSyncLocker;
  20. class InterprocessSync {
  21. public:
  22. /// \brief Constructor
  23. ///
  24. /// Creates a interprocess synchronization object
  25. InterprocessSync(const std::string component_name) :
  26. component_name_(component_name)
  27. {}
  28. /// \brief Destructor
  29. virtual ~InterprocessSync() {}
  30. virtual InterprocessSyncLocker* getLocker() = 0;
  31. protected:
  32. std::string component_name_;
  33. };
  34. class InterprocessSyncLocker {
  35. friend class InterprocessSync;
  36. public:
  37. virtual bool lock() = 0;
  38. virtual bool tryLock() = 0;
  39. virtual bool unlock() = 0;
  40. /// \brief Destructor
  41. virtual ~InterprocessSyncLocker() {}
  42. protected:
  43. InterprocessSyncLocker(InterprocessSync* sync) :
  44. sync_(sync), is_locked_(false)
  45. {}
  46. InterprocessSync* sync_;
  47. bool is_locked_;
  48. };
  49. } // namespace util
  50. } // namespace isc
  51. #endif // __INTERPROCESS_SYNC_H__