Commit 4ba692d3 authored by David COME's avatar David COME
Browse files

Removed TRyMutexLocker and Mutex::trylock

parent e45e5e2e
......@@ -46,19 +46,6 @@ namespace threading {
pthread_mutex_unlock(&m_mutex),
"Error from pthread_mutex_unlock in castor::tape::threading::Mutex::unlock()");
}
/**
* Try to aquire the mutex
* @return true if the mutex was succesffuly acquired, false otherwise
*/
bool trylock() {
const int val=pthread_mutex_trylock(&m_mutex);
if(0==val){
return true;
}
else {
return false;
}
}
private:
pthread_mutex_t m_mutex;
};
......@@ -76,21 +63,6 @@ namespace threading {
private:
Mutex * m_mutex;
};
/**
* A simple scoped locker for mutexes. Highly recommended as
* the mutex will be released in all cases (exception, mid-code return, etc...)
* To use, simply instanciate and forget.
* @param m pointer to a Mutex instance
*/
class TryMutexLocker {
public:
TryMutexLocker(Mutex * m) :m_mutex(m),m_succes(m->trylock()) {}
~TryMutexLocker() { if(m_succes){m_mutex->unlock();} }
operator bool() const {return m_succes; }
private:
Mutex * m_mutex;
bool m_succes;
};
/**
* An exception throwing wrapper to posix semaphores.
......
......@@ -97,21 +97,4 @@ namespace unitTests {
ASSERT_NE(std::string::npos, w.find("Exception in child thread"));
}
}
TEST(castor_tape_threading, TestTryMutexLocker) {
castor::tape::threading::Mutex m;
ASSERT_EQ(true, m.trylock());
ASSERT_NO_THROW(m.unlock());
{
castor::tape::threading::TryMutexLocker l1(&m);
ASSERT_EQ(true, l1);
castor::tape::threading::TryMutexLocker l2(&m);
ASSERT_EQ(false, l2);
ASSERT_THROW(m.lock(),castor::exception::Errnum);
}
ASSERT_THROW(m.unlock(),castor::exception::Errnum);
}
} // namespace unitTests
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment