XDispatch 0.6.1
synchronized.h
Go to the documentation of this file.
00001 /*
00002 * Copyright (c) 2011 MLBA. All rights reserved.
00003 *
00004 * @MLBA_OPEN_LICENSE_HEADER_START@
00005 *
00006 * Licensed under the Apache License, Version 2.0 (the "License");
00007 * you may not use this file except in compliance with the License.
00008 * You may obtain a copy of the License at
00009 *
00010 *     http://www.apache.org/licenses/LICENSE-2.0
00011 *
00012 * Unless required by applicable law or agreed to in writing, software
00013 * distributed under the License is distributed on an "AS IS" BASIS,
00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 * See the License for the specific language governing permissions and
00016 * limitations under the License.
00017 *
00018 * @MLBA_OPEN_LICENSE_HEADER_END@
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 __XDISPATCH_BEGIN_NAMESPACE
00031 
00036 class XDISPATCH_EXPORT synclock;
00037 
00044 XDISPATCH_EXPORT synclock get_lock_for_key(unsigned int key);
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(unsigned int);
00071     synclock(dispatch_semaphore_t);
00072 };
00073 
00074 # define XDISPATCH_CONCAT(A,B) A ## B
00075 # define XDISPATCH_LOCK_VAR(X) XDISPATCH_CONCAT(xd_synclock_, X)
00076 
00085 #  define XDISPATCH_SYNCHRONIZE( lock ) for(xdispatch::synclock XDISPATCH_LOCK_VAR(__LINE__)(lock) ; XDISPATCH_LOCK_VAR(__LINE__) ; XDISPATCH_LOCK_VAR(__LINE__).unlock() )
00086 
00095 #  define XDISPATCH_SYNCHRONIZED XDISPATCH_SYNCHRONIZE(xdispatch::get_lock_for_key(__COUNTER__))
00096 
00240 #ifndef XDISPATCH_NO_KEYWORDS
00241 # ifndef synchronize
00242 #  define synchronize( lock ) XDISPATCH_SYNCHRONIZE(lock)
00243 # endif
00244 
00245 # ifndef synchronized
00246 #  define synchronized XDISPATCH_SYNCHRONIZED
00247 # endif
00248 #endif
00249 
00250 __XDISPATCH_END_NAMESPACE
00251 
00252 #endif /* SYNCHRONIZED_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Thu Apr 12 2012 09:50:43 for XDispatch by Doxygen 1.7.4
© 2010-2012 MLBA (about | privacy) All Rights reserved.