1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
3
* PrimeBase Media Stream for MySQL
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.
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.
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
19
* Original author: Paul McCullagh (H&G2JCtL)
20
* Continued development: Barry Leslie
25
* The definitions are used by all code, and is NOT required
30
#ifndef __CSGLOBAL_H__
31
#define __CSGLOBAL_H__
36
/* Those compilers that support the function
37
* macro (in particular the "pretty" function
38
* macro must be defined here.
41
#define __FUNC__ __PRETTY_FUNCTION__
43
#define __FUNC__ __FUNCTION__
46
/* This is the call context: */
47
#define CS_CONTEXT __FUNC__, __FILE__, __LINE__
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);
53
#define ASSERT(x) ((x) ? 1 : cs_assert(CS_CONTEXT, #x))
54
#define HOPE(x) ((x) ? 1 : cs_hope(CS_CONTEXT, #x))
60
#define new_(v, t) do { v = new t; if (!v) CSException::throwOSError(CS_CONTEXT, ENOMEM); } while (0)
63
* -----------------------------------------------------------------------
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.
72
* It also sets up the current thread pointer 'self'.
74
#define inner_() int cs_frame = self->callTop++; \
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__; \
83
#define outer_() self->callTop = cs_frame;
85
#define enter_() CSThread *self = CSThread::getSelf(); \
89
* On exit to a function, either exit_() or
90
* return_() must be called.
92
#define exit_() do { \
98
#define return_(x) do { \
105
* -----------------------------------------------------------------------
106
* Throwing and catching (the jump stack)
109
int prof_setjmp(void);
111
#define TX_CHK_JMP() if ((self)->jumpDepth < 0 || (self)->jumpDepth >= CS_JUMP_STACK_SIZE) CSException::throwCoreError(__FUNC__, __FILE__, __LINE__, CS_ERR_JUMP_OVERFLOW)
113
#define profile_setjmp prof_setjmp()
115
#define profile_setjmp
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:
129
* -----------------------------------------------------------------------
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); \
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)); \
148
ASSERT(((self)->relTop - 1)->x.r_pooled == ((CSPooled *) r)); \
152
#define retain_(r) do { \
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; \
167
#define lock_(r) do { \
168
if ((self)->relTop >= (self)->relStack + CS_RELEASE_STACK_SIZE) \
169
CSException::throwCoreError(CS_CONTEXT, CS_ERR_RELEASE_OVERFLOW); \
171
(self)->relTop->r_type = CS_RELEASE_MUTEX; \
172
(self)->relTop->x.r_mutex = (r); \
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; \
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); \
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; \
201
rp->returnToPool(); \