mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
Prevent data race for pathHandlers
This commit is contained in:
parent
ea67232cdb
commit
4296dde287
@ -142,7 +142,8 @@ static std::vector<CSubNet> rpc_allow_subnets;
|
||||
//! Work queue for handling longer requests off the event loop thread
|
||||
static std::unique_ptr<WorkQueue<HTTPClosure>> g_work_queue{nullptr};
|
||||
//! Handlers for (sub)paths
|
||||
static std::vector<HTTPPathHandler> pathHandlers;
|
||||
static GlobalMutex g_httppathhandlers_mutex;
|
||||
static std::vector<HTTPPathHandler> pathHandlers GUARDED_BY(g_httppathhandlers_mutex);
|
||||
//! Bound listening sockets
|
||||
static std::vector<evhttp_bound_socket *> boundSockets;
|
||||
|
||||
@ -243,6 +244,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
|
||||
// Find registered handler for prefix
|
||||
std::string strURI = hreq->GetURI();
|
||||
std::string path;
|
||||
LOCK(g_httppathhandlers_mutex);
|
||||
std::vector<HTTPPathHandler>::const_iterator i = pathHandlers.begin();
|
||||
std::vector<HTTPPathHandler>::const_iterator iend = pathHandlers.end();
|
||||
for (; i != iend; ++i) {
|
||||
@ -674,11 +676,13 @@ std::optional<std::string> GetQueryParameterFromUri(const char* uri, const std::
|
||||
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
|
||||
{
|
||||
LogPrint(BCLog::HTTP, "Registering HTTP handler for %s (exactmatch %d)\n", prefix, exactMatch);
|
||||
LOCK(g_httppathhandlers_mutex);
|
||||
pathHandlers.push_back(HTTPPathHandler(prefix, exactMatch, handler));
|
||||
}
|
||||
|
||||
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
|
||||
{
|
||||
LOCK(g_httppathhandlers_mutex);
|
||||
std::vector<HTTPPathHandler>::iterator i = pathHandlers.begin();
|
||||
std::vector<HTTPPathHandler>::iterator iend = pathHandlers.end();
|
||||
for (; i != iend; ++i)
|
||||
|
Loading…
Reference in New Issue
Block a user