From 297b073c94d4199c1f7cd1b5dee54ec98da4b40e Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Sun, 9 Sep 2012 11:12:15 -0400 Subject: [PATCH] fix major bugs --- include/fc/shared_ptr.hpp | 4 ++-- src/filesystem.cpp | 4 ++-- src/thread.cpp | 28 ++++++++++++---------------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/include/fc/shared_ptr.hpp b/include/fc/shared_ptr.hpp index 0674aca..adba5d4 100644 --- a/include/fc/shared_ptr.hpp +++ b/include/fc/shared_ptr.hpp @@ -52,11 +52,11 @@ namespace fc { shared_ptr& operator=(const shared_ptr& p ) { shared_ptr tmp(p); - fc::swap(tmp,*this); + fc::swap(tmp._ptr,_ptr); return *this; } shared_ptr& operator=(shared_ptr&& p ) { - fc::swap(*this,p); + fc::swap(_ptr,p._ptr); return *this; } T& operator* ()const { return *_ptr; } diff --git a/src/filesystem.cpp b/src/filesystem.cpp index a2cad46..4a305f3 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -41,10 +41,10 @@ namespace fc { } path::operator boost::filesystem::path& () { - return static_cast(*this); + return *_p; } path::operator const boost::filesystem::path& ()const { - return static_cast(*this); + return *_p; } fc::string path::string()const { diff --git a/src/thread.cpp b/src/thread.cpp index ba7c06b..8967c65 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -7,11 +7,21 @@ namespace fc { static boost::mutex m; return m; } + thread*& current_thread() { + #ifdef _MSC_VER + static __declspec(thread) thread* t = NULL; + #else + static __thread thread* t = NULL; + #endif + return t; + } + thread::thread( const char* name ) { promise::ptr p(new promise()); boost::thread* t = new boost::thread( [this,p]() { try { this->my = new thread_d(*this); + current_thread() = this; p->set_value(); exec(); } catch ( ... ) { @@ -41,22 +51,8 @@ namespace fc { } thread& thread::current() { - // Apple does not support __thread by default, but some custom gcc builds - // for Mac OS X support it. Backup use boost::thread_specific_ptr - #if defined(__APPLE__) && (__GNUC__ <= 4 && __GNUC_MINOR__ < 4) - #warning using boost::thread_specific_ptr instead of __thread, use gcc 4.5 or newer for better performance. - static boost::thread_specific_ptr t; - if( !t.get() ) t.reset( new thread((thread_d*)0) ); - return *t.get(); - #else - #ifdef _MSC_VER - static __declspec(thread) thread* t = NULL; - #else - static __thread thread* t = NULL; - #endif - if( !t ) t = new thread((thread_d*)0); - return *t; - #endif + if( !current_thread() ) current_thread() = new thread((thread_d*)0); + return *current_thread(); } const string& thread::name()const { return my->name; } void thread::set_name( const fc::string& n ) { my->name = n; }