/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/sys/apr/Condition.h

00001 #ifndef _sys_apr_Condition_h
00002 #define _sys_apr_Condition_h
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  * 
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  * 
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
00022  *
00023  */
00024 
00025 #include "APRPool.h"
00026 #include "qpid/sys/Mutex.h"
00027 #include "qpid/sys/Time.h"
00028 
00029 #include <sys/errno.h>
00030 #include <boost/noncopyable.hpp>
00031 #include <apr_thread_cond.h>
00032 
00033 namespace qpid {
00034 namespace sys {
00035 
00039 class Condition
00040 {
00041   public:
00042     inline Condition();
00043     inline ~Condition();
00044     inline void wait(Mutex&);
00045     inline bool wait(Mutex&, const AbsTime& absoluteTime);
00046     inline void notify();
00047     inline void notifyAll();
00048 
00049   private:
00050     apr_thread_cond_t* condition;
00051 };
00052 
00053 
00054 Condition::Condition() {
00055     CHECK_APR_SUCCESS(apr_thread_cond_create(&condition, APRPool::get()));
00056 }
00057 
00058 Condition::~Condition() {
00059     CHECK_APR_SUCCESS(apr_thread_cond_destroy(condition));
00060 }
00061 
00062 void Condition::wait(Mutex& mutex) {
00063     CHECK_APR_SUCCESS(apr_thread_cond_wait(condition, mutex.mutex));
00064 }
00065 
00066 bool Condition::wait(Mutex& mutex, const AbsTime& absoluteTime){
00067     // APR uses microseconds.
00068     apr_status_t status =
00069         apr_thread_cond_timedwait(
00070             condition, mutex.mutex, Duration(now(), absoluteTime)/TIME_USEC);
00071     if(status != APR_TIMEUP) CHECK_APR_SUCCESS(status);
00072     return status == 0;
00073 }
00074 
00075 void Condition::notify(){
00076     CHECK_APR_SUCCESS(apr_thread_cond_signal(condition));
00077 }
00078 
00079 void Condition::notifyAll(){
00080     CHECK_APR_SUCCESS(apr_thread_cond_broadcast(condition));
00081 }
00082 
00083 }}
00084 #endif  

Generated on Thu Apr 10 11:08:18 2008 for Qpid by  doxygen 1.4.7