Realistic 3D camera system
3D camera system components
posix_tss_ptr.hpp
Go to the documentation of this file.
1 //
2 // detail/posix_tss_ptr.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 #ifndef ASIO_DETAIL_POSIX_TSS_PTR_HPP
12 #define ASIO_DETAIL_POSIX_TSS_PTR_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 
20 #if defined(ASIO_HAS_PTHREADS)
21 
22 #include <pthread.h>
24 
26 
27 namespace asio {
28 namespace detail {
29 
30 // Helper function to create thread-specific storage.
31 ASIO_DECL void posix_tss_ptr_create(pthread_key_t& key);
32 
33 template <typename T>
34 class posix_tss_ptr
35  : private noncopyable
36 {
37 public:
38  // Constructor.
39  posix_tss_ptr()
40  {
41  posix_tss_ptr_create(tss_key_);
42  }
43 
44  // Destructor.
45  ~posix_tss_ptr()
46  {
47  ::pthread_key_delete(tss_key_);
48  }
49 
50  // Get the value.
51  operator T*() const
52  {
53  return static_cast<T*>(::pthread_getspecific(tss_key_));
54  }
55 
56  // Set the value.
57  void operator=(T* value)
58  {
59  ::pthread_setspecific(tss_key_, value);
60  }
61 
62 private:
63  // Thread-specific storage to allow unlocked access to determine whether a
64  // thread is a member of the pool.
65  pthread_key_t tss_key_;
66 };
67 
68 } // namespace detail
69 } // namespace asio
70 
72 
73 #if defined(ASIO_HEADER_ONLY)
75 #endif // defined(ASIO_HEADER_ONLY)
76 
77 #endif // defined(ASIO_HAS_PTHREADS)
78 
79 #endif // ASIO_DETAIL_POSIX_TSS_PTR_HPP
#define ASIO_DECL
Definition: config.hpp:43