XDispatch 0.7.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
once.h
Go to the documentation of this file.
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_ONCE_H_
00024 #define XDISPATCH_ONCE_H_
00025 
00031 #ifndef __XDISPATCH_INDIRECT__
00032 #error "Please #include <xdispatch/dispatch.h> instead of this file directly."
00033 #endif
00034 
00035 #include <iostream>
00036 
00037 __XDISPATCH_BEGIN_NAMESPACE
00038 
00039 class operation;
00040 
00051 class XDISPATCH_EXPORT once {
00052 
00053     public:
00058         once();
00064         once( dispatch_once_t* );
00065 
00070         dispatch_once_t* native_once() const;
00071 
00083         void operator()(operation&);
00084 #ifdef XDISPATCH_HAS_BLOCKS
00085 
00093         inline void operator()(dispatch_block_t b) {
00094             once_block op(b);
00095             operator()( op );
00096         }
00097 #endif
00098 
00099     private:
00100         dispatch_once_t _once_obj;
00101         dispatch_once_t* _once;
00102 
00103 #ifdef XDISPATCH_HAS_BLOCKS
00104         // we define our own block class
00105         // as the block_operation does a
00106         // copy of the stored block, something
00107         // we do not need in here
00108         class once_block : public operation {
00109             public:
00110                 once_block(dispatch_block_t b)
00111                     : operation(), block( b ) {}
00112 
00113                 void operator()() {
00114                     XDISPATCH_BLOCK_EXEC(block)();
00115                 }
00116 
00117             private:
00118                 dispatch_block_t block;
00119         };
00120 #endif
00121 
00122         friend XDISPATCH_EXPORT std::ostream& operator<<(std::ostream&, const once& );
00123 };
00124 
00125 XDISPATCH_EXPORT std::ostream& operator<<(std::ostream&, const once* );
00126 XDISPATCH_EXPORT std::ostream& operator<<(std::ostream&, const once& );
00127 
00128 __XDISPATCH_END_NAMESPACE
00129 
00132 #endif /* XDISPATCH_ONCE_H_ */

Generated on Tue Jun 12 2012 14:11:47 for XDispatch by Doxygen 1.8.0
© 2010-2012 MLBA (about | privacy) All Rights reserved.