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 *(*pCreateComponent)();
assert(Application::IsMainThread());
Logger::Write(LogInformation, "base", "Loading component '" + path + "'");
#ifdef _WIN32

View File

@ -113,6 +113,8 @@ time_t ConfigObject::GetCommitTimestamp(void) const
void ConfigObject::Commit(void)
{
assert(Application::IsMainThread());
ConfigObject::Ptr dobj = GetObject(GetType(), GetName());
ConfigObject::Ptr self = GetSelf();
assert(!dobj || dobj == self);
@ -125,6 +127,8 @@ void ConfigObject::Commit(void)
void ConfigObject::Unregister(void)
{
assert(Application::IsMainThread());
ConfigObject::Ptr self = GetSelf();
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)
{
assert(Application::IsMainThread());
m_Loggers.push_back(logger);
}

View File

@ -34,11 +34,8 @@ Socket::Socket(void)
*/
Socket::~Socket(void)
{
{
mutex::scoped_lock lock(m_Mutex);
CloseInternal(true);
}
mutex::scoped_lock lock(m_Mutex);
CloseInternal(true);
}
void Socket::Start(void)

View File

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