ithewei il y a 4 ans
Parent
commit
ad2f267ada
2 fichiers modifiés avec 23 ajouts et 10 suppressions
  1. 16 0
      cpputil/ThreadLocalStorage.cpp
  2. 7 10
      cpputil/ThreadLocalStorage.h

+ 16 - 0
cpputil/ThreadLocalStorage.cpp

@@ -2,8 +2,22 @@
 
 #include "hthread.h"
 
+namespace hv {
+
 ThreadLocalStorage ThreadLocalStorage::tls[ThreadLocalStorage::MAX_NUM];
 
+void ThreadLocalStorage::set(int idx, void* val) {
+    return tls[idx].set(val);
+}
+
+void* ThreadLocalStorage::get(int idx) {
+    return tls[idx].get();
+}
+
+void ThreadLocalStorage::setThreadName(const char* name) {
+    set(THREAD_NAME, (void*)name);
+}
+
 const char* ThreadLocalStorage::threadName() {
     static char unnamed[32] = {0};
     void* value = get(THREAD_NAME);
@@ -13,3 +27,5 @@ const char* ThreadLocalStorage::threadName() {
     snprintf(unnamed, sizeof(unnamed)-1, "thread-%ld", hv_gettid());
     return unnamed;
 }
+
+}

+ 7 - 10
cpputil/ThreadLocalStorage.h

@@ -25,6 +25,8 @@
 #endif
 
 #ifdef __cplusplus
+namespace hv {
+
 class HV_EXPORT ThreadLocalStorage {
 public:
     enum {
@@ -48,23 +50,18 @@ public:
         return hthread_get_value(key);
     }
 
-    static void set(int idx, void* val) {
-        return tls[idx].set(val);
-    }
-
-    static void* get(int idx) {
-        return tls[idx].get();
-    }
+    static void  set(int idx, void* val);
+    static void* get(int idx);
 
-    static void setThreadName(const char* name) {
-        set(THREAD_NAME, (void*)name);
-    }
+    static void  setThreadName(const char* name);
     static const char* threadName();
 
 private:
     hthread_key_t key;
     static ThreadLocalStorage tls[MAX_NUM];
 };
+
+}
 #endif
 
 #endif // HV_THREAD_LOCAL_STORAGE_H_