summaryrefslogtreecommitdiff
path: root/src
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
parent29ff2e254871ebc359af344d6ee453047e8ad2ec (diff)
Made the Error object thread safe.
Diffstat (limited to 'src')
-rw-r--r--src/error.cc16
-rw-r--r--src/error.h8
-rw-r--r--src/mainwindow.cc1
3 files changed, 21 insertions, 4 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();
-
}
diff --git a/src/error.h b/src/error.h
index 8b26471..a7e6b29 100644
--- a/src/error.h
+++ b/src/error.h
@@ -30,6 +30,9 @@
#include <string>
using namespace std;
+#include <pthread.h>
+#include <semaphore.h>
+
/**
* This struct contains one error, and a pointer to the previous one.
*/
@@ -54,8 +57,9 @@ public:
void removeAllErrors();
private:
- // Used to save the state of the network and camera connections.
- bool error;
+ pthread_mutex_t mutex;
+
+ // A pointer to the last error.
_err_entry *lastError;
};
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index e779c19..8164981 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -95,7 +95,6 @@ MainWindow::MainWindow( QWidget* parent, const char* name )
cfg.readInt("server_port"));
cam_error = camera->errorObject();
- cam_error->pushError("fisk");
while(cam_error->hasError()) {
MessageBox(this, "", cam_error->popErrorString().c_str(), TYPE_OK, ICON_ERROR).exec();
}