![]() |
Bitcoin Core 30.99.0
P2P Digital Currency
|
The thread_local ThreadContext g_thread_context struct provides information about individual threads and a way of communicating between them. More...
#include <proxy-io.h>
Public Member Functions | |
ConnThreads callback_threads | MP_GUARDED_BY (waiter->m_mutex) |
When client is making a request to a server, this is the callbackThread argument it passes in the request, used by the server in case it needs to make callbacks into the client that need to execute while the client is waiting. More... | |
ConnThreads request_threads | MP_GUARDED_BY (waiter->m_mutex) |
When client is making a request to a server, this is the thread argument it passes in the request, used to control which thread on server will be responsible for executing it. More... | |
Public Attributes | |
std::string | thread_name |
Identifying string for debug. More... | |
std::unique_ptr< Waiter > | waiter = nullptr |
Waiter object used to allow remote clients to execute code on this thread. More... | |
bool | loop_thread = false |
Whether this thread is a capnp event loop thread. More... | |
The thread_local ThreadContext g_thread_context struct provides information about individual threads and a way of communicating between them.
Because it's a thread local struct, each ThreadContext instance is initialized by the thread that owns it.
ThreadContext is used for any client threads created externally which make IPC calls, and for server threads created by ProxyServer<ThreadMap>::makeThread() which execute IPC calls for clients.
In both cases, the struct holds information like the thread name, and a Waiter object where the EventLoop can post incoming IPC requests to execute on the thread. The struct also holds ConnThread maps associating the thread with local and remote ProxyClient<Thread> objects.
Definition at line 572 of file proxy-io.h.
ConnThreads callback_threads mp::ThreadContext::MP_GUARDED_BY | ( | waiter-> | m_mutex | ) |
When client is making a request to a server, this is the callbackThread
argument it passes in the request, used by the server in case it needs to make callbacks into the client that need to execute while the client is waiting.
This will be set to a local thread object.
Synchronization note: The callback_thread and request_thread maps are only ever accessed internally by this thread's destructor and externally by Cap'n Proto event loop threads. Since it's possible for IPC client threads to make calls over different connections that could have different event loops, these maps are guarded by Waiter::m_mutex in case different event loop threads add or remove map entries simultaneously. However, individual ProxyClient<Thread> objects in the maps will only be associated with one event loop and guarded by EventLoop::m_mutex. So Waiter::m_mutex does not need to be held while accessing individual ProxyClient<Thread> instances, and may even need to be released to respect lock order and avoid locking Waiter::m_mutex before EventLoop::m_mutex.
ConnThreads request_threads mp::ThreadContext::MP_GUARDED_BY | ( | waiter-> | m_mutex | ) |
When client is making a request to a server, this is the thread
argument it passes in the request, used to control which thread on server will be responsible for executing it.
If client call is being made from a local thread, this will be a remote thread object returned by makeThread. If a client call is being made from a thread currently handling a server request, this will be set to the callbackThread
request thread argument passed in that request.
Synchronization note: callback_threads note applies here as well.
bool mp::ThreadContext::loop_thread = false |
Whether this thread is a capnp event loop thread.
Not really used except to assert false if there's an attempt to execute a blocking operation which could deadlock the thread.
Definition at line 627 of file proxy-io.h.
std::string mp::ThreadContext::thread_name |
Identifying string for debug.
Definition at line 575 of file proxy-io.h.
std::unique_ptr<Waiter> mp::ThreadContext::waiter = nullptr |
Waiter object used to allow remote clients to execute code on this thread.
For server threads created by ProxyServer<ThreadMap>::makeThread(), this is initialized in that function. Otherwise, for client threads created externally, this is initialized the first time the thread tries to make an IPC call. Having a waiter is necessary for threads making IPC calls in case a server they are calling expects them to execute a callback during the call, before it sends a response.
For IPC client threads, the Waiter pointer is never cleared and the Waiter just gets destroyed when the thread does. For server threads created by makeThread(), this pointer is set to null in the ~ProxyServer<Thread> as a signal for the thread to exit and destroy itself. In both cases, the same Waiter object is used across different calls and only created and destroyed once for the lifetime of the thread.
Definition at line 592 of file proxy-io.h.