From 9704c57c47dc31f592ecf3a38e303ee3bcbbae74 Mon Sep 17 00:00:00 2001
From: Pixel <pixel@nobis-crew.org>
Date: Thu, 13 Oct 2011 23:50:26 -0700
Subject: Implementing a pthread TLSManager.

---
 src/Local.cc | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

(limited to 'src')

diff --git a/src/Local.cc b/src/Local.cc
index 1619557..8418fb1 100644
--- a/src/Local.cc
+++ b/src/Local.cc
@@ -29,3 +29,32 @@ void Balau::Local::doStart() {
     m_globals = reinterpret_cast<void **>(realloc(m_globals, s_size * sizeof(void *)));
     m_globals[m_idx] = 0;
 }
+
+class PThreadsTLSManager : public Balau::TLSManager, public Balau::AtStart {
+  public:
+      PThreadsTLSManager() : AtStart(0) { }
+    virtual void * getTLS();
+    virtual void * setTLS(void * val);
+    virtual void doStart();
+  private:
+    pthread_key_t m_key;
+};
+
+PThreadsTLSManager pthreadsTLSManager;
+
+void PThreadsTLSManager::doStart() {
+    int r;
+
+    r = pthread_key_create(&m_key, NULL);
+    Assert(r == 0);
+}
+
+void * PThreadsTLSManager::getTLS() {
+    return pthread_getspecific(m_key);
+}
+
+void * PThreadsTLSManager::setTLS(void * val) {
+    void * r = pthread_getspecific(m_key);
+    pthread_setspecific(m_key, val);
+    return r;
+}
-- 
cgit v1.2.3