summaryrefslogtreecommitdiff
path: root/src/error.cc
diff options
context:
space:
mode:
authordeva <deva>2005-03-27 10:29:50 +0000
committerdeva <deva>2005-03-27 10:29:50 +0000
commitc61ab7c4232eb80b7cc3c2f37ba2715e16b4ee73 (patch)
tree2d49cb3cc44f0249e0b90e547b58bb50f68c5270 /src/error.cc
parent29ff2e254871ebc359af344d6ee453047e8ad2ec (diff)
Made the Error object thread safe.
Diffstat (limited to 'src/error.cc')
-rw-r--r--src/error.cc16
1 files changed, 15 insertions, 1 deletions
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();
-
}