damitha 2003/09/05 05:11:29
Modified: c/src/engine SharedObject.cpp SharedObject.h
Log:
Log:Changed the code so that the code use a mutex to lock and unlock. This will make
the code thread safe.
Revision Changes Path
1.4 +5 -5 xml-axis/c/src/engine/SharedObject.cpp
Index: SharedObject.cpp
===================================================================
RCS file: /home/cvs/xml-axis/c/src/engine/SharedObject.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SharedObject.cpp 27 Aug 2003 12:16:35 -0000 1.3
+++ SharedObject.cpp 5 Sep 2003 12:11:28 -0000 1.4
@@ -72,26 +72,26 @@
SharedObject::SharedObject()
{
m_bLocked = false;
+ mut = new pthread_mutex_t;
+ pthread_mutex_init(mut, NULL);
}
SharedObject::~SharedObject()
{
-
+ pthread_mutex_destroy(mut);
}
//Following functions should be improved to avoid chances of failure
//using platform specific mechanisms
int SharedObject::lock()
{
- while (m_bLocked)
- {
- Ax_Sleep(0);
- }
+ pthread_mutex_lock(mut);
m_bLocked = true;
return 0;
}
int SharedObject::unlock()
{
+ pthread_mutex_unlock(mut);
m_bLocked = false;
return 0;
}
1.5 +4 -1 xml-axis/c/src/engine/SharedObject.h
Index: SharedObject.h
===================================================================
RCS file: /home/cvs/xml-axis/c/src/engine/SharedObject.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SharedObject.h 1 Sep 2003 07:28:28 -0000 1.4
+++ SharedObject.h 5 Sep 2003 12:11:28 -0000 1.5
@@ -67,6 +67,7 @@
#define AFX_SHAREDOBJECT_H__0805D25C_2F7E_4B19_BECE_0A8BFE9F0830__INCLUDED_
#include "../common/GDefine.h"
+#include "pthread.h"
class SharedObject
{
@@ -77,7 +78,9 @@
int unlock();
int lock();
private:
- volatile bool m_bLocked;
+ bool m_bLocked;
+ pthread_mutex_t* mut;
};
+static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
#endif //
!defined(AFX_SHAREDOBJECT_H__0805D25C_2F7E_4B19_BECE_0A8BFE9F0830__INCLUDED_)