Browse Source

- recursive mutex
- fixed not thread safe Zip access

dmuratshin 8 years ago
parent
commit
78a22d4454

+ 13 - 3
oxygine/src/core/Mutex.cpp

@@ -5,10 +5,20 @@
 
 namespace oxygine
 {
-    Mutex::Mutex()//:_handle(PTHREAD_MUTEX_INITIALIZER)
+    Mutex::Mutex(bool recursive)
     {
-        //_handle = PTHREAD_MUTEX_INITIALIZER;
-        pthread_mutex_init(&_handle, 0);
+        if (recursive)
+        {
+            pthread_mutexattr_t   mta;
+            pthread_mutexattr_init(&mta);
+            pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);
+
+            pthread_mutex_init(&_handle, &mta);
+        }
+        else
+        {
+            pthread_mutex_init(&_handle, 0);
+        }
     }
 
     Mutex::~Mutex()

+ 1 - 1
oxygine/src/core/Mutex.h

@@ -12,7 +12,7 @@ namespace oxygine
     class Mutex
     {
     public:
-        Mutex();
+        Mutex(bool recursive = false);
         ~Mutex();
 
         void lock();

+ 3 - 1
oxygine/src/core/ZipFileSystem.cpp

@@ -40,7 +40,7 @@ namespace oxygine
             return true;
         }
 
-        Zips::Zips(): _sort(false)
+        Zips::Zips(): _sort(false), _lock(true)
         {
 
         }
@@ -456,6 +456,8 @@ namespace oxygine
 
         FileSystem::status ZipFileSystem::_open(const char* file, const char* mode, error_policy ep, file::fileHandle*& fh)
         {
+            MutexAutoLock lock(_zips._lock);
+
             const file_entry* entry = _zips.getEntryByName(file);
             if (entry)
             {

+ 1 - 0
oxygine/src/core/ZipFileSystem.h

@@ -42,6 +42,7 @@ namespace oxygine
             const char* getZipFileName(int i) const { return _zps[i].name; }
 
         private:
+            friend class ZipFileSystem;
             void read(unzFile zp);
 
             bool _sort;