]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/immutable_object_cache/test_common.h
Import ceph 15.2.8
[ceph.git] / ceph / src / test / immutable_object_cache / test_common.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #ifndef CACHE_TEST_COMMON_H
4 #define CACHE_TEST_COMMON_H
5
6 #include <pthread.h>
7
8 class WaitEvent {
9 public:
10 WaitEvent() : m_signaled(false) {
11 pthread_mutex_init(&m_lock, NULL);
12 pthread_cond_init(&m_cond, NULL);
13 }
14
15 ~WaitEvent() {
16 pthread_mutex_destroy(&m_lock);
17 pthread_cond_destroy(&m_cond);
18 }
19
20 void wait() {
21 pthread_mutex_lock(&m_lock);
22 while (!m_signaled) {
23 pthread_cond_wait(&m_cond, &m_lock);
24 }
25 m_signaled = false;
26 pthread_mutex_unlock(&m_lock);
27 }
28
29 void signal() {
30 pthread_mutex_lock(&m_lock);
31 m_signaled = true;
32 pthread_cond_signal(&m_cond);
33 pthread_mutex_unlock(&m_lock);
34 }
35 private:
36 pthread_mutex_t m_lock;
37 pthread_cond_t m_cond;
38 bool m_signaled;
39 };
40
41 #endif