-
Notifications
You must be signed in to change notification settings - Fork 33
/
SkaleCommon.cpp
76 lines (55 loc) · 1.99 KB
/
SkaleCommon.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
Copyright (C) 2018-2019 SKALE Labs
This file is part of skale-consensus.
skale-consensus is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
skale-consensus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with skale-consensus. If not, see <https://www.gnu.org/licenses/>.
@file SkaleCommon.cpp
@author Stan Kladko
@date 2018
*/
#include "SkaleCommon.h"
#include "Log.h"
#include "exceptions/FatalError.h"
#include "thirdparty/json.hpp"
#include "crypto/BLAKE3Hash.h"
#include "node/ConsensusEngine.h"
#include "node/Node.h"
// TODO Fix microiprofile linkage
#if MICROPROFILE_ENABLED
extern "C" void MicroProfileOnThreadCreate( const char* );
#endif
void setThreadName( std::string const& _n, ConsensusEngine* _engine ) {
string prefix;
CHECK_STATE( _engine );
if ( _engine->getNodeIDs().size() > 1 ) {
prefix = to_string( logThreadLocal_->getNodeID() );
} else {
prefix = "";
}
string name = ( prefix + _n ).substr( 0, 15 );
#if defined( __GLIBC__ )
pthread_setname_np( pthread_self(), name.c_str() );
#elif defined( __APPLE__ )
pthread_setname_np( name.c_str() );
#else
#error "error: setThreadName: we're not in Linux nor in apple?!"
#endif
#if MICROPROFILE_ENABLED
MicroProfileOnThreadCreate( _n.c_str() );
#endif
}
std::string getThreadName() {
char buf[32];
int ok = pthread_getname_np( pthread_self(), buf, sizeof( buf ) );
CHECK_STATE( ok == 0 );
return std::string( buf );
}
thread_local ptr< SkaleLog > logThreadLocal_ = nullptr;