summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Local.cc28
-rw-r--r--src/Task.cc2
-rw-r--r--src/Threads.cc2
3 files changed, 14 insertions, 18 deletions
diff --git a/src/Local.cc b/src/Local.cc
index 9729c35..a9eccdd 100644
--- a/src/Local.cc
+++ b/src/Local.cc
@@ -13,10 +13,6 @@ void * Balau::TLSManager::setTLS(void * val) {
return r;
}
-void * Balau::TLSManager::createTLS() {
- return Local::create();
-}
-
static Balau::TLSManager dummyTLSManager;
Balau::TLSManager * Balau::g_tlsManager = &dummyTLSManager;
@@ -29,31 +25,31 @@ void Balau::Local::doStart() {
m_globals[m_idx] = 0;
}
-class PThreadsTLSManager : public Balau::TLSManager, public Balau::AtStart {
+class GlobalPThreadsTLSManager : public Balau::PThreadsTLSManager, public Balau::AtStart {
public:
- PThreadsTLSManager() : AtStart(0) { }
- virtual void * getTLS();
- virtual void * setTLS(void * val);
- virtual void doStart();
- private:
- pthread_key_t m_key;
+ GlobalPThreadsTLSManager() : AtStart(0) { }
+ void doStart();
};
-PThreadsTLSManager pthreadsTLSManager;
+GlobalPThreadsTLSManager pthreadsTLSManager;
+
+void GlobalPThreadsTLSManager::doStart() {
+ init();
+ Balau::g_tlsManager = this;
+}
-void PThreadsTLSManager::doStart() {
+void Balau::PThreadsTLSManager::init() {
int r;
r = pthread_key_create(&m_key, NULL);
RAssert(r == 0, "Unable to create a pthtread_key: %i", r);
- Balau::g_tlsManager = this;
}
-void * PThreadsTLSManager::getTLS() {
+void * Balau::PThreadsTLSManager::getTLS() {
return pthread_getspecific(m_key);
}
-void * PThreadsTLSManager::setTLS(void * val) {
+void * Balau::PThreadsTLSManager::setTLS(void * val) {
void * r = pthread_getspecific(m_key);
pthread_setspecific(m_key, val);
return r;
diff --git a/src/Task.cc b/src/Task.cc
index 6278fd5..aba29b8 100644
--- a/src/Task.cc
+++ b/src/Task.cc
@@ -35,7 +35,7 @@ void Balau::Task::setup(TaskMan * taskMan, void * stack) {
m_taskMan = taskMan;
- m_tls = g_tlsManager->createTLS();
+ m_tls = Local::createTLS();
void * oldTLS = g_tlsManager->getTLS();
g_tlsManager->setTLS(m_tls);
localTask.set(this);
diff --git a/src/Threads.cc b/src/Threads.cc
index fe90394..9ecfff5 100644
--- a/src/Threads.cc
+++ b/src/Threads.cc
@@ -39,7 +39,7 @@ Balau::RWLock::RWLock() {
}
void * Balau::ThreadHelper::threadProc(void * arg) {
- void * tls = g_tlsManager->createTLS();
+ void * tls = Local::createTLS();
g_tlsManager->setTLS(tls);
Balau::Thread * thread = reinterpret_cast<Balau::Thread *>(arg);
void * r = thread->proc();