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
00026 #ifndef __XDISPATCH_INDIRECT__
00027 #error "Please #include <xdispatch/dispatch.h> instead of this file directly."
00028 #endif
00029
00030 #include "dispatch.h"
00031
00032 __XDISPATCH_BEGIN_NAMESPACE
00033
00038 class XDISPATCH_EXPORT synclock;
00039
00046 XDISPATCH_EXPORT synclock get_lock_for_key(unsigned int key);
00047
00055 class XDISPATCH_EXPORT synclock {
00056
00057 public:
00058 synclock();
00059 synclock(const synclock&);
00060 ~synclock();
00061
00062 operator bool() const;
00063
00064 void unlock();
00065
00066 private:
00067 dispatch_semaphore_t sem;
00068 bool lock;
00069
00070 synclock& operator= (synclock);
00071
00072 friend synclock get_lock_for_key(unsigned int);
00073 synclock(dispatch_semaphore_t);
00074 };
00075
00076 # define XDISPATCH_CONCAT(A,B) A ## B
00077 # define XDISPATCH_LOCK_VAR(X) XDISPATCH_CONCAT(xd_synclock_, X)
00078
00087 # define XDISPATCH_SYNCHRONIZE( lock ) for(xdispatch::synclock XDISPATCH_LOCK_VAR(__LINE__)(lock) ; XDISPATCH_LOCK_VAR(__LINE__) ; XDISPATCH_LOCK_VAR(__LINE__).unlock() )
00088
00097 # define XDISPATCH_SYNCHRONIZED XDISPATCH_SYNCHRONIZE(xdispatch::get_lock_for_key(__COUNTER__))
00098
00242 #ifndef XDISPATCH_NO_KEYWORDS
00243 # ifndef synchronize
00244 # define synchronize( lock ) XDISPATCH_SYNCHRONIZE(lock)
00245 # endif
00246
00247 # ifndef synchronized
00248 # define synchronized XDISPATCH_SYNCHRONIZED
00249 # endif
00250 #endif
00251
00252 __XDISPATCH_END_NAMESPACE
00253
00254 #endif