-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy paththreadglobals.cpp
55 lines (45 loc) · 1.21 KB
/
threadglobals.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
This file is part of FlashMQ (https://www.flashmq.org)
Copyright (C) 2021-2023 Wiebe Cazemier
FlashMQ is free software: you can redistribute it and/or modify
it under the terms of The Open Software License 3.0 (OSL-3.0).
See LICENSE for license details.
*/
#include "threadglobals.h"
#include <cassert>
thread_local Authentication *ThreadGlobals::auth = nullptr;
thread_local ThreadData *ThreadGlobals::threadData = nullptr;
thread_local Settings *ThreadGlobals::settings = nullptr;
void ThreadGlobals::assign(Authentication *auth)
{
#ifndef TESTING
assert(ThreadGlobals::auth == nullptr);
#endif
ThreadGlobals::auth = auth;
}
Authentication *ThreadGlobals::getAuth()
{
return auth;
}
void ThreadGlobals::assignThreadData(ThreadData *threadData)
{
#ifndef TESTING
assert(ThreadGlobals::threadData == nullptr);
#endif
ThreadGlobals::threadData = threadData;
}
ThreadData *ThreadGlobals::getThreadData()
{
return threadData;
}
void ThreadGlobals::assignSettings(Settings *settings)
{
#ifndef TESTING
assert(ThreadGlobals::settings == nullptr || ThreadGlobals::settings == settings);
#endif
ThreadGlobals::settings = settings;
}
Settings *ThreadGlobals::getSettings()
{
return settings;
}