activemq-cpp-3.4.0

src/main/decaf/util/concurrent/Semaphore.h

Go to the documentation of this file.
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_SEMAPHORE_H_
00019 #define _DECAF_UTIL_CONCURRENT_SEMAPHORE_H_
00020 
00021 #include <decaf/util/Config.h>
00022 
00023 #include <decaf/lang/exceptions/InterruptedException.h>
00024 #include <decaf/lang/exceptions/RuntimeException.h>
00025 #include <decaf/lang/exceptions/IllegalArgumentException.h>
00026 
00027 #include <decaf/util/concurrent/TimeUnit.h>
00028 
00029 #include <memory>
00030 
00031 namespace decaf {
00032 namespace util {
00033 namespace concurrent {
00034 
00035     class SemaphoreHandle;
00036 
00142     class DECAF_API Semaphore {
00143     private:
00144 
00145         std::auto_ptr<SemaphoreHandle> handle;
00146 
00147     private:
00148 
00149         Semaphore( const Semaphore& );
00150         Semaphore& operator= ( const Semaphore& );
00151 
00152     public:
00153 
00160         Semaphore( int permits );
00161 
00170         Semaphore( int permits, bool fair );
00171 
00172         virtual ~Semaphore();
00173 
00198         void acquire();
00199 
00217         void acquireUninterruptibly();
00218 
00237         bool tryAcquire();
00238 
00275         bool tryAcquire( long long timeout, const TimeUnit& unit );
00276 
00290         void release();
00291 
00322         void acquire( int permits );
00323 
00344         void acquireUninterruptibly( int permits );
00345 
00370         bool tryAcquire( int permits );
00371 
00414         bool tryAcquire( int permits, long long timeout, const TimeUnit& unit );
00415 
00432         void release( int permits );
00433 
00441         int availablePermits() const;
00442 
00450         int drainPermits();
00451 
00455         bool isFair() const;
00456 
00463         std::string toString() const;
00464 
00465     };
00466 
00467 }}}
00468 
00469 #endif /* _DECAF_UTIL_CONCURRENT_SEMAPHORE_H_ */