00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00047 #ifndef WINSTL_INCL_WINSTL_SYNCH_HPP_TSS_INDEX
00048 #define WINSTL_INCL_WINSTL_SYNCH_HPP_TSS_INDEX
00049
00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define WINSTL_VER_WINSTL_SYNCH_HPP_TSS_INDEX_MAJOR 4
00052 # define WINSTL_VER_WINSTL_SYNCH_HPP_TSS_INDEX_MINOR 0
00053 # define WINSTL_VER_WINSTL_SYNCH_HPP_TSS_INDEX_REVISION 4
00054 # define WINSTL_VER_WINSTL_SYNCH_HPP_TSS_INDEX_EDIT 37
00055 #endif
00056
00057
00058
00059
00060
00061 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00062 # include <winstl/winstl.h>
00063 #endif
00064 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00065 # ifndef WINSTL_INCL_WINSTL_SYNCH_ERROR_HPP_EXCEPTIONS
00066 # include <winstl/synch/error/exceptions.hpp>
00067 # endif
00068 #endif
00069
00070
00071
00072
00073
00074 #ifndef _WINSTL_NO_NAMESPACE
00075 # if defined(_STLSOFT_NO_NAMESPACE) || \
00076 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00077
00078 namespace winstl
00079 {
00080 # else
00081
00082
00083 namespace stlsoft
00084 {
00085
00086 namespace winstl_project
00087 {
00088
00089 # endif
00090 #endif
00091
00092
00093
00094
00095
00096 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00097
00103 class tss_exception
00104 : public synchronisation_exception
00105 {
00108 public:
00109 typedef synchronisation_exception parent_class_type;
00110 typedef tss_exception class_type;
00111 typedef parent_class_type::error_code_type error_code_type;
00113
00116 public:
00117 ss_explicit_k tss_exception(error_code_type err)
00118 : parent_class_type("", err)
00119 {}
00121
00124 public:
00125 virtual char const* what() const stlsoft_throw_0()
00126 {
00127 return "Failed to allocate a TSS key";
00128 }
00130
00133 private:
00134 class_type& operator =(class_type const&);
00136 };
00137 #endif
00138
00139
00144 class tss_index
00145 {
00148 public:
00150 typedef tss_index class_type;
00152 typedef ws_dword_t key_type;
00156 typedef key_type index_type;
00158 typedef void* value_type;
00160
00163 public:
00165 ss_explicit_k tss_index()
00166 : m_index(index_create_())
00167 {}
00169 ~tss_index() stlsoft_throw_0()
00170 {
00171 index_destroy_(m_index);
00172 }
00174
00177 public:
00179 void set_value(value_type value)
00180 {
00181 class_type::set_slot_value_(m_index, value);
00182 }
00184 value_type get_value() const
00185 {
00186 return class_type::get_slot_value_(m_index);
00187 }
00189
00192 public:
00194 operator key_type () const
00195 {
00196 return m_index;
00197 }
00199
00202 private:
00203 static key_type index_create_()
00204 {
00205 key_type key = ::TlsAlloc();
00206
00207 if(0xFFFFFFFF == key)
00208 {
00209 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00210 STLSOFT_THROW_X(tss_exception(::GetLastError()));
00211 #else
00212 ::OutputDebugStringA("Fatal: Could not allocate a TSS key!\n");
00213 ::RaiseException(STATUS_NO_MEMORY, EXCEPTION_NONCONTINUABLE, 0, 0);
00214 #endif
00215 }
00216
00217 return key;
00218 }
00219
00220 static void index_destroy_(key_type key)
00221 {
00222 ::TlsFree(key);
00223 }
00224
00225 static void set_slot_value_(key_type key, value_type value)
00226 {
00227 ::TlsSetValue(key, value);
00228 }
00229
00230 static value_type get_slot_value_(key_type key)
00231 {
00232 return ::TlsGetValue(key);
00233 }
00235
00238 private:
00239 key_type m_index;
00241
00244 private:
00245 tss_index(class_type const&);
00246 class_type& operator =(class_type const&);
00248 };
00249
00250
00251
00252 #ifndef _WINSTL_NO_NAMESPACE
00253 # if defined(_STLSOFT_NO_NAMESPACE) || \
00254 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00255 }
00256 # else
00257 }
00258 }
00259 # endif
00260 #endif
00261
00262
00263
00264 #endif
00265
00266