summaryrefslogtreecommitdiff
path: root/zip/ZipArchive/ZipMutex_lnx.h
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2008-06-08 11:04:43 +0200
committerTomas Bzatek <tbzatek@users.sourceforge.net>2008-06-08 11:04:43 +0200
commit16f738ecee689c6feb2acb7e4ef4d9bb4144ae7d (patch)
tree3d22f54f7298f81b18ed66d05a62fa8bfab359ab /zip/ZipArchive/ZipMutex_lnx.h
downloadtuxcmd-modules-16f738ecee689c6feb2acb7e4ef4d9bb4144ae7d.tar.xz
Diffstat (limited to 'zip/ZipArchive/ZipMutex_lnx.h')
-rw-r--r--zip/ZipArchive/ZipMutex_lnx.h84
1 files changed, 84 insertions, 0 deletions
diff --git a/zip/ZipArchive/ZipMutex_lnx.h b/zip/ZipArchive/ZipMutex_lnx.h
new file mode 100644
index 0000000..dd201d0
--- /dev/null
+++ b/zip/ZipArchive/ZipMutex_lnx.h
@@ -0,0 +1,84 @@
+////////////////////////////////////////////////////////////////////////////////
+// This source file is part of the ZipArchive library source distribution and
+// is Copyrighted 2000 - 2007 by Artpol Software - Tadeusz Dracz
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// For the licensing details refer to the License.txt file.
+//
+// Web Site: http://www.artpol-software.com
+////////////////////////////////////////////////////////////////////////////////
+
+#ifndef ZIPARCHIVE_ZIPMUTEX_DOT_H
+ #error Do not include this file directly. Include ZipMutex.h instead
+#endif
+
+#ifdef ZIP_ARCHIVE_USE_LOCKING
+
+#include <pthread.h>
+
+namespace ZipArchiveLib
+{
+
+class ZIP_API CZipMutex
+{
+ pthread_mutex_t m_mutex;
+ bool m_bOpened;
+public:
+ CZipMutex(bool bOpen = false)
+ {
+ if (bOpen)
+ Open();
+ else
+ m_bOpened = false;
+ }
+
+ void Open()
+ {
+ Close();
+ if (pthread_mutex_init(&m_mutex, NULL) == 0)
+ m_bOpened = true;
+ else
+ CZipException::Throw(CZipException::mutexError);
+ }
+
+ void Lock()
+ {
+ if (pthread_mutex_lock(&m_mutex) != 0)
+ CZipException::Throw(CZipException::mutexError);
+ }
+
+ void Unlock()
+ {
+ if (pthread_mutex_unlock(&m_mutex) != 0)
+ CZipException::Throw(CZipException::mutexError);
+ }
+
+ CZipMutex& operator=(const CZipMutex&)
+ {
+ m_bOpened = false;
+ return *this;
+ }
+
+
+ void Close()
+ {
+ if (m_bOpened)
+ if (pthread_mutex_destroy(&m_mutex) == 0)
+ m_bOpened = false;
+ else
+ CZipException::Throw(CZipException::mutexError);
+ }
+
+ ~CZipMutex()
+ {
+ Close();
+ }
+};
+
+}
+
+#endif