Browse Source

fix gettid

ithewei 6 years ago
parent
commit
346680947e
4 changed files with 22 additions and 5 deletions
  1. 12 2
      herr.cpp
  2. 1 1
      hifconf.cpp
  3. 1 1
      hplatform.h
  4. 8 1
      hthread.h

+ 12 - 2
herr.cpp

@@ -22,11 +22,21 @@ int  get_id_errcode(int id) {
 }
 
 void set_last_errcode(int errcode) {
-    set_id_errcode(gettid(), errcode);
+#if defined(OS_WIN) || defined(OS_LINUX)
+    int id = gettid();
+#else
+    int id = getpid();
+#endif
+    set_id_errcode(id, errcode);
 }
 
 int  get_last_errcode() {
-    return get_id_errcode(gettid());
+#if defined(OS_WIN) || defined(OS_LINUX)
+    int id = gettid();
+#else
+    int id = getpid();
+#endif
+    return get_id_errcode(id);
 }
 
 const char* get_errmsg(int err) {

+ 1 - 1
hifconf.cpp

@@ -6,7 +6,7 @@
 
 #include "hplatform.h"
 
-#ifdef OS_UNIX
+#ifdef OS_LINUX
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/socket.h>

+ 1 - 1
hplatform.h

@@ -115,7 +115,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <signal.h>
-#include <error.h>
+#include <errno.h>
 
 #ifdef _MSC_VER
     typedef int pid_t;

+ 8 - 1
hthread.h

@@ -10,7 +10,14 @@
 
 #ifdef OS_WIN
 #define gettid  GetCurrentThreadId
-#elif !defined(OS_ANDROID)
+#elif defined(OS_ANDROID)
+#define gettid  gettid
+#elif defined(OS_LINUX)
+#include <sys/syscall.h>
+inline int gettid() {
+    return syscall(SYS_gettid);
+}
+#else
 #define gettid  pthread_self
 #endif