From c61ab7c4232eb80b7cc3c2f37ba2715e16b4ee73 Mon Sep 17 00:00:00 2001 From: deva Date: Sun, 27 Mar 2005 10:29:50 +0000 Subject: Made the Error object thread safe. --- src/error.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/error.cc') diff --git a/src/error.cc b/src/error.cc index b166042..4e3f045 100644 --- a/src/error.cc +++ b/src/error.cc @@ -30,12 +30,21 @@ Error::Error() { // Initialize lastError = NULL; + + pthread_mutex_init (&mutex, NULL); } Error::~Error() { } +/* + pthread_mutex_lock(&mutex); + // ... do something + pthread_mutex_unlock(&mutex); + + */ + bool Error::hasError() { return lastError != NULL; @@ -52,17 +61,20 @@ string Error::popAllErrorStrings() string Error::popErrorString() { + pthread_mutex_lock(&mutex); if(lastError == NULL) return string(""); _err_entry *err = lastError; string le = err->errstr; lastError = err->prev; delete err; + pthread_mutex_unlock(&mutex); return le; } void Error::pushError(char* errstr) { + pthread_mutex_lock(&mutex); printf("New Error: [%s]\n", errstr); _err_entry *err = new _err_entry; @@ -70,19 +82,21 @@ void Error::pushError(char* errstr) err->errstr = errstr; err->prev = lastError; lastError = err; + pthread_mutex_unlock(&mutex); } void Error::pushError(string &errstr) { + pthread_mutex_lock(&mutex); _err_entry *err = new _err_entry; err->errstr = errstr; err->prev = lastError; lastError = err; + pthread_mutex_unlock(&mutex); } void Error::removeAllErrors() { while(lastError) popErrorString(); - } -- cgit v1.2.3