]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/Semaphore.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / common / Semaphore.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15
16 #ifndef CEPH_Sem_Posix__H
17 #define CEPH_Sem_Posix__H
18
19 #include "common/ceph_mutex.h"
20
21 class Semaphore
22 {
23 ceph::mutex m = ceph::make_mutex("Semaphore::m");
24 ceph::condition_variable c;
25 int count = 0;
26
27 public:
28
29 void Put()
30 {
31 std::lock_guard l(m);
32 count++;
33 c.notify_all();
34 }
35
36 void Get()
37 {
38 std::unique_lock l(m);
39 while(count <= 0) {
40 c.wait(l);
41 }
42 count--;
43 }
44 };
45
46 #endif // !_Mutex_Posix_