]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | ////////////////////////////////////////////////////////////////////////////// |
2 | // | |
3 | // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost | |
4 | // Software License, Version 1.0. (See accompanying file | |
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | // | |
7 | // See http://www.boost.org/libs/interprocess for documentation. | |
8 | // | |
9 | ////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef BOOST_INTERPROCESS_POSIX_NAMED_CONDITION_HPP | |
12 | #define BOOST_INTERPROCESS_POSIX_NAMED_CONDITION_HPP | |
13 | ||
14 | #ifndef BOOST_CONFIG_HPP | |
15 | # include <boost/config.hpp> | |
16 | #endif | |
17 | # | |
18 | #if defined(BOOST_HAS_PRAGMA_ONCE) | |
19 | # pragma once | |
20 | #endif | |
21 | ||
22 | #include <boost/interprocess/detail/config_begin.hpp> | |
23 | #include <boost/interprocess/detail/workaround.hpp> | |
24 | ||
25 | #include <boost/interprocess/sync/posix/semaphore_wrapper.hpp> | |
26 | ||
27 | namespace boost { | |
28 | namespace interprocess { | |
29 | ||
30 | #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) | |
31 | namespace ipcdetail{ class interprocess_tester; } | |
32 | #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED | |
33 | ||
34 | namespace ipcdetail { | |
35 | ||
36 | class posix_named_semaphore | |
37 | { | |
38 | posix_named_semaphore(); | |
39 | posix_named_semaphore(const posix_named_semaphore&); | |
40 | posix_named_semaphore &operator= (const posix_named_semaphore &); | |
41 | ||
42 | public: | |
43 | posix_named_semaphore | |
44 | (create_only_t, const char *name, unsigned int initialCount, const permissions &perm = permissions()) | |
45 | { semaphore_open(mp_sem, DoCreate, name, initialCount, perm); } | |
46 | ||
47 | posix_named_semaphore(open_or_create_t, const char *name, unsigned int initialCount, const permissions &perm = permissions()) | |
48 | { semaphore_open(mp_sem, DoOpenOrCreate, name, initialCount, perm); } | |
49 | ||
50 | posix_named_semaphore(open_only_t, const char *name) | |
51 | { semaphore_open(mp_sem, DoOpen, name); } | |
52 | ||
53 | ~posix_named_semaphore() | |
54 | { | |
55 | if(mp_sem != BOOST_INTERPROCESS_POSIX_SEM_FAILED) | |
56 | semaphore_close(mp_sem); | |
57 | } | |
58 | ||
59 | void post() | |
60 | { semaphore_post(mp_sem); } | |
61 | ||
62 | void wait() | |
63 | { semaphore_wait(mp_sem); } | |
64 | ||
65 | bool try_wait() | |
66 | { return semaphore_try_wait(mp_sem); } | |
67 | ||
68 | bool timed_wait(const boost::posix_time::ptime &abs_time) | |
69 | { return semaphore_timed_wait(mp_sem, abs_time); } | |
70 | ||
71 | static bool remove(const char *name) | |
72 | { return semaphore_unlink(name); } | |
73 | ||
74 | private: | |
75 | friend class ipcdetail::interprocess_tester; | |
76 | void dont_close_on_destruction() | |
77 | { mp_sem = BOOST_INTERPROCESS_POSIX_SEM_FAILED; } | |
78 | ||
79 | sem_t *mp_sem; | |
80 | }; | |
81 | ||
82 | } //namespace ipcdetail { | |
83 | } //namespace interprocess { | |
84 | } //namespace boost { | |
85 | ||
86 | #include <boost/interprocess/detail/config_end.hpp> | |
87 | ||
88 | #endif //#ifndef BOOST_INTERPROCESS_POSIX_NAMED_CONDITION_HPP |