ZFFramework
 
Loading...
Searching...
No Matches
zfsynchronize.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_zfsynchronize_h_
7#define _ZFI_zfsynchronize_h_
8
9#include "ZFObjectCore.h"
10#include "zfany.h"
12
13// internal test
14// #define _ZFP_ZFSYNCHRONIZE_LOG_ENABLE 1
15
16// ============================================================
32#if _ZFP_ZFSYNCHRONIZE_LOG_ENABLE
33 #define zfsynchronize(obj) \
34 _ZFP_zfsynchronizeContainerWithLog ZFUniqueName(zfsynchronize_holder)(obj \
35 , ZFCallerInfoCreate())
36#else
37 #define zfsynchronize(obj) \
38 _ZFP_zfsynchronizeContainer ZFUniqueName(zfsynchronize_holder)(obj)
39#endif
40
54#if _ZFP_ZFSYNCHRONIZE_LOG_ENABLE
55 #define zfsynchronizeLock(obj) _ZFP_zfsynchronizeLockWithLog(obj \
56 , ZFCallerInfoCreate())
57#else
58 #define zfsynchronizeLock(obj) _ZFP_zfsynchronizeLock(obj)
59#endif
60
64#if _ZFP_ZFSYNCHRONIZE_LOG_ENABLE
65 #define zfsynchronizeUnlock(obj) _ZFP_zfsynchronizeUnlockWithLog(obj \
66 , ZFCallerInfoCreate())
67#else
68 #define zfsynchronizeUnlock(obj) _ZFP_zfsynchronizeUnlock(obj)
69#endif
70
71// ============================================================
72// no log version
73zffinal zfclassNotPOD ZFLIB_ZFCore _ZFP_zfsynchronizeContainer {
74public:
75 _ZFP_zfsynchronizeContainer(ZF_IN zfany const &obj)
76 : m_obj(obj)
77 {
78 m_obj->_ZFP_ZFObjectLock();
79 }
80 ~_ZFP_zfsynchronizeContainer(void) {
81 m_obj->_ZFP_ZFObjectUnlock();
82 }
83private:
84 ZFObject *m_obj;
85};
86
87inline void _ZFP_zfsynchronizeLock(ZF_IN zfany const &obj) {
88 obj->_ZFP_ZFObjectLock();
89}
90inline void _ZFP_zfsynchronizeUnlock(ZF_IN zfany const &obj) {
91 obj->_ZFP_ZFObjectUnlock();
92}
93
94// ============================================================
95// log version
96#if _ZFP_ZFSYNCHRONIZE_LOG_ENABLE
97zffinal zfclassNotPOD ZFLIB_ZFCore _ZFP_zfsynchronizeContainerWithLog {
98public:
99 _ZFP_zfsynchronizeContainerWithLog(
100 ZF_IN zfany const &obj
101 , ZF_IN const ZFCallerInfo &callerInfo
102 );
103 ~_ZFP_zfsynchronizeContainerWithLog(void);
104private:
105 ZFObject *m_obj;
106 ZFCallerInfo callerInfo;
107};
108
109extern ZFLIB_ZFCore void _ZFP_zfsynchronizeLockWithLog(
110 ZF_IN zfany const &obj
111 , ZF_IN const ZFCallerInfo &callerInfo
112 );
113extern ZFLIB_ZFCore void _ZFP_zfsynchronizeUnlockWithLog(
114 ZF_IN zfany const &obj
115 , ZF_IN const ZFCallerInfo &callerInfo
116 );
117#endif // #if _ZFP_ZFSYNCHRONIZE_LOG_ENABLE
118
120#endif // #ifndef _ZFI_zfsynchronize_h_
121
#define ZFLIB_ZFCore
used to export symbols
Definition ZFCoreEnvDef.h:30
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define zfclassNotPOD
shows the class is not a POD type, you should not memset it or declare it in stack or copy value by c...
Definition ZFCoreTypeDef_ClassType.h:48
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
base class of all objects
util class to hold caller info
Definition ZFCallerInfo.h:63
base class of all objects
Definition ZFObjectCore.h:209
util method to cast ZFObject types freely
Definition zfany.h:35
util class to cast ZFObject types freely