~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Added the PBMS daemon plugin.

(Augen zu und durch!)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
 
2
 *
 
3
 * PrimeBase Media Stream for MySQL
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
18
 *
 
19
 * Original author: Paul McCullagh (H&G2JCtL)
 
20
 * Continued development: Barry Leslie
 
21
 *
 
22
 * 2007-05-20
 
23
 *
 
24
 * CORE SYSTEM:
 
25
 * The definitions are used by all code, and is NOT required
 
26
 * by any header file!
 
27
 *
 
28
 */
 
29
 
 
30
#ifndef __CSGLOBAL_H__
 
31
#define __CSGLOBAL_H__
 
32
 
 
33
#include "CSDefs.h"
 
34
#include "CSThread.h"
 
35
 
 
36
/* Those compilers that support the function
 
37
 * macro (in particular the "pretty" function
 
38
 * macro must be defined here.
 
39
 */
 
40
#ifdef __MWERKS__
 
41
#define __FUNC__                        __PRETTY_FUNCTION__
 
42
#else
 
43
#define __FUNC__                        __FUNCTION__
 
44
#endif
 
45
 
 
46
/* This is the call context: */
 
47
#define CS_CONTEXT                      __FUNC__, __FILE__, __LINE__
 
48
 
 
49
#ifdef DEBUG
 
50
int cs_assert(const char *func, const char *file, int line, const char *message);
 
51
int cs_hope(const char *func, const char *file, int line, const char *message);
 
52
 
 
53
#define ASSERT(x)                       ((x) ? 1 : cs_assert(CS_CONTEXT, #x))
 
54
#define HOPE(x)                         ((x) ? 1 : cs_hope(CS_CONTEXT, #x))
 
55
#else
 
56
#define ASSERT(x)
 
57
#define ASSERT(x)
 
58
#endif
 
59
 
 
60
#define new_(v, t)                      do { v = new t; if (!v) CSException::throwOSError(CS_CONTEXT, ENOMEM); } while (0)
 
61
 
 
62
/*
 
63
 * -----------------------------------------------------------------------
 
64
 * Call stack
 
65
 */
 
66
 
 
67
/*
 
68
 * This macro must be placed at the start of every function.
 
69
 * It records the current context so that we can
 
70
 * dump a type of stack trace later if necessary.
 
71
 *
 
72
 * It also sets up the current thread pointer 'self'.
 
73
 */
 
74
#define inner_()                        int                     cs_frame = self->callTop++; \
 
75
                                                        do { \
 
76
                                                                if (cs_frame< CS_CALL_STACK_SIZE) { \
 
77
                                                                        self->callStack[cs_frame].cs_func = __FUNC__; \
 
78
                                                                        self->callStack[cs_frame].cs_file = __FILE__; \
 
79
                                                                        self->callStack[cs_frame].cs_line = __LINE__; \
 
80
                                                                } \
 
81
                                                        } while (0)
 
82
 
 
83
#define outer_()                        self->callTop = cs_frame;
 
84
 
 
85
#define enter_()                        CSThread        *self = CSThread::getSelf(); \
 
86
                                                        inner_()
 
87
 
 
88
/*
 
89
 * On exit to a function, either exit_() or
 
90
 * return_() must be called.
 
91
 */
 
92
#define exit_()                         do { \
 
93
                                                                outer_(); \
 
94
                                                                return; \
 
95
                                                        } while (0)
 
96
                                        
 
97
 
 
98
#define return_(x)                      do { \
 
99
                                                                outer_(); \
 
100
                                                                return(x); \
 
101
                                                        } while (0)
 
102
 
 
103
 
 
104
/*
 
105
 * -----------------------------------------------------------------------
 
106
 * Throwing and catching (the jump stack)
 
107
 */
 
108
 
 
109
int prof_setjmp(void);
 
110
 
 
111
#define TX_CHK_JMP()            if ((self)->jumpDepth < 0 || (self)->jumpDepth >= CS_JUMP_STACK_SIZE) CSException::throwCoreError(__FUNC__, __FILE__, __LINE__, CS_ERR_JUMP_OVERFLOW)
 
112
#ifdef PROFILE
 
113
#define profile_setjmp          prof_setjmp()
 
114
#else
 
115
#define profile_setjmp                  
 
116
#endif
 
117
 
 
118
#define throw_()                        (self)->throwException()
 
119
#define try_(n)                         int throw_##n; throw_##n = 0; TX_CHK_JMP(); \
 
120
                                                        (self)->jumpEnv[(self)->jumpDepth].jb_res_top = (self)->relTop; \
 
121
                                                        (self)->jumpEnv[(self)->jumpDepth].jb_call_top = (self)->callTop; \
 
122
                                                        (self)->jumpDepth++; profile_setjmp; \
 
123
                                                        if (setjmp((self)->jumpEnv[(self)->jumpDepth-1].jb_buffer)) goto catch_##n;
 
124
#define catch_(n)                       (self)->jumpDepth--; goto cont_##n; catch_##n: (self)->jumpDepth--; self->caught();
 
125
#define finally_(n)                     (self)->jumpDepth--; goto final_##n; catch_##n: throw_##n = 1; (self)->jumpDepth--; self->caught(); final_##n:
 
126
#define cont_(n)                        if (throw_##n) throw_(); cont_##n:
 
127
 
 
128
/*
 
129
 * -----------------------------------------------------------------------
 
130
 * The release stack
 
131
 */
 
132
 
 
133
#define push_(r)                        do { \
 
134
                                                                if ((self)->relTop >= (self)->relStack + CS_RELEASE_STACK_SIZE) \
 
135
                                                                        CSException::throwCoreError(CS_CONTEXT, CS_ERR_RELEASE_OVERFLOW); \
 
136
                                                                (self)->relTop->r_type = CS_RELEASE_OBJECT; \
 
137
                                                                (self)->relTop->x.r_object = (r); \
 
138
                                                                (self)->relTop++; \
 
139
                                                        } while (0)
 
140
 
 
141
#define pop_(r)                         do { \
 
142
                                                                ASSERT((self)->relTop > (self)->relStack); \
 
143
                                                                if (((self)->relTop - 1)->r_type == CS_RELEASE_OBJECT) \
 
144
                                                                        ASSERT(((self)->relTop - 1)->x.r_object == ((CSObject *) r)); \
 
145
                                                                else if (((self)->relTop - 1)->r_type == CS_RELEASE_MUTEX) \
 
146
                                                                        ASSERT(((self)->relTop - 1)->x.r_mutex == ((CSMutex *) r)); \
 
147
                                                                else \
 
148
                                                                        ASSERT(((self)->relTop - 1)->x.r_pooled == ((CSPooled *) r)); \
 
149
                                                                (self)->relTop--; \
 
150
                                                        } while (0)
 
151
 
 
152
#define retain_(r)                      do { \
 
153
                                                                (r)->retain(); \
 
154
                                                                push_(r); \
 
155
                                                        } while (0)
 
156
 
 
157
#define release_(r)                     do {  \
 
158
                                                                register CSObject *rp; \
 
159
                                                                ASSERT((self)->relTop > (self)->relStack); \
 
160
                                                                ASSERT(((self)->relTop - 1)->r_type == CS_RELEASE_OBJECT); \
 
161
                                                                rp = ((self)->relTop - 1)->x.r_object; \
 
162
                                                                ASSERT(rp == (r)); \
 
163
                                                                (self)->relTop--; \
 
164
                                                                rp->release(); \
 
165
                                                        } while (0)
 
166
 
 
167
#define lock_(r)                        do { \
 
168
                                                                if ((self)->relTop >= (self)->relStack + CS_RELEASE_STACK_SIZE) \
 
169
                                                                        CSException::throwCoreError(CS_CONTEXT, CS_ERR_RELEASE_OVERFLOW); \
 
170
                                                                (r)->lock(); \
 
171
                                                                (self)->relTop->r_type = CS_RELEASE_MUTEX; \
 
172
                                                                (self)->relTop->x.r_mutex = (r); \
 
173
                                                                (self)->relTop++; \
 
174
                                                        } while (0)
 
175
 
 
176
#define unlock_(r)                      do {  \
 
177
                                                                register CSMutex *rp; \
 
178
                                                                ASSERT((self)->relTop > (self)->relStack); \
 
179
                                                                ASSERT(((self)->relTop - 1)->r_type == CS_RELEASE_MUTEX); \
 
180
                                                                rp = ((self)->relTop - 1)->x.r_mutex; \
 
181
                                                                ASSERT(rp == (r)); \
 
182
                                                                (self)->relTop--; \
 
183
                                                                rp->unlock(); \
 
184
                                                        } while (0)
 
185
 
 
186
#define frompool_(r)            do { \
 
187
                                                                if ((self)->relTop >= (self)->relStack + CS_RELEASE_STACK_SIZE) \
 
188
                                                                        CSException::throwCoreError(CS_CONTEXT, CS_ERR_RELEASE_OVERFLOW); \
 
189
                                                                (self)->relTop->r_type = CS_RELEASE_POOLED; \
 
190
                                                                (self)->relTop->x.r_pooled = (r); \
 
191
                                                                (self)->relTop++; \
 
192
                                                        } while (0)
 
193
 
 
194
#define backtopool_(r)          do {  \
 
195
                                                                register CSPooled *rp; \
 
196
                                                                ASSERT((self)->relTop > (self)->relStack); \
 
197
                                                                ASSERT(((self)->relTop - 1)->r_type == CS_RELEASE_POOLED); \
 
198
                                                                rp = ((self)->relTop - 1)->x.r_pooled; \
 
199
                                                                ASSERT(rp == (r)); \
 
200
                                                                (self)->relTop--; \
 
201
                                                                rp->returnToPool(); \
 
202
                                                        } while (0)
 
203
 
 
204
#endif