Added assert()s for some common thread-safety problems.

This commit is contained in:
Gunnar Beutner 2012-07-10 13:00:53 +02:00
parent f2979eb08b
commit 60c4dce4dd
5 changed files with 14 additions and 5 deletions

View File

@ -134,6 +134,8 @@ Component::Ptr Application::LoadComponent(const string& path,
Component::Ptr component; Component::Ptr component;
Component *(*pCreateComponent)(); Component *(*pCreateComponent)();
assert(Application::IsMainThread());
Logger::Write(LogInformation, "base", "Loading component '" + path + "'"); Logger::Write(LogInformation, "base", "Loading component '" + path + "'");
#ifdef _WIN32 #ifdef _WIN32

View File

@ -113,6 +113,8 @@ time_t ConfigObject::GetCommitTimestamp(void) const
void ConfigObject::Commit(void) void ConfigObject::Commit(void)
{ {
assert(Application::IsMainThread());
ConfigObject::Ptr dobj = GetObject(GetType(), GetName()); ConfigObject::Ptr dobj = GetObject(GetType(), GetName());
ConfigObject::Ptr self = GetSelf(); ConfigObject::Ptr self = GetSelf();
assert(!dobj || dobj == self); assert(!dobj || dobj == self);
@ -125,6 +127,8 @@ void ConfigObject::Commit(void)
void ConfigObject::Unregister(void) void ConfigObject::Unregister(void)
{ {
assert(Application::IsMainThread());
ConfigObject::Ptr self = GetSelf(); ConfigObject::Ptr self = GetSelf();
m_Container->RemoveObject(self); m_Container->RemoveObject(self);
} }

View File

@ -61,6 +61,8 @@ void Logger::Write(LogSeverity severity, const string& facility,
*/ */
void Logger::RegisterLogger(const Logger::Ptr& logger) void Logger::RegisterLogger(const Logger::Ptr& logger)
{ {
assert(Application::IsMainThread());
m_Loggers.push_back(logger); m_Loggers.push_back(logger);
} }

View File

@ -33,13 +33,10 @@ Socket::Socket(void)
* Destructor for the Socket class. * Destructor for the Socket class.
*/ */
Socket::~Socket(void) Socket::~Socket(void)
{
{ {
mutex::scoped_lock lock(m_Mutex); mutex::scoped_lock lock(m_Mutex);
CloseInternal(true); CloseInternal(true);
} }
}
void Socket::Start(void) void Socket::Start(void)
{ {

View File

@ -136,6 +136,8 @@ long Timer::GetInterval(void) const
*/ */
void Timer::Start(void) void Timer::Start(void)
{ {
assert(Application::IsMainThread());
Stop(); Stop();
Timers.push_back(GetSelf()); Timers.push_back(GetSelf());
@ -148,6 +150,8 @@ void Timer::Start(void)
*/ */
void Timer::Stop(void) void Timer::Stop(void)
{ {
assert(Application::IsMainThread());
Timers.remove_if(WeakPtrEqual<Timer>(this)); Timers.remove_if(WeakPtrEqual<Timer>(this));
} }