semaphore_wrapper.h 768 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*!
 *  Copyright (c) 2021 by Contributors
 * \file semaphore_wrapper.h
 * \brief A simple corss platform semaphore wrapper
 */
#ifndef DGL_RUNTIME_SEMAPHORE_WRAPPER_H_
#define DGL_RUNTIME_SEMAPHORE_WRAPPER_H_

#ifdef _WIN32
#include <windows.h>
#else
#include <semaphore.h>
#endif


namespace dgl {
namespace runtime {

/*!
 * \brief A simple crossplatform Semaphore wrapper
 */
class Semaphore {
 public:
  /*!
   * \brief Semaphore constructor
   */
  Semaphore();
  /*!
   * \brief blocking wait, decrease semaphore by 1
   */
  void Wait();
  /*!
   * \brief increase semaphore by 1
   */
  void Post();
 private:
#ifdef _WIN32
  HANDLE sem_;
#else
  sem_t sem_;
#endif
};

}  // namespace runtime
}  // namespace dgl

#endif  // DGL_RUNTIME_SEMAPHORE_WRAPPER_H_