Skip to content

Commit b5a9432

Browse files
committed
typo and etc.
1 parent 4a438cb commit b5a9432

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

ddprof-lib/src/main/cpp/threadLocal.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ typedef void* (*CREATE_FUNC)(void);
5656
// Cleanup the value when deleting the key
5757
typedef void (*CLEAN_FUNC)(void*);
5858

59-
static constexpr pthread_key_t INVLID_KEY = pthread_key_t(-1);
59+
static constexpr pthread_key_t INVALID_KEY = pthread_key_t(-1);
6060

6161
template <typename T, CREATE_FUNC C = nullptr, CLEAN_FUNC F = nullptr>
6262
class ThreadLocal {
@@ -67,10 +67,12 @@ class ThreadLocal {
6767
ThreadLocal(const ThreadLocal&) = delete;
6868
ThreadLocal& operator=(const ThreadLocal&) = delete;
6969

70-
ThreadLocal() : _key(INVLID_KEY) {
70+
ThreadLocal() : _key(INVALID_KEY) {
7171
static_assert(sizeof(T) == sizeof(void*),
7272
"ThreadLocal<T> requires sizeof(T)==sizeof(void*); use a pointer type or add a specialization");
73-
pthread_key_create(&_key, F);
73+
if (pthread_key_create(&_key, F) != 0) {
74+
_key = INVALID_KEY;
75+
}
7476
// What to do if we can not create a key?
7577
// We probably want to shutdown profiler gracefully, instead of
7678
// aborting user application - We will need this mechanism globally,
@@ -87,7 +89,7 @@ class ThreadLocal {
8789
}
8890

8991
bool isKeyValid() const {
90-
return _key != INVLID_KEY;
92+
return _key != INVALID_KEY;
9193
}
9294

9395
/**
@@ -134,11 +136,13 @@ class ThreadLocal<double> {
134136
ThreadLocal(const ThreadLocal&) = delete;
135137
ThreadLocal& operator=(const ThreadLocal&) = delete;
136138

137-
ThreadLocal() : _key(INVLID_KEY) {
139+
ThreadLocal() : _key(INVALID_KEY) {
138140
// Only support 64-bit platforms, double and void* are the same size
139141
static_assert(sizeof(void*) == 8);
140142
static_assert(sizeof(double) == 8);
141-
pthread_key_create(&_key, nullptr);
143+
if (pthread_key_create(&_key, nullptr) != 0) {
144+
_key =INVALID_KEY;
145+
}
142146
// What to do if we can not create a key?
143147
assert(isKeyValid() && "Invalid pthread key");
144148
}
@@ -152,7 +156,7 @@ class ThreadLocal<double> {
152156
}
153157

154158
bool isKeyValid() const {
155-
return _key != INVLID_KEY;
159+
return _key != INVALID_KEY;
156160
}
157161

158162
// double <--> u64 cast, preserve bit format
@@ -200,7 +204,7 @@ class ThreadLocal<JVMThread*> {
200204
ThreadLocal(const ThreadLocal&) = delete;
201205
ThreadLocal& operator=(const ThreadLocal&) = delete;
202206

203-
ThreadLocal() : _key(INVLID_KEY) {
207+
ThreadLocal() : _key(INVALID_KEY) {
204208
}
205209

206210
void initialize(void* current_thread) {
@@ -222,7 +226,7 @@ class ThreadLocal<JVMThread*> {
222226
}
223227

224228
bool isKeyValid() const {
225-
return _key != INVLID_KEY;
229+
return _key != INVALID_KEY;
226230
}
227231

228232
pthread_key_t key() const {

0 commit comments

Comments
 (0)