What about implementations of QMutexPrivate constructor? Code for win:
QMutexPrivate::QMutexPrivate()
{
event = CreateEvent(0, FALSE, FALSE, 0);
if (!event)
qWarning("QMutexData::QMutexData: Cannot create event");
}
QMutexPrivate::QMutexPrivate()
{
event = CreateEvent(0, FALSE, FALSE, 0);
if (!event)
qWarning("QMutexData::QMutexData: Cannot create event");
}
To copy to clipboard, switch view to plain text mode
Code for unix:
static void report_error(int code, const char *where, const char *what)
{
if (code != 0)
qWarning("%s: %s failure: %s", where, what, qPrintable(qt_error_string(code)));
}
QMutexPrivate::QMutexPrivate()
: wakeup(false)
{
report_error(pthread_mutex_init(&mutex, NULL), "QMutex", "mutex init");
qt_initialize_pthread_cond(&cond, "QMutex");
}
static void report_error(int code, const char *where, const char *what)
{
if (code != 0)
qWarning("%s: %s failure: %s", where, what, qPrintable(qt_error_string(code)));
}
QMutexPrivate::QMutexPrivate()
: wakeup(false)
{
report_error(pthread_mutex_init(&mutex, NULL), "QMutex", "mutex init");
qt_initialize_pthread_cond(&cond, "QMutex");
}
To copy to clipboard, switch view to plain text mode
Constructor initializes synchronization primitive, then if it failed, just reports it with warning and keeps going:
bool QMutexPrivate::wait(int timeout)
{
report_error(pthread_mutex_lock(&mutex), "QMutex::lock", "mutex lock");
...
bool QMutexPrivate::wait(int timeout)
{
report_error(pthread_mutex_lock(&mutex), "QMutex::lock", "mutex lock");
...
To copy to clipboard, switch view to plain text mode
Similar code is for Windows. Is that right to just warn about the problem and then execute another functions on it?! Shouldn't the application be aware that there was a problem with the mutex, so it can stop doing what it's doing, maybe retry, or allow any other kind of recovery strategy?
Bookmarks