From 5362e70f8f3c58f0f1fc67ea0a8fc299c554e1bc Mon Sep 17 00:00:00 2001 From: boz Date: Wed, 15 Aug 2007 20:55:36 +0000 Subject: [PATCH] THRIFT: mutex trylock support Summary: add trylock support to the Mutex class Reviewed By: mcslee Test Plan: added trylock mutexes to foreman, walked through them in gdb (behaved correctly) and then ran an entire sweep (behaved correctly) Notes: slee ftw git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665204 13f79535-47bb-0310-9956-ffa450edef68 --- lib/cpp/src/concurrency/Mutex.cpp | 4 ++++ lib/cpp/src/concurrency/Mutex.h | 1 + 2 files changed, 5 insertions(+) diff --git a/lib/cpp/src/concurrency/Mutex.cpp b/lib/cpp/src/concurrency/Mutex.cpp index 8f797958..695d5dc5 100644 --- a/lib/cpp/src/concurrency/Mutex.cpp +++ b/lib/cpp/src/concurrency/Mutex.cpp @@ -35,6 +35,8 @@ class Mutex::impl { void lock() const { pthread_mutex_lock(&pthread_mutex_); } + bool trylock() const { return (0 == pthread_mutex_trylock(&pthread_mutex_)); } + void unlock() const { pthread_mutex_unlock(&pthread_mutex_); } private: @@ -46,6 +48,8 @@ Mutex::Mutex() : impl_(new Mutex::impl()) {} void Mutex::lock() const { impl_->lock(); } +bool Mutex::trylock() const { return impl_->trylock(); } + void Mutex::unlock() const { impl_->unlock(); } /** diff --git a/lib/cpp/src/concurrency/Mutex.h b/lib/cpp/src/concurrency/Mutex.h index 02accf90..72f75257 100644 --- a/lib/cpp/src/concurrency/Mutex.h +++ b/lib/cpp/src/concurrency/Mutex.h @@ -20,6 +20,7 @@ class Mutex { Mutex(); virtual ~Mutex() {} virtual void lock() const; + virtual bool trylock() const; virtual void unlock() const; private: -- 2.17.1