From d2db92f6b5d275b3150deb7a52a8da142a7cc953 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 31 Aug 2012 16:13:04 -0700 Subject: Simplifying TLS code a bit (removing createTLS...) and making the PthreadsTLSManager its own global class. --- src/Local.cc | 28 ++++++++++++---------------- src/Task.cc | 2 +- src/Threads.cc | 2 +- 3 files changed, 14 insertions(+), 18 deletions(-) (limited to 'src') 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(arg); void * r = thread->proc(); -- cgit v1.2.3