activemq-cpp-3.9.5
AbstractQueuedSynchronizer.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_ABSTRACTQUEUEDSYNCHRONIZER_H_
19#define _DECAF_UTIL_CONCURRENT_LOCKS_ABSTRACTQUEUEDSYNCHRONIZER_H_
20
21#include <decaf/util/Config.h>
22
26#include <decaf/lang/Thread.h>
27
28namespace decaf {
29namespace util {
30namespace concurrent {
31namespace locks {
32
33 class SynchronizerState;
34
35 class DECAF_API AbstractQueuedSynchronizer : public AbstractOwnableSynchronizer {
36 private:
37
39
40 private:
41
42 AbstractQueuedSynchronizer(const AbstractQueuedSynchronizer&);
43 AbstractQueuedSynchronizer& operator= (const AbstractQueuedSynchronizer&);
44
45 protected:
46
48
49 public:
50
55 class ConditionObject : public Condition {
56 private:
57
59
60 private:
61
62 ConditionObject(const ConditionObject&);
63 ConditionObject& operator= (const ConditionObject&);
64
65 public:
66
68 virtual ~ConditionObject() {}
69
70 protected:
71
77 virtual bool isOwnedBy(const AbstractQueuedSynchronizer* sync) const = 0;
78
85 virtual bool hasWaiters() const = 0;
86
93 virtual int getWaitQueueLength() const = 0;
94
102 };
103
104 public:
105
107
116 void acquire(int arg);
117
126 void acquireShared(int arg);
127
139 void acquireInterruptibly(int arg);
140
152
161
170
178
187
195 int getQueueLength() const;
196
209
223
227 bool hasContended() const;
228
232 bool hasQueuedThreads() const;
233
245
253 bool isQueued(decaf::lang::Thread* thread) const;
254
263
274 bool release(int arg);
275
286 bool releaseShared(int arg);
287
296 std::string toString() const;
297
312 bool tryAcquireNanos(int arg, long long nanos);
313
328 bool tryAcquireSharedNanos(int arg, long long nanos);
329
330 protected:
331
337 virtual int getState() const;
338
345 virtual void setState(int value);
346
358 virtual bool compareAndSetState(int expect, int update);
359
369 virtual bool isHeldExclusively() const;
370
390 virtual bool tryAcquire(int arg);
391
413 virtual int tryAcquireShared(int arg);
414
430 virtual bool tryRelease(int arg);
431
447 virtual bool tryReleaseShared(int arg);
448
457
491
492 friend class SynchronizerState;
493 };
494
495}}}}
496
497#endif /* _DECAF_UTIL_CONCURRENT_LOCKS_ABSTRACTQUEUEDSYNCHRONIZER_H_ */
A Thread is a concurrent unit of execution.
Definition Thread.h:64
The root interface in the collection hierarchy.
Definition Collection.h:69
Condition object for this Synchronizer, which serves as the basis for other Lock objects.
Definition AbstractQueuedSynchronizer.h:55
virtual int getWaitQueueLength() const =0
Calculates and returns an estimate of the number of Threads that are waiting on this Condition object...
virtual bool isOwnedBy(const AbstractQueuedSynchronizer *sync) const =0
Used to check on the ownership status of this ConditionObject.
virtual Collection< decaf::lang::Thread * > * getWaitingThreads() const =0
Retrieves a new Collection object that contains Threads that may be waiting on this Condition object.
friend class AbstractQueuedSynchronizer
Definition AbstractQueuedSynchronizer.h:58
virtual bool hasWaiters() const =0
Returns true if there are any waiters on this Condition object at the time of its calling.
virtual ~ConditionObject()
Definition AbstractQueuedSynchronizer.h:68
virtual void setState(int value)
Sets the synchronization state to the given value.
bool owns(const AbstractQueuedSynchronizer::ConditionObject *condition) const
Checks whether the given ConditionObject uses this Synchronizer as its lock object.
void acquire(int arg)
Acquire the lock exclusively, ignoring interrupts.
virtual int getState() const
Gets and returns the currently set value of this object Synchronization sate.
Collection< decaf::lang::Thread * > * getQueuedThreads() const
Creates and returns a new Collection object that contains a best effort snapshot of the threads that ...
virtual bool tryAcquire(int arg)
Performs the actual work of attempting to acquire the lock in exclusive mode.
Collection< decaf::lang::Thread * > * getExclusiveQueuedThreads() const
Creates and returns a new Collection object that contains only those threads that may be waiting to a...
bool hasQueuedPredecessors() const
Queries whether any threads have been waiting to acquire longer than the current thread.
virtual bool compareAndSetState(int expect, int update)
Sets the synchronization state to the specified value if the current value is equal to the expected v...
std::string toString() const
Gets a string that identifies this Synchronizer along with its present state.
bool hasWaiters(const AbstractQueuedSynchronizer::ConditionObject *condition) const
Returns true if there are any threads that are currently waiting on the given ConditionObject,...
virtual bool tryReleaseShared(int arg)
Performs a release for the calling thread in shared mode.
Collection< decaf::lang::Thread * > * getSharedQueuedThreads() const
Creates and returns a new Collection object that contains only those threads that may be waiting to a...
void acquireInterruptibly(int arg)
Acquire the lock exclusively, allowing for interrupts.
bool isQueued(decaf::lang::Thread *thread) const
Traverse the Queue if waiting threads to see if the given thread is present.
void acquireSharedInterruptibly(int arg)
Acquire the lock in shared mode, allowing interruption.
virtual bool isHeldExclusively() const
If the calling thread hold an exclusive lock on this synchronization then this method returns true,...
virtual bool tryRelease(int arg)
Performs a release for the calling thread in exclusive mode.
bool releaseShared(int arg)
When held in shared mode this method releases the Synchronizer.
virtual ConditionObject * createDefaultConditionObject()
Provides a means for derived classes to create a ConditionObject implemented by the basic logic imple...
friend class SynchronizerState
Definition AbstractQueuedSynchronizer.h:492
virtual int tryAcquireShared(int arg)
Performs the actual work of attempting to acquire the lock in shared mode.
decaf::lang::Thread * getFirstQueuedThread() const
Returns the first thread queue (the thread that's been waiting the longest) if there are currently no...
bool tryAcquireSharedNanos(int arg, long long nanos)
Acquires in shared mode if possible, first checking if the calling thread has already been interrupte...
bool tryAcquireNanos(int arg, long long nanos)
Acquires in exclusive mode if possible, first checking if the calling thread has already been interru...
int getWaitQueueLength(const AbstractQueuedSynchronizer::ConditionObject *condition) const
Gets an estimated count of the number of threads that are currently waiting on the given ConditionObj...
bool release(int arg)
When held in exclusive mode this method releases the Synchronizer.
Collection< decaf::lang::Thread * > * getWaitingThreads(const AbstractQueuedSynchronizer::ConditionObject *condition) const
Creates and returns a new Collection object that contains all the threads that may be waiting on the ...
void acquireShared(int arg)
Acquire the lock in shared mode, ignoring interrupts.
int getQueueLength() const
Gets an estimated count of the number of threads that are currently waiting to acquire,...
Condition factors out the Mutex monitor methods (wait, notify and notifyAll) into distinct objects to...
Definition Condition.h:132
#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