summaryrefslogtreecommitdiffstats
path: root/ext/asio/detail/posix_mutex.hpp
diff options
context:
space:
mode:
authorEvan Hunt <each@isc.org>2010-05-20 03:26:23 +0200
committerEvan Hunt <each@isc.org>2010-05-20 03:26:23 +0200
commit4f5ca8bd9ccf7c9a92e3e5b95336cbcb11dfb56c (patch)
tree30e2bfbfec81e887134b2fd91a6d98964c49af53 /ext/asio/detail/posix_mutex.hpp
parentshort-lived branch for trac #168: use asio instead of boost::asio. (diff)
downloadkea-4f5ca8bd9ccf7c9a92e3e5b95336cbcb11dfb56c.tar.xz
kea-4f5ca8bd9ccf7c9a92e3e5b95336cbcb11dfb56c.zip
- added ASIO library header files (version 1.4.5, downloaded from
http://sourceforge.net/projects/asio/files, project page http://think-async.com/Asio). - removed uses of boost::asio - removed custom TCP/UDP code git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac168@1864 e5f2f494-b856-4b98-b285-d166d9295462
Diffstat (limited to 'ext/asio/detail/posix_mutex.hpp')
-rw-r--r--ext/asio/detail/posix_mutex.hpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/ext/asio/detail/posix_mutex.hpp b/ext/asio/detail/posix_mutex.hpp
new file mode 100644
index 0000000000..230b83a356
--- /dev/null
+++ b/ext/asio/detail/posix_mutex.hpp
@@ -0,0 +1,91 @@
+//
+// posix_mutex.hpp
+// ~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef ASIO_DETAIL_POSIX_MUTEX_HPP
+#define ASIO_DETAIL_POSIX_MUTEX_HPP
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
+
+#include "asio/detail/push_options.hpp"
+
+#include "asio/detail/push_options.hpp"
+#include <boost/config.hpp>
+#include "asio/detail/pop_options.hpp"
+
+#if defined(BOOST_HAS_PTHREADS)
+
+#include "asio/detail/push_options.hpp"
+#include <boost/throw_exception.hpp>
+#include <pthread.h>
+#include "asio/detail/pop_options.hpp"
+
+#include "asio/error.hpp"
+#include "asio/system_error.hpp"
+#include "asio/detail/noncopyable.hpp"
+#include "asio/detail/scoped_lock.hpp"
+
+namespace asio {
+namespace detail {
+
+class posix_event;
+
+class posix_mutex
+ : private noncopyable
+{
+public:
+ typedef asio::detail::scoped_lock<posix_mutex> scoped_lock;
+
+ // Constructor.
+ posix_mutex()
+ {
+ int error = ::pthread_mutex_init(&mutex_, 0);
+ if (error != 0)
+ {
+ asio::system_error e(
+ asio::error_code(error,
+ asio::error::get_system_category()),
+ "mutex");
+ boost::throw_exception(e);
+ }
+ }
+
+ // Destructor.
+ ~posix_mutex()
+ {
+ ::pthread_mutex_destroy(&mutex_); // Ignore EBUSY.
+ }
+
+ // Lock the mutex.
+ void lock()
+ {
+ (void)::pthread_mutex_lock(&mutex_); // Ignore EINVAL.
+ }
+
+ // Unlock the mutex.
+ void unlock()
+ {
+ (void)::pthread_mutex_unlock(&mutex_); // Ignore EINVAL.
+ }
+
+private:
+ friend class posix_event;
+ ::pthread_mutex_t mutex_;
+};
+
+} // namespace detail
+} // namespace asio
+
+#endif // defined(BOOST_HAS_PTHREADS)
+
+#include "asio/detail/pop_options.hpp"
+
+#endif // ASIO_DETAIL_POSIX_MUTEX_HPP