RCFProto
 All Classes Functions Typedefs
posix_mutex.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2013, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 2.0
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 //
20 // detail/posix_mutex.hpp
21 // ~~~~~~~~~~~~~~~~~~~~~~
22 //
23 // Copyright (c) 2003-2011 Christopher M. Kohlhoff (chris at kohlhoff dot com)
24 //
25 // Distributed under the Boost Software License, Version 1.0. (See accompanying
26 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
27 //
28 
29 #ifndef RCF_DETAIL_POSIX_MUTEX_HPP
30 #define RCF_DETAIL_POSIX_MUTEX_HPP
31 
32 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
33 # pragma once
34 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
35 
36 #if defined(BOOST_HAS_PTHREADS)
37 
38 #include <pthread.h>
39 #include <RCF/thread/scoped_lock.hpp>
40 #include <RCF/thread/push_options.hpp>
41 
42 namespace RCF {
43 namespace detail {
44 
45 class posix_event;
46 
47 class posix_mutex
48  : private noncopyable
49 {
50 public:
51  typedef RCF::detail::scoped_lock<posix_mutex> scoped_lock;
52 
53  // Constructor.
54  RCF_EXPORT posix_mutex();
55 
56  // Destructor.
57  ~posix_mutex()
58  {
59  ::pthread_mutex_destroy(&mutex_); // Ignore EBUSY.
60  }
61 
62  // Lock the mutex.
63  void lock()
64  {
65  (void)::pthread_mutex_lock(&mutex_); // Ignore EINVAL.
66  }
67 
68  // Unlock the mutex.
69  void unlock()
70  {
71  (void)::pthread_mutex_unlock(&mutex_); // Ignore EINVAL.
72  }
73 
74 private:
75  friend class posix_event;
76  ::pthread_mutex_t mutex_;
77 };
78 
79 } // namespace detail
80 } // namespace RCF
81 
82 #include <RCF/thread/pop_options.hpp>
83 
84 #endif // defined(BOOST_HAS_PTHREADS)
85 
86 #endif // RCF_DETAIL_POSIX_MUTEX_HPP