activemq-cpp-3.6.0
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 
24 #include <decaf/util/Collection.h>
25 
26 namespace decaf {
27 namespace util {
28 namespace concurrent {
29 namespace 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 
97  ReentrantLock();
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 
269  virtual Condition* newCondition();
270 
271  public: // Diagnostics methods.
272 
304  int getHoldCount() const;
305 
346  bool isHeldByCurrentThread() const;
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 
418  bool hasQueuedThread(decaf::lang::Thread* thread) const;
419 
420  protected:
421 
433  decaf::util::Collection<decaf::lang::Thread*>* getWaitingThreads(Condition* condition) const;
434 
445  decaf::lang::Thread* getOwner() const;
446 
454  decaf::util::Collection<decaf::lang::Thread*>* getQueuedThreads() const;
455 
456  };
457 
458 }}}}
459 
460 #endif /* _DECAF_UTIL_CONCURRENT_LOCKS_REENTRANTLOCK_H_ */