ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
threadmap.hpp
Go to the documentation of this file.
1/** ************************************************************************************************
2 * \file
3 * This header file is part of module \alib_threads of the \aliblong.
4 *
5 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
6 * Published under \ref mainpage_license "Boost Software License".
7 **************************************************************************************************/
8#ifndef HPP_ALIB_THREADS_DETAIL_THREADMAP
9#define HPP_ALIB_THREADS_DETAIL_THREADMAP 1
10
11#if !defined(HPP_ALIB_THREADS_THREAD)
13#endif
14
15#if !defined (_GLIBCXX_MUTEX) && !defined(_MUTEX_)
16# include <mutex>
17#endif
18
19#if ALIB_MONOMEM
20# if !defined(HPP_ALIB_MONOMEM_HASHMAP)
22# endif
23#else
24# if !defined(_GLIBCXX_UNORDERED_MAP) && !defined(_UNORDERED_MAP_)
25# include <unordered_map>
26# endif
27#endif
28
29
30
31namespace alib { namespace threads { namespace detail {
32
33#if ALIB_MONOMEM
34
35 /**
36 * The hash map used to find the current thread object.
37 * The object uses default values for \alib{monomem;HashTable::BaseLoadFactor} and
38 * \alib{monomem;HashTable::MaxLoadFactor}. Depending on the use of threads by a
39 * using application, these values might be modified \e prior to starting the first phase of
40 * \ref alib_manual_bootstrapping "bootstrapping ALib".
41 *
42 * If so, an initial call to \alib{monomem;HashTable::Reserve} may be likewise be performed.
43 *
44 * \note
45 * With the absence of module \alib_monomem in the \alibdist, the type of this object
46 * is <c>std::unordered_map</c>.
47 */
48 extern ALIB_API HashMap <std::thread::id, Thread*> threadMap;
49
50#else
51 extern ALIB_API std::unordered_map<std::thread::id, Thread*> threadMap;
52#endif
53
54#if !ALIB_MONOMEM || defined(ALIB_DOX)
55/**
56 * The internal mutex used with operations like starting, ending or finding thread objects.
57 *
58 * \note
59 * With the presence of module \alib_monomem in the \alibdist, this object is not available.
60 * Instead, \alib{monomem;GlobalAllocatorLock} is used, because this likewise protects
61 * modifications on object \alib{threads;detail::threadMap}, which uses this allocator.
62 */
63extern ALIB_API std::mutex moduleLock;
64#endif
65
66
67/**
68 * Retrieves the \alib object associated with the given C++ <c>std::thread::id</c>.
69 * In case the threadID is not found in the hash table, the given id is considered a system
70 * thread and is entered into the hash table.
71 *
72 * @param c11ID The native thread id.
73 * @return The associated \alib thread object.
74 */
75ALIB_API Thread* getThread(std::thread::id c11ID );
76
77/**
78 * Internal method to start a thread.
79 * @param thread The \alib thread object to start.
80 */
81void threadStart( Thread* thread );
82
83}}} // namespace [alib::threads::detail]
84
85#endif // HPP_ALIB_THREADS_DETAIL_THREADMAP
#define ALIB_API
Definition alib.hpp:538
ALIB_API HashMap< std::thread::id, Thread * > threadMap
ALIB_API std::mutex moduleLock
void threadStart(Thread *thread)
Definition thread.cpp:89
ALIB_API Thread * getThread(std::thread::id c11ID)
Definition thread.cpp:96
Definition alib.cpp:57