]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
11fdf7f2 TL |
19 | #include "common/ceph_mutex.h" |
20 | ||
7c673cae FG |
21 | class Semaphore |
22 | { | |
11fdf7f2 TL |
23 | ceph::mutex m = ceph::make_mutex("Semaphore::m"); |
24 | ceph::condition_variable c; | |
25 | int count = 0; | |
7c673cae FG |
26 | |
27 | public: | |
28 | ||
7c673cae FG |
29 | void Put() |
30 | { | |
11fdf7f2 | 31 | std::lock_guard l(m); |
7c673cae | 32 | count++; |
11fdf7f2 | 33 | c.notify_all(); |
7c673cae FG |
34 | } |
35 | ||
36 | void Get() | |
11fdf7f2 TL |
37 | { |
38 | std::unique_lock l(m); | |
7c673cae | 39 | while(count <= 0) { |
11fdf7f2 | 40 | c.wait(l); |
7c673cae FG |
41 | } |
42 | count--; | |
7c673cae FG |
43 | } |
44 | }; | |
45 | ||
46 | #endif // !_Mutex_Posix_ |