00001 00002 /* 00003 * Copyright (c) 2011-2012 MLBA-Team. All rights reserved. 00004 * 00005 * @MLBA_OPEN_LICENSE_HEADER_START@ 00006 * 00007 * Licensed under the Apache License, Version 2.0 (the "License"); 00008 * you may not use this file except in compliance with the License. 00009 * You may obtain a copy of the License at 00010 * 00011 * http://www.apache.org/licenses/LICENSE-2.0 00012 * 00013 * Unless required by applicable law or agreed to in writing, software 00014 * distributed under the License is distributed on an "AS IS" BASIS, 00015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00016 * See the License for the specific language governing permissions and 00017 * limitations under the License. 00018 * 00019 * @MLBA_OPEN_LICENSE_HEADER_END@ 00020 */ 00021 00022 00023 #ifndef XDISPATCH_SEMAPHORE_H_ 00024 #define XDISPATCH_SEMAPHORE_H_ 00025 00031 #ifndef __XDISPATCH_INDIRECT__ 00032 #error "Please #include <xdispatch/dispatch.h> instead of this file directly." 00033 #endif 00034 00035 #include <memory> 00036 00037 __XDISPATCH_BEGIN_NAMESPACE 00038 00047 class XDISPATCH_EXPORT semaphore { 00048 00049 public: 00061 semaphore(int = 1); 00066 semaphore(dispatch_semaphore_t); 00067 semaphore(const semaphore&); 00068 ~semaphore(); 00069 00079 int release(); 00087 void acquire(); 00097 bool try_acquire(dispatch_time_t); 00107 bool try_acquire(struct tm*); 00113 const dispatch_semaphore_t native_semaphore() const; 00114 00115 semaphore& operator=(const semaphore&); 00116 bool operator ==(const semaphore&); 00117 bool operator ==(const dispatch_semaphore_t&); 00118 bool operator !=(const semaphore&); 00119 bool operator !=(const dispatch_semaphore_t&); 00120 00121 private: 00122 class data; 00123 pointer<data>::unique d; 00124 00125 }; 00126 00127 XDISPATCH_EXPORT std::ostream& operator<<(std::ostream&, const semaphore*); 00128 XDISPATCH_EXPORT std::ostream& operator<<(std::ostream&, const semaphore&); 00129 00130 XDISPATCH_EXPORT bool operator ==(const dispatch_semaphore_t&, const semaphore&); 00131 XDISPATCH_EXPORT bool operator !=(const dispatch_semaphore_t&, const semaphore&); 00132 00133 __XDISPATCH_END_NAMESPACE 00134 00137 #endif /* XDISPATCH_SEMAPHORE_H_ */