Skip to content

Instantly share code, notes, and snippets.

@computerquip
Created February 15, 2015 17:50
Show Gist options
  • Save computerquip/ffc7ba7965930669ac4c to your computer and use it in GitHub Desktop.
Save computerquip/ffc7ba7965930669ac4c to your computer and use it in GitHub Desktop.
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()
@lawlove
Copy link

lawlove commented Feb 16, 2015

I know this isn't finalized code but just for reference it looks like line 35 should be != instead of ==

@Tele42
Copy link

Tele42 commented Feb 20, 2016

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