Realistic 3D camera system
3D camera system components
win_tss_ptr.hpp
Go to the documentation of this file.
1 //
2 // detail/win_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_WIN_TSS_PTR_HPP
12 #define ASIO_DETAIL_WIN_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_WINDOWS)
21 
24 
26 
27 namespace asio {
28 namespace detail {
29 
30 // Helper function to create thread-specific storage.
31 ASIO_DECL DWORD win_tss_ptr_create();
32 
33 template <typename T>
34 class win_tss_ptr
35  : private noncopyable
36 {
37 public:
38  // Constructor.
39  win_tss_ptr()
40  : tss_key_(win_tss_ptr_create())
41  {
42  }
43 
44  // Destructor.
45  ~win_tss_ptr()
46  {
47  ::TlsFree(tss_key_);
48  }
49 
50  // Get the value.
51  operator T*() const
52  {
53  return static_cast<T*>(::TlsGetValue(tss_key_));
54  }
55 
56  // Set the value.
57  void operator=(T* value)
58  {
59  ::TlsSetValue(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  DWORD 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_WINDOWS)
78 
79 #endif // ASIO_DETAIL_WIN_TSS_PTR_HPP
#define ASIO_DECL
Definition: config.hpp:43