~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to include/libtorrent/asio/detail/win_tss_ptr.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2010-08-10 12:59:37 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810125937-jbcmmf17y8yo9hgz
Tags: 0.15.0-0ubuntu1
* New upstream version.
* debian/patches/100_fix_html_docs.patch: refreshed.
* debian/control: bump up standards-version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// win_tss_ptr.hpp
3
 
// ~~~~~~~~~~~~~~~
4
 
//
5
 
// Copyright (c) 2003-2008 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/push_options.hpp"
19
 
 
20
 
#include "asio/detail/push_options.hpp"
21
 
#include <boost/config.hpp>
22
 
#include "asio/detail/pop_options.hpp"
23
 
 
24
 
#if defined(BOOST_WINDOWS)
25
 
 
26
 
#include "asio/error.hpp"
27
 
#include "asio/system_error.hpp"
28
 
#include "asio/detail/noncopyable.hpp"
29
 
#include "asio/detail/socket_types.hpp"
30
 
 
31
 
#include "asio/detail/push_options.hpp"
32
 
#include <boost/throw_exception.hpp>
33
 
#include "asio/detail/pop_options.hpp"
34
 
 
35
 
namespace asio {
36
 
namespace detail {
37
 
 
38
 
template <typename T>
39
 
class win_tss_ptr
40
 
  : private noncopyable
41
 
{
42
 
public:
43
 
#if defined(UNDER_CE)
44
 
  enum { out_of_indexes = 0xFFFFFFFF };
45
 
#else
46
 
  enum { out_of_indexes = TLS_OUT_OF_INDEXES };
47
 
#endif
48
 
 
49
 
  // Constructor.
50
 
  win_tss_ptr()
51
 
  {
52
 
    tss_key_ = ::TlsAlloc();
53
 
    if (tss_key_ == out_of_indexes)
54
 
    {
55
 
      DWORD last_error = ::GetLastError();
56
 
      asio::system_error e(
57
 
          asio::error_code(last_error,
58
 
            asio::error::get_system_category()),
59
 
          "tss");
60
 
      boost::throw_exception(e);
61
 
    }
62
 
  }
63
 
 
64
 
  // Destructor.
65
 
  ~win_tss_ptr()
66
 
  {
67
 
    ::TlsFree(tss_key_);
68
 
  }
69
 
 
70
 
  // Get the value.
71
 
  operator T*() const
72
 
  {
73
 
    return static_cast<T*>(::TlsGetValue(tss_key_));
74
 
  }
75
 
 
76
 
  // Set the value.
77
 
  void operator=(T* value)
78
 
  {
79
 
    ::TlsSetValue(tss_key_, value);
80
 
  }
81
 
 
82
 
private:
83
 
  // Thread-specific storage to allow unlocked access to determine whether a
84
 
  // thread is a member of the pool.
85
 
  DWORD tss_key_;
86
 
};
87
 
 
88
 
} // namespace detail
89
 
} // namespace asio
90
 
 
91
 
#endif // defined(BOOST_WINDOWS)
92
 
 
93
 
#include "asio/detail/pop_options.hpp"
94
 
 
95
 
#endif // ASIO_DETAIL_WIN_TSS_PTR_HPP