00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #ifndef _DECAF_UTIL_CONCURRENT_LOCKS_ABSTRACTQUEUEDSYNCHRONIZER_H_ 00019 #define _DECAF_UTIL_CONCURRENT_LOCKS_ABSTRACTQUEUEDSYNCHRONIZER_H_ 00020 00021 #include <decaf/util/Config.h> 00022 00023 #include <decaf/util/concurrent/locks/AbstractOwnableSynchronizer.h> 00024 #include <decaf/util/concurrent/locks/Condition.h> 00025 #include <decaf/util/Collection.h> 00026 #include <decaf/lang/Thread.h> 00027 00028 namespace decaf { 00029 namespace util { 00030 namespace concurrent { 00031 namespace locks { 00032 00033 class SynchronizerState; 00034 00035 class DECAF_API AbstractQueuedSynchronizer : public AbstractOwnableSynchronizer { 00036 private: 00037 00038 SynchronizerState* impl; 00039 00040 private: 00041 00042 AbstractQueuedSynchronizer(const AbstractQueuedSynchronizer&); 00043 AbstractQueuedSynchronizer& operator= (const AbstractQueuedSynchronizer&); 00044 00045 protected: 00046 00047 AbstractQueuedSynchronizer(); 00048 00049 public: 00050 00055 class ConditionObject : public Condition { 00056 private: 00057 00058 friend class AbstractQueuedSynchronizer; 00059 00060 private: 00061 00062 ConditionObject(const ConditionObject&); 00063 ConditionObject& operator= (const ConditionObject&); 00064 00065 public: 00066 00067 ConditionObject() : Condition() {} 00068 virtual ~ConditionObject() {} 00069 00070 protected: 00071 00077 virtual bool isOwnedBy(const AbstractQueuedSynchronizer* sync) const = 0; 00078 00085 virtual bool hasWaiters() const = 0; 00086 00093 virtual int getWaitQueueLength() const = 0; 00094 00101 virtual Collection<decaf::lang::Thread*>* getWaitingThreads() const = 0; 00102 }; 00103 00104 public: 00105 00106 virtual ~AbstractQueuedSynchronizer(); 00107 00116 void acquire(int arg); 00117 00126 void acquireShared(int arg); 00127 00139 void acquireInterruptibly(int arg); 00140 00151 void acquireSharedInterruptibly(int arg); 00152 00160 Collection<decaf::lang::Thread*>* getExclusiveQueuedThreads() const; 00161 00169 Collection<decaf::lang::Thread*>* getSharedQueuedThreads() const; 00170 00177 decaf::lang::Thread* getFirstQueuedThread() const; 00178 00186 Collection<decaf::lang::Thread*>* getQueuedThreads() const; 00187 00195 int getQueueLength() const; 00196 00208 Collection<decaf::lang::Thread*>* getWaitingThreads(const AbstractQueuedSynchronizer::ConditionObject* condition) const; 00209 00222 int getWaitQueueLength(const AbstractQueuedSynchronizer::ConditionObject* condition) const; 00223 00227 bool hasContended() const; 00228 00232 bool hasQueuedThreads() const; 00233 00244 bool hasWaiters(const AbstractQueuedSynchronizer::ConditionObject* condition) const; 00245 00253 bool isQueued(decaf::lang::Thread* thread) const; 00254 00262 bool owns(const AbstractQueuedSynchronizer::ConditionObject* condition) const; 00263 00274 bool release(int arg); 00275 00286 bool releaseShared(int arg); 00287 00296 std::string toString() const; 00297 00312 bool tryAcquireNanos(int arg, long long nanos); 00313 00328 bool tryAcquireSharedNanos(int arg, long long nanos); 00329 00330 protected: 00331 00337 virtual int getState() const; 00338 00345 virtual void setState(int value); 00346 00358 virtual bool compareAndSetState(int expect, int update); 00359 00369 virtual bool isHeldExclusively() const; 00370 00390 virtual bool tryAcquire(int arg); 00391 00413 virtual int tryAcquireShared(int arg); 00414 00430 virtual bool tryRelease(int arg); 00431 00447 virtual bool tryReleaseShared(int arg); 00448 00456 virtual ConditionObject* createDefaultConditionObject(); 00457 00490 bool hasQueuedPredecessors() const; 00491 00492 friend class SynchronizerState; 00493 }; 00494 00495 }}}} 00496 00497 #endif /* _DECAF_UTIL_CONCURRENT_LOCKS_ABSTRACTQUEUEDSYNCHRONIZER_H_ */
1.6.1