Created
February 15, 2015 17:50
-
-
Save computerquip/ffc7ba7965930669ac4c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/voglcore/vogl_port_posix.cpp b/src/voglcore/vogl_port_posix.cpp | |
index 0df14e4..a911059 100644 | |
--- a/src/voglcore/vogl_port_posix.cpp | |
+++ b/src/voglcore/vogl_port_posix.cpp | |
@@ -37,11 +37,42 @@ | |
#include <sys/mman.h> | |
#include <sys/syscall.h> | |
#include <sys/time.h> | |
+#include <map> | |
#if defined(PLATFORM_OSX) | |
#include <unistd.h> | |
#endif | |
+namespace { | |
+ | |
+struct pthread_comp | |
+{ | |
+ bool operator()(pthread_t p1, pthread_t p2) const | |
+ { | |
+ return pthread_equal(p1, p2); | |
+ } | |
+}; | |
+ | |
+typedef std::map<pthread_t, uint64_t, pthread_comp> pthread_map; | |
+pthread_map g_pthread_lookup; | |
+ | |
+uint64_t get_pthread_index(pthread_t id) | |
+{ | |
+ /* Index probably needs to be atomically dealt with */ | |
+ static uint64_t index = 0; | |
+ | |
+ pthread_map::iterator found = g_pthread_lookup.find(id); | |
+ | |
+ if (found == g_pthread_lookup.end()) | |
+ return found->second; | |
+ | |
+ g_pthread_lookup[id] = index; | |
+ | |
+ return index++; | |
+} | |
+ | |
+} | |
+ | |
int plat_chdir(const char* path) | |
{ | |
return chdir(path); | |
@@ -108,7 +139,7 @@ pid_t plat_gettid() | |
uint64_t plat_posix_gettid() | |
{ | |
- return reinterpret_cast<uintptr_t>(pthread_self()); | |
+ return get_pthread_index(pthread_self()); | |
} | |
pid_t plat_getpid() |
There also is trailing whitespace on lines 24, 32, 34, 37, and 39.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I know this isn't finalized code but just for reference it looks like line 35 should be != instead of ==