Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00105
00106
00107
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