Skip to content
Snippets Groups Projects
Commit 960f8fa5 authored by Steven Murray's avatar Steven Murray
Browse files

Added a private copy constructor to utils::ScopedLock. Users of this class

should not be able to make copies of its objects.
parent 14f7c9fc
Branches
Tags
No related merge requests found
......@@ -36,7 +36,8 @@
//-----------------------------------------------------------------------------
castor::tape::utils::ScopedLock::ScopedLock(pthread_mutex_t &mutex)
throw(castor::exception::Exception) :
m_mutex(mutex) {
m_mutex(&mutex) {
const int rc = pthread_mutex_lock(&mutex);
// Throw an exception if the mutex could not be locked
......@@ -52,6 +53,17 @@ castor::tape::utils::ScopedLock::ScopedLock(pthread_mutex_t &mutex)
}
//-----------------------------------------------------------------------------
// copy constructor
//-----------------------------------------------------------------------------
castor::tape::utils::ScopedLock::ScopedLock(const ScopedLock &s) throw() :
m_mutex(NULL) {
// This code is never executed because the ScopedLock assignment operator is
// private
}
//-----------------------------------------------------------------------------
// ScopedLock assignment operator
//-----------------------------------------------------------------------------
......@@ -69,5 +81,7 @@ castor::tape::utils::ScopedLock
//-----------------------------------------------------------------------------
castor::tape::utils::ScopedLock::~ScopedLock() throw() {
pthread_mutex_unlock(&m_mutex);
if(m_mutex != NULL) {
pthread_mutex_unlock(m_mutex);
}
}
......@@ -59,6 +59,12 @@ namespace utils {
private:
/**
* Private copy constructor to prevent users from trying to copy a
* ScopedLock.
*/
ScopedLock(const ScopedLock &s) throw();
/**
* Private assignment operator to prevent users from trying to copy a
* ScopedLock.
......@@ -68,7 +74,7 @@ namespace utils {
/**
* The mutex on which the lock has been taken.
*/
pthread_mutex_t &m_mutex;
pthread_mutex_t *m_mutex;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment