summaryrefslogtreecommitdiff
path: root/XMPCommon/source/AutoSharedLock.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'XMPCommon/source/AutoSharedLock.cpp')
-rw-r--r--XMPCommon/source/AutoSharedLock.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/XMPCommon/source/AutoSharedLock.cpp b/XMPCommon/source/AutoSharedLock.cpp
new file mode 100644
index 0000000..4648365
--- /dev/null
+++ b/XMPCommon/source/AutoSharedLock.cpp
@@ -0,0 +1,49 @@
+// =================================================================================================
+// ADOBE SYSTEMS INCORPORATED
+// Copyright 2014 Adobe Systems Incorporated
+// All Rights Reserved
+//
+// NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
+// of the Adobe license agreement accompanying it.
+// =================================================================================================
+
+#include "XMPCommon/Utilities/AutoSharedLock.h"
+#include "XMPCommon/Interfaces/ISharedMutex.h"
+#include "XMPCommon/Interfaces/IError_I.h"
+#include "XMPCommon/XMPCommonErrorCodes_I.h"
+
+namespace XMP_COMPONENT_INT_NAMESPACE {
+ AutoSharedLock::AutoSharedLock( const spISharedMutex & mutex, bool exclusiveLock /*= false */ )
+ : mMutex( mutex )
+ , mExclusiveLock( exclusiveLock )
+ {
+ if ( mMutex ) {
+ eMultiThreadingErrorCode er;
+ if ( mExclusiveLock )
+ er = mMutex->Lock();
+ else
+ er = mMutex->LockShared();
+ if ( er != kMTECNone ) {
+ NOTIFY_ERROR( IError_v1::kEDMultiThreading, er, "Unable to lock the mutex", IError_v1::kESProcessFatal, false, false );
+ }
+ }
+ }
+
+ AutoSharedLock::~AutoSharedLock() {
+ Release();
+ }
+
+ void AutoSharedLock::Release() {
+ if ( mMutex ) {
+ eMultiThreadingErrorCode er;
+ if ( mExclusiveLock )
+ er = mMutex->Unlock();
+ else
+ er = mMutex->UnlockShared();
+ if ( er != kMTECNone ) {
+ NOTIFY_ERROR( IError_v1::kEDMultiThreading, er, "Unable to lock the mutex", IError_v1::kESProcessFatal, false, false );
+ }
+ }
+ }
+
+}