activemq-cpp-3.9.5
ReentrantLock.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _DECAF_UTIL_CONCURRENT_LOCKS_REENTRANTLOCK_H_
19#define _DECAF_UTIL_CONCURRENT_LOCKS_REENTRANTLOCK_H_
20
21#include <decaf/util/Config.h>
22
25
26namespace decaf {
27namespace util {
28namespace concurrent {
29namespace locks {
30
31 class Sync;
32
80 class DECAF_API ReentrantLock : public Lock {
81 private:
82
83 // Instance of an AbstractQueuedSynchronizer specific to this type of Lock.
84 // Will vary depending on whether fair or unfair lock semantics are requested.
85 Sync* sync;
86
87 private:
88
89 ReentrantLock( const ReentrantLock& );
90 ReentrantLock& operator= ( const ReentrantLock& );
91
92 public:
93
98
105 ReentrantLock(bool fair);
106
107 virtual ~ReentrantLock();
108
124 virtual void lock();
125
158 virtual void lockInterruptibly();
159
181 virtual bool tryLock();
182
234 virtual bool tryLock( long long time, const TimeUnit& unit );
235
245 virtual void unlock();
246
270
271 public: // Diagnostics methods.
272
304 int getHoldCount() const;
305
347
354 bool isLocked() const;
355
361 bool isFair() const;
362
370 std::string toString() const;
371
379 int getQueueLength() const;
380
393 int getWaitQueueLength(Condition* condition) const;
394
405 bool hasWaiters(Condition* condition) const;
406
410 bool hasQueuedThreads() const;
411
419
420 protected:
421
434
446
455
456 };
457
458}}}}
459
460#endif /* _DECAF_UTIL_CONCURRENT_LOCKS_REENTRANTLOCK_H_ */
A Thread is a concurrent unit of execution.
Definition Thread.h:64
The root interface in the collection hierarchy.
Definition Collection.h:69
A TimeUnit represents time durations at a given unit of granularity and provides utility methods to c...
Definition TimeUnit.h:62
Condition factors out the Mutex monitor methods (wait, notify and notifyAll) into distinct objects to...
Definition Condition.h:132
Lock implementations provide more extensive locking operations than can be obtained using synchronize...
Definition Lock.h:99
virtual void lockInterruptibly()
Acquires the lock unless the current thread is interrupted.
int getHoldCount() const
Queries the number of holds on this lock by the current thread.
bool hasWaiters(Condition *condition) const
Returns true if there are any threads that are currently waiting on the given Condition object,...
bool isHeldByCurrentThread() const
Queries if this lock is held by the current thread.
virtual void unlock()
Attempts to release this lock.
decaf::util::Collection< decaf::lang::Thread * > * getQueuedThreads() const
Creates and returns a new Collection object that contains a best effort snapshot of the threads that ...
int getQueueLength() const
Gets an estimated count of the number of threads that are currently waiting to acquire,...
virtual Condition * newCondition()
Returns a Condition instance for use with this Lock instance.
virtual void lock()
Acquires the lock.
decaf::util::Collection< decaf::lang::Thread * > * getWaitingThreads(Condition *condition) const
Creates and returns a new Collection object that contains all the threads that may be waiting on the ...
decaf::lang::Thread * getOwner() const
Returns the thread that currently owns this lock, or NULL if not owned.
bool isLocked() const
Queries if this lock is held by any thread.
int getWaitQueueLength(Condition *condition) const
Gets an estimated count of the number of threads that are currently waiting on the given Condition ob...
virtual bool tryLock(long long time, const TimeUnit &unit)
Acquires the lock if it is not held by another thread within the given waiting time and the current t...
bool isFair() const
Returns true if this lock has fairness set true.
std::string toString() const
Returns a string identifying this lock, as well as its lock state.
ReentrantLock(bool fair)
Create a new ReentrantLock instance with the specified locking semantics.
ReentrantLock()
Create a new ReentrantLock instance with unfair locking semantics.
bool hasQueuedThread(decaf::lang::Thread *thread) const
virtual bool tryLock()
Acquires the lock only if it is not held by another thread at the time of invocation.
#define DECAF_API
Definition Config.h:29
Definition AbstractOwnableSynchronizer.h:29
Definition AbstractExecutorService.h:28
Definition AbstractCollection.h:33
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition AprPool.h:25