tls.h
Go to the documentation of this file.
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef _TBB_tls_H
#define _TBB_tls_H
#if USE_PTHREAD
#include <pthread.h>
#else /* assume USE_WINTHREAD */
#include "tbb/machine/windows_api.h"
#endif
namespace tbb {
namespace internal {
typedef void (*tls_dtor_t)(void*);
template <typename T>
class basic_tls {
#if USE_PTHREAD
typedef pthread_key_t tls_key_t;
public:
int create( tls_dtor_t dtor = NULL ) {
return pthread_key_create(&my_key, dtor);
}
int destroy() { return pthread_key_delete(my_key); }
void set( T value ) { pthread_setspecific(my_key, (void*)value); }
T get() { return (T)pthread_getspecific(my_key); }
#else /* USE_WINTHREAD */
typedef DWORD tls_key_t;
public:
#if !__TBB_WIN8UI_SUPPORT
int create() {
tls_key_t tmp = TlsAlloc();
if( tmp==TLS_OUT_OF_INDEXES )
return TLS_OUT_OF_INDEXES;
my_key = tmp;
return 0;
}
int destroy() { TlsFree(my_key); my_key=0; return 0; }
void set( T value ) { TlsSetValue(my_key, (LPVOID)value); }
T get() { return (T)TlsGetValue(my_key); }
#else
int create() {
tls_key_t tmp = FlsAlloc(NULL);
if( tmp== (DWORD)0xFFFFFFFF )
return (DWORD)0xFFFFFFFF;
my_key = tmp;
return 0;
}
int destroy() { FlsFree(my_key); my_key=0; return 0; }
void set( T value ) { FlsSetValue(my_key, (LPVOID)value); }
T get() { return (T)FlsGetValue(my_key); }
#endif /* !__TBB_WIN8UI_SUPPORT */
#endif /* USE_WINTHREAD */
private:
tls_key_t my_key;
};
template <typename T>
class tls : public basic_tls<T> {
typedef basic_tls<T> base;
public:
tls() { base::create(); }
~tls() { base::destroy(); }
T operator=(T value) { base::set(value); return value; }
operator T() { return base::get(); }
};
template <typename T>
class tls<T*> : basic_tls<T*> {
typedef basic_tls<T*> base;
static void internal_dtor(void* ptr) {
if (ptr) delete (T*)ptr;
}
T* internal_get() {
T* result = base::get();
if (!result) {
result = new T;
base::set(result);
}
return result;
}
public:
tls() {
#if USE_PTHREAD
base::create( internal_dtor );
#else
base::create();
#endif
}
~tls() { base::destroy(); }
T* operator=(T* value) { base::set(value); return value; }
operator T*() { return internal_get(); }
T* operator->() { return internal_get(); }
T& operator*() { return *internal_get(); }
};
} // namespace internal
} // namespace tbb
#endif /* _TBB_tls_H */
windows_api.h
void
void
Definition: ittnotify_static.h:91
value
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
Definition: ittnotify_static.h:192
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
tbb::internal::tls_dtor_t
void(* tls_dtor_t)(void *)
Definition: tls.h:30
internal
Definition: _flow_graph_async_msg_impl.h:24
tbb::internal::basic_tls
Basic cross-platform wrapper class for TLS operations.
Definition: tls.h:34
tbb::internal::basic_tls::tls_key_t
DWORD tls_key_t
Definition: tls.h:45
tbb::internal::basic_tls::set
void set(T value)
Definition: tls.h:56
tbb::internal::basic_tls::get
T get()
Definition: tls.h:57
tbb::internal::basic_tls::my_key
tls_key_t my_key
Definition: tls.h:72
tbb::internal::basic_tls::destroy
int destroy()
Definition: tls.h:55
tbb::internal::basic_tls::create
int create()
Definition: tls.h:48
tbb::internal::tls
More advanced TLS support template class.
Definition: tls.h:78
tbb::internal::tls::tls
tls()
Definition: tls.h:81
tbb::internal::tls::~tls
~tls()
Definition: tls.h:82
tbb::internal::tls::operator=
T operator=(T value)
Definition: tls.h:83
tbb::internal::tls::base
basic_tls< T > base
Definition: tls.h:79
tbb::internal::tls< T * >::base
basic_tls< T * > base
Definition: tls.h:89
tbb::internal::tls< T * >::tls
tls()
Definition: tls.h:102
tbb::internal::tls< T * >::operator->
T * operator->()
Definition: tls.h:112
tbb::internal::tls< T * >::internal_dtor
static void internal_dtor(void *ptr)
Definition: tls.h:90
tbb::internal::tls< T * >::operator*
T & operator*()
Definition: tls.h:113
tbb::internal::tls< T * >::operator=
T * operator=(T *value)
Definition: tls.h:110
tbb::internal::tls< T * >::~tls
~tls()
Definition: tls.h:109
tbb::internal::tls< T * >::internal_get
T * internal_get()
Definition: tls.h:93

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.