Mutex.h 507 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef ML_MUTEX_H
  2. #define ML_MUTEX_H
  3. #include "ml-private.h"
  4. class Mutex {
  5. public:
  6. Mutex() {
  7. netdata_mutex_init(&M);
  8. }
  9. void lock() {
  10. netdata_mutex_lock(&M);
  11. }
  12. void unlock() {
  13. netdata_mutex_unlock(&M);
  14. }
  15. bool try_lock() {
  16. return netdata_mutex_trylock(&M) == 0;
  17. }
  18. netdata_mutex_t *inner() {
  19. return &M;
  20. }
  21. ~Mutex() {
  22. netdata_mutex_destroy(&M);
  23. }
  24. private:
  25. netdata_mutex_t M;
  26. };
  27. #endif /* ML_MUTEX_H */