Added error checking to the condition signals
This commit is contained in:
parent
fd74a92cd5
commit
70a6ebaee5
3 changed files with 20 additions and 15 deletions
|
@ -333,7 +333,7 @@ void connect_operation::run()
|
|||
wassert(schemas.count(connect_) == 0);
|
||||
schemas.insert(std::pair<network::connection,schema_pair>(connect_,schema_pair()));
|
||||
|
||||
notify_finished();
|
||||
while(!notify_finished());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,13 +12,14 @@
|
|||
*/
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
#include "log.hpp"
|
||||
#include "thread.hpp"
|
||||
|
||||
#include <new>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#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)
|
||||
|
|
|
@ -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_; }
|
||||
|
|
Loading…
Add table
Reference in a new issue