~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSGlobal.h

  • Committer: Lee Bieber
  • Date: 2010-10-22 16:47:38 UTC
  • mfrom: (1841.1.7 drizzle_pbms)
  • Revision ID: kalebral@gmail.com-20101022164738-vv8w22b8towpb307
Merge Barry - fix bug 657830: PBMS build failure in GCC 4.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#define __CSGLOBAL_H__
32
32
 
33
33
#include "CSDefs.h"
 
34
#include "CSObject.h"
34
35
#include "CSThread.h"
35
36
 
36
 
/* Those compilers that support the function
37
 
 * macro (in particular the "pretty" function
38
 
 * macro must be defined here.
39
 
 */
40
 
#ifdef OS_WINDOWS
41
 
#define __FUNC__                                __FUNCTION__
42
 
#elif defined(OS_SOLARIS)
43
 
#define __FUNC__                                "__func__"
44
 
#else
45
 
#define __FUNC__                                __PRETTY_FUNCTION__
46
 
#endif
47
 
 
48
37
 
49
38
/* This is the call context: */
50
39
#define CS_CONTEXT                      __FUNC__, __FILE__, __LINE__
60
49
#define ASSERT(x)
61
50
#endif
62
51
 
 
52
#ifdef DEBUG
 
53
#define retain()                        retain(__FUNC__, __FILE__, __LINE__)
 
54
#define release()                       release(__FUNC__, __FILE__, __LINE__)
 
55
#endif
 
56
 
63
57
#define new_(v, t)                      do { v = new t; if (!v) CSException::throwOSError(CS_CONTEXT, ENOMEM); } while (0)
64
58
 
65
59
/*
74
68
 *
75
69
 * It also sets up the current thread pointer 'self'.
76
70
 */
 
71
#ifdef DEBUG
 
72
#define STACK_CHECK    CSReleasePtr self_reltop = self->relTop
 
73
#else
 
74
#define STACK_CHECK   
 
75
#endif
 
76
 
77
77
#define inner_()                        int                     cs_frame = self->callTop++; \
 
78
                                                        STACK_CHECK ; \
78
79
                                                        do { \
79
80
                                                                if (cs_frame< CS_CALL_STACK_SIZE) { \
80
81
                                                                        self->callStack[cs_frame].cs_func = __FUNC__; \
83
84
                                                                } \
84
85
                                                        } while (0)
85
86
 
86
 
#define outer_()                        self->callTop = cs_frame;
 
87
#define outer_()                        self->callTop = cs_frame; \
 
88
                                                        ASSERT(self->relTop == self_reltop); 
87
89
 
88
90
#define enter_()                        CSThread        *self = CSThread::getSelf(); \
89
91
                                                        inner_()
109
111
 * Throwing and catching (the jump stack)
110
112
 */
111
113
 
112
 
/*
113
 
 * Quote from the C99 spec on setjmp:
114
 
 * All accessible objects have values, and all other components of the abstract 
115
 
 * machine have state, as of the time the longjmp function was called, except that 
116
 
 * the values of objects of automatic storage duration that are local to the function 
117
 
 * containing the invocation of the corresponding setjmp macro that do not have 
118
 
 * volatile-qualified type and have been changed between the setjmp invocation and 
119
 
 * longjmp call are indeterminate. 
120
 
 *
121
 
 * GCC will not put variables into registers for which the address gets taken do use
122
 
 * CLOBBER_PROTECT() to protect variables from being clobbered.
123
 
 * This came from Jens Thoms Toerring. Thanks!
124
 
 */
125
 
#define CLOBBER_PROTECT(a) do { if ((void *)&(a) == (void*) 1) (a) = (a);} while(0)
126
 
 
127
114
int prof_setjmp(void);
128
115
 
129
116
#define TX_CHK_JMP()            if ((self)->jumpDepth < 0 || (self)->jumpDepth >= CS_JUMP_STACK_SIZE) CSException::throwCoreError(__FUNC__, __FILE__, __LINE__, CS_ERR_JUMP_OVERFLOW)
168
155
                                                                (self)->relTop++; \
169
156
                                                        } while (0)
170
157
 
 
158
#define push_ref_(r)                    do { \
 
159
                                                                if ((self)->relTop >= (self)->relStack + CS_RELEASE_STACK_SIZE) {\
 
160
                                                                        CSException::throwCoreError(CS_CONTEXT, CS_ERR_RELEASE_OVERFLOW); \
 
161
                                                                } \
 
162
                                                                (self)->relTop->r_type = CS_RELEASE_OBJECT_PTR; \
 
163
                                                                (self)->relTop->x.r_objectPtr = (CSObject **)&(r); \
 
164
                                                                (self)->relTop++; \
 
165
                                                        } while (0)
 
166
 
171
167
#define pop_(r)                         do { \
172
168
                                                                ASSERT((self)->relTop > (self)->relStack); \
173
169
                                                                if (((self)->relTop - 1)->r_type == CS_RELEASE_OBJECT) {\
177
173
                                                                } else if (((self)->relTop - 1)->r_type == CS_RELEASE_POOLED) {\
178
174
                                                                        ASSERT(((self)->relTop - 1)->x.r_pooled == ((CSPooled *) r)); \
179
175
                                                                } else if (((self)->relTop - 1)->r_type == CS_RELEASE_MEM) {\
180
 
                                                                        ASSERT(((self)->relTop - 1)->x.r_mem == ((CSPooled *) r)); \
 
176
                                                                        ASSERT(((self)->relTop - 1)->x.r_mem == ((void *) r)); \
 
177
                                                                }  else if (((self)->relTop - 1)->r_type == CS_RELEASE_OBJECT_PTR) {\
 
178
                                                                        ASSERT(((self)->relTop - 1)->x.r_objectPtr == ((CSObject **) &(r))); \
181
179
                                                                }  else {\
182
180
                                                                        ASSERT(false); \
183
181
                                                                } \
203
201
                                                                        ASSERT(mem == (void *)(r)); \
204
202
                                                                        (self)->relTop--; \
205
203
                                                                        cs_free(mem); \
206
 
                                                                }  else {\
 
204
                                                                }  else if (((self)->relTop - 1)->r_type == CS_RELEASE_OBJECT_PTR) {\
 
205
                                                                        register CSObject **rp; \
 
206
                                                                        rp = ((self)->relTop - 1)->x.r_objectPtr; \
 
207
                                                                        ASSERT(rp == (CSObject **)&(r)); \
 
208
                                                                        (self)->relTop--; \
 
209
                                                                        if(*rp) (*rp)->release(); \
 
210
                                                                } else {\
207
211
                                                                        ASSERT(false); \
208
212
                                                                } \
209
213
                                                        } while (0)
218
222
                                                                (self)->relTop++; \
219
223
                                                        } while (0)
220
224
 
 
225
#define locked_(r)                      do { \
 
226
                                                                if ((self)->relTop >= (self)->relStack + CS_RELEASE_STACK_SIZE) \
 
227
                                                                        CSException::throwCoreError(CS_CONTEXT, CS_ERR_RELEASE_OVERFLOW); \
 
228
                                                                (self)->relTop->r_type = CS_RELEASE_MUTEX; \
 
229
                                                                (self)->relTop->x.r_mutex = (r); \
 
230
                                                                (self)->relTop++; \
 
231
                                                        } while (0)
 
232
 
221
233
#define unlock_(r)                      do {  \
222
234
                                                                register CSMutex *rp; \
223
235
                                                                ASSERT((self)->relTop > (self)->relStack); \