~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

This will now require someone to do a --plugin-add in order to have csv,
archive, or blackhole running.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
 
1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
2
2
 *
3
3
 * PrimeBase Media Stream for MySQL
4
4
 *
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
 *
19
19
 * Original author: Paul McCullagh (H&G2JCtL)
20
20
 * Continued development: Barry Leslie
31
31
#define __CSGLOBAL_H__
32
32
 
33
33
#include "CSDefs.h"
34
 
#include "CSObject.h"
35
34
#include "CSThread.h"
36
35
 
 
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
 
37
48
 
38
49
/* This is the call context: */
39
50
#define CS_CONTEXT                      __FUNC__, __FILE__, __LINE__
49
60
#define ASSERT(x)
50
61
#endif
51
62
 
52
 
#ifdef DEBUG
53
 
#define retain()                        retain(__FUNC__, __FILE__, __LINE__)
54
 
#define release()                       release(__FUNC__, __FILE__, __LINE__)
55
 
#endif
56
 
 
57
63
#define new_(v, t)                      do { v = new t; if (!v) CSException::throwOSError(CS_CONTEXT, ENOMEM); } while (0)
58
64
 
59
65
/*
68
74
 *
69
75
 * It also sets up the current thread pointer 'self'.
70
76
 */
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 ; \
79
78
                                                        do { \
80
79
                                                                if (cs_frame< CS_CALL_STACK_SIZE) { \
81
80
                                                                        self->callStack[cs_frame].cs_func = __FUNC__; \
84
83
                                                                } \
85
84
                                                        } while (0)
86
85
 
87
 
#define outer_()                        self->callTop = cs_frame; \
88
 
                                                        ASSERT(self->relTop == self_reltop); 
 
86
#define outer_()                        self->callTop = cs_frame;
89
87
 
90
88
#define enter_()                        CSThread        *self = CSThread::getSelf(); \
91
89
                                                        inner_()
111
109
 * Throwing and catching (the jump stack)
112
110
 */
113
111
 
 
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
 
114
127
int prof_setjmp(void);
115
128
 
116
129
#define TX_CHK_JMP()            if ((self)->jumpDepth < 0 || (self)->jumpDepth >= CS_JUMP_STACK_SIZE) CSException::throwCoreError(__FUNC__, __FILE__, __LINE__, CS_ERR_JUMP_OVERFLOW)
155
168
                                                                (self)->relTop++; \
156
169
                                                        } while (0)
157
170
 
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
 
 
167
171
#define pop_(r)                         do { \
168
172
                                                                ASSERT((self)->relTop > (self)->relStack); \
169
173
                                                                if (((self)->relTop - 1)->r_type == CS_RELEASE_OBJECT) {\
173
177
                                                                } else if (((self)->relTop - 1)->r_type == CS_RELEASE_POOLED) {\
174
178
                                                                        ASSERT(((self)->relTop - 1)->x.r_pooled == ((CSPooled *) r)); \
175
179
                                                                } else if (((self)->relTop - 1)->r_type == CS_RELEASE_MEM) {\
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))); \
 
180
                                                                        ASSERT(((self)->relTop - 1)->x.r_mem == ((CSPooled *) r)); \
179
181
                                                                }  else {\
180
182
                                                                        ASSERT(false); \
181
183
                                                                } \
201
203
                                                                        ASSERT(mem == (void *)(r)); \
202
204
                                                                        (self)->relTop--; \
203
205
                                                                        cs_free(mem); \
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 {\
 
206
                                                                }  else {\
211
207
                                                                        ASSERT(false); \
212
208
                                                                } \
213
209
                                                        } while (0)
222
218
                                                                (self)->relTop++; \
223
219
                                                        } while (0)
224
220
 
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
 
 
233
221
#define unlock_(r)                      do {  \
234
222
                                                                register CSMutex *rp; \
235
223
                                                                ASSERT((self)->relTop > (self)->relStack); \