From 70a6ebaee550f55e750c96a098776a7f34e5a41c Mon Sep 17 00:00:00 2001 From: Jon Daniel Date: Mon, 8 Aug 2005 12:48:51 +0000 Subject: [PATCH] Added error checking to the condition signals --- src/network.cpp | 2 +- src/thread.cpp | 23 ++++++++++++++++------- src/thread.hpp | 10 +++------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/network.cpp b/src/network.cpp index 00e8037ccee..a3c93977fc3 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -333,7 +333,7 @@ void connect_operation::run() wassert(schemas.count(connect_) == 0); schemas.insert(std::pair(connect_,schema_pair())); - notify_finished(); + while(!notify_finished()); } } diff --git a/src/thread.cpp b/src/thread.cpp index ab71798aac2..d380bd2cdb9 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -12,13 +12,14 @@ */ #include "global.hpp" - +#include "log.hpp" #include "thread.hpp" #include #include #include +#define ERR_G LOG_STREAM(err, general) namespace { int run_async_operation(void* data) @@ -128,19 +129,27 @@ condition::WAIT_TIMEOUT_RESULT condition::wait_timeout(const mutex& m, unsigned } } -void condition::notify_one() +bool condition::notify_one() { - SDL_CondSignal(cond_); + if(SDL_CondSignal(cond_) < 0) { + ERR_G << "SDL_CondSignal: " << SDL_GetError() << "\n"; + return false; + } + return true; } -void condition::notify_all() +bool condition::notify_all() { - SDL_CondBroadcast(cond_); + if(SDL_CondBroadcast(cond_) < 0) { + ERR_G << "SDL_CondBroadcast: " << SDL_GetError() << "\n"; + return false; + } + return true; } -void async_operation::notify_finished() +bool async_operation::notify_finished() { - finished_.notify_one(); + return finished_.notify_one(); } async_operation::RESULT async_operation::execute(waiter& wait) diff --git a/src/thread.hpp b/src/thread.hpp index 58546e0cc7b..415d74bddb6 100644 --- a/src/thread.hpp +++ b/src/thread.hpp @@ -161,18 +161,14 @@ public: // signal the condition and wake up one thread waiting on the // condition. If no thread is waiting, notify_one() is a no-op. // Does not unlock the mutex. - // - // \todo SDL_CondSignal can return an error. This is never checked - void notify_one(); + bool notify_one(); // signal all threads waiting on the condition and let them contend // for the lock. This is often used when varying resource amounts are // involved and you do not know how many processes might continue. // The function should be used with care, especially if many threads are // waiting on the condition variable. - // - // \todo SDL_CondBroadcast can return an error. This is never checked - void notify_all(); + bool notify_all(); private: condition(const condition&); @@ -218,7 +214,7 @@ public: //while holding the mutex and after checking is_aborted() //if we want to be sure that if the operation is completed, the caller is notified. //will be called in any case after the operation returns - void notify_finished(); + bool notify_finished(); //must hold the mutex before calling this function from the worker thread bool is_aborted() const { return aborted_; }