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 SYNCHRONIZED_H_
00024 #define SYNCHRONIZED_H_
00025
00031 #ifndef __XDISPATCH_INDIRECT__
00032 #error "Please #include <xdispatch/dispatch.h> instead of this file directly."
00033 #endif
00034
00035 #include <string>
00036
00037 __XDISPATCH_BEGIN_NAMESPACE
00038
00043 class XDISPATCH_EXPORT synclock;
00044
00045
00053 class XDISPATCH_EXPORT synclock {
00054
00055 public:
00056 synclock();
00057 synclock(const synclock&);
00058 ~synclock();
00059
00060 operator bool() const;
00061
00062 void unlock();
00063
00064 private:
00065 struct data;
00066 data* _d;
00067
00068 synclock& operator= (synclock);
00069
00070 friend XDISPATCH_EXPORT synclock get_lock_for_key(const std::string&);
00071 friend XDISPATCH_EXPORT synclock get_lock_for_key( dispatch_semaphore_t );
00072 synclock(dispatch_semaphore_t);
00073 };
00074
00075
00079 XDISPATCH_EXPORT void init_semaphore_for_synclock(void*);
00086 XDISPATCH_EXPORT XDISPATCH_DEPRECATED( synclock get_lock_for_key(const std::string& key) );
00090 inline synclock get_lock_for_key( dispatch_semaphore_t sem ){ return synclock(sem); }
00094 inline synclock get_lock_for_key( synclock& s ){ return s; }
00095
00096
00097 # define XDISPATCH_CONCAT(A,B) A ## B
00098 # define XDISPATCH_LOCK_VAR(X) XDISPATCH_CONCAT(xd_synclock_, X)
00099 # define XDISPATCH_LOCK_VAR_SEM(X) XDISPATCH_CONCAT( __xd_synclock_sem_, X)
00100 # define XDISPATCH_LOCK_VAR_ONCE(X) XDISPATCH_CONCAT( __xd_synclock_once_, X)
00101 # define XDISPATCH_SYNC_HEADER( lock ) for( xdispatch::synclock XDISPATCH_LOCK_VAR(__LINE__)(lock) ; XDISPATCH_LOCK_VAR(__LINE__) ; XDISPATCH_LOCK_VAR(__LINE__).unlock() )
00102 # define XDISPATCH_SYNC_DECL( id ) \
00103 static dispatch_semaphore_t XDISPATCH_LOCK_VAR_SEM( id ); \
00104 static dispatch_once_t XDISPATCH_LOCK_VAR_ONCE( id ); \
00105 dispatch_once_f( &XDISPATCH_LOCK_VAR_ONCE( id ), &XDISPATCH_LOCK_VAR_SEM( id ), xdispatch::init_semaphore_for_synclock ); \
00106 XDISPATCH_SYNC_HEADER( xdispatch::get_lock_for_key( XDISPATCH_LOCK_VAR_SEM( id ) ) )
00107
00116 # define XDISPATCH_SYNCHRONIZE( lock ) XDISPATCH_SYNC_HEADER( xdispatch::get_lock_for_key( lock ) )
00117
00126 # define XDISPATCH_SYNCHRONIZED XDISPATCH_SYNC_DECL( __COUNTER__ )
00127
00277 #ifndef XDISPATCH_NO_KEYWORDS
00278 # ifndef synchronize
00279 # define synchronize( lock ) XDISPATCH_SYNCHRONIZE(lock)
00280 # endif
00281
00282 # ifndef synchronized
00283 # define synchronized XDISPATCH_SYNCHRONIZED
00284 # endif
00285 #endif
00286
00287 __XDISPATCH_END_NAMESPACE
00288
00291 #endif