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_CONDITION_H_ 00019 #define _DECAF_UTIL_CONCURRENT_LOCKS_CONDITION_H_ 00020 00021 #include <decaf/util/Config.h> 00022 00023 #include <decaf/util/Date.h> 00024 #include <decaf/util/concurrent/TimeUnit.h> 00025 #include <decaf/lang/exceptions/RuntimeException.h> 00026 #include <decaf/lang/exceptions/InterruptedException.h> 00027 #include <decaf/lang/exceptions/IllegalMonitorStateException.h> 00028 00029 namespace decaf { 00030 namespace util { 00031 namespace concurrent { 00032 namespace locks { 00033 00132 class DECAF_API Condition { 00133 public: 00134 00135 virtual ~Condition(); 00136 00185 virtual void await() = 0; 00186 00221 virtual void awaitUninterruptibly() = 0; 00222 00303 virtual long long awaitNanos(long long nanosTimeout) = 0; 00304 00327 virtual bool await(long long time, const TimeUnit& unit) = 0; 00328 00329 /* 00330 * Causes the current thread to wait until it is signaled or interrupted, or the 00331 * specified deadline elapses. 00332 * 00333 * The lock associated with this condition is atomically released and the current 00334 * thread becomes disabled for thread scheduling purposes and lies dormant until one 00335 * of five things happens: 00336 * 00337 * * Some other thread invokes the signal() method for this Condition and the 00338 * current thread happens to be chosen as the thread to be awakened; or 00339 * * Some other thread invokes the signalAll() method for this Condition; or 00340 * * Some other thread interrupts the current thread, and interruption of thread 00341 * suspension is supported; or 00342 * * The specified deadline elapses; or 00343 * * A "spurious wakeup" occurs. 00344 * 00345 * In all cases, before this method can return the current thread must re-acquire the 00346 * lock associated with this condition. When the thread returns it is guaranteed to 00347 * hold this lock. 00348 * 00349 * If the current thread: 00350 * 00351 * * has its interrupted status set on entry to this method; or 00352 * * is interrupted while waiting and interruption of thread suspension is supported, 00353 * 00354 * then InterruptedException is thrown and the current thread's interrupted status is 00355 * cleared. It is not specified, in the first case, whether or not the test for 00356 * interruption occurs before the lock is released. 00357 * 00358 * The return value indicates whether the deadline has elapsed, which can be used as 00359 * follows: 00360 * 00361 * bool aMethod( const Date& deadline ) { 00362 * bool stillWaiting = true; 00363 * while (!conditionBeingWaitedFor) { 00364 * if (stillWaiting) 00365 * stillWaiting = theCondition->awaitUntil(deadline); 00366 * else 00367 * return false; 00368 * } 00369 * // ... 00370 * } 00371 * 00372 * Implementation Considerations 00373 * 00374 * The current thread is assumed to hold the lock associated with this Condition when 00375 * this method is called. It is up to the implementation to determine if this is the 00376 * case and if not, how to respond. Typically, an exception will be thrown (such as 00377 * IllegalMonitorStateException) and the implementation must document that fact. 00378 * 00379 * An implementation can favor responding to an interrupt over normal method return 00380 * in response to a signal, or over indicating the passing of the specified deadline. 00381 * In either case the implementation must ensure that the signal is redirected to 00382 * another waiting thread, if there is one. 00383 * 00384 * @param deadline - the absolute time to wait until 00385 * 00386 * @returns false if the deadline has elapsed upon return, else true 00387 * 00388 * @throws RuntimeException 00389 * if an unexpected error occurs while trying to wait on the Condition. 00390 * 00391 * @throws InterruptedException 00392 * if the current thread is interrupted (and interruption of thread suspension 00393 * is supported) 00394 * 00395 * @throws IllegalMonitorStateException 00396 * if the caller is not the lock owner. 00397 */ 00398 virtual bool awaitUntil(const Date& deadline) = 0; 00399 00409 virtual void signal() = 0; 00410 00420 virtual void signalAll() = 0; 00421 00422 }; 00423 00424 }}}} 00425 00426 #endif /*_DECAF_UTIL_CONCURRENT_LOCKS_CONDITION_H_*/
1.6.1