~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: patrick crews
  • Date: 2010-09-29 15:15:19 UTC
  • mfrom: (1099.4.188 drizzle)
  • Revision ID: gleebix@gmail.com-20100929151519-6mrmzd1ciw2p9nws
Tags: 2010.09.1802
Update translations

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
35
35
#include "CSDefs.h"
36
36
#include "CSMutex.h"
37
37
#include "CSException.h"
38
 
#include "CSObject.h"
39
38
#include "CSStorage.h"
40
39
 
 
40
using namespace std;
 
41
 
41
42
#define CS_THREAD_TYPE                          int
42
43
 
43
44
/* Types of threads: */
58
59
#define CS_RELEASE_MUTEX                2
59
60
#define CS_RELEASE_POOLED               3
60
61
#define CS_RELEASE_MEM                  4
61
 
#define CS_RELEASE_OBJECT_PTR   5
62
62
 
63
63
typedef struct CSRelease {
64
64
        int                                             r_type;
67
67
                CSMutex                         *r_mutex;                                       /* The mutex to be unlocked! */
68
68
                CSPooled                        *r_pooled;
69
69
                void                            *r_mem;
70
 
                CSObject                        **r_objectPtr;
71
70
        } x;
72
71
} CSReleaseRec, *CSReleasePtr;
73
72
 
125
124
        /* Set to true when the thread must quit (never reset!): */
126
125
        bool                    myMustQuit;     
127
126
        
128
 
        CSException             myException;
129
 
#if defined(MYSQL_SERVER) ||  defined(DRIZZLED)
130
 
 
131
127
        /* Set to true when this tread was initialized through the internal PBMS api. */
132
128
        /* When this is the case than it must only be freed via the API as well. */
133
129
        bool                    pbms_api_owner;
134
130
 
 
131
        CSException             myException;
 
132
 
135
133
        /* Transaction references. */
136
134
#ifdef DRIZZLED
137
135
        CSSortedList    mySavePoints;
138
136
#endif
139
 
        uint32_t                myTID;                  // Current transaction ID
140
 
        uint32_t                myTransRef;             // Reference to the current transaction cache index
 
137
        uint32_t                        myTID;                  // Current transaction ID
 
138
        uint32_t                        myTransRef;             // Reference to the current transaction cache index
141
139
        bool                    myIsAutoCommit; // Is the current transaction in auto commit mode.
142
 
        uint32_t                myCacheVersion; // The last transaction cache version checked. Used during overflow.
 
140
        uint32_t                        myCacheVersion; // The last transaction cache version checked. Used during overflow.
143
141
        bool                    myStartTxn;             // A flag to indicate the start of a new transaction.
144
 
        uint32_t                myStmtCount;    // Counts the number of statements in the current transaction.
145
 
        uint32_t                myStartStmt;    // The myStmtCount at the start of the last logical statement. (An update is 2 statements but only 1 logical statement.)
146
 
        void                    *myInfo;
147
 
#endif
 
142
        uint32_t                        myStmtCount;    // Counts the number of statements in the current transaction.
 
143
        uint32_t                        myStartStmt;    // The myStmtCount at the start of the last logical statement. (An update is 2 statements but only 1 logical statement.)
 
144
        void                    *myInfo;                // A place to hang some info. (Be carefull with this!)
148
145
        
149
146
        /* The call stack */
150
147
        int                             callTop;
166
163
                ignoreSignals(false),
167
164
                isRunning(false),
168
165
                myMustQuit(false),
169
 
#if defined(MYSQL_SERVER) ||  defined(DRIZZLED)
170
166
                pbms_api_owner(false),
171
167
                myTID(0),
172
168
                myTransRef(0),
176
172
                myStmtCount(0),
177
173
                myStartStmt(0),
178
174
                myInfo(NULL),
179
 
#endif
180
175
                callTop(0),
181
176
                jumpDepth(0),
182
177
                relTop(relStack),
183
178
                iIsMain(false),
184
 
                isDetached(false),
185
179
                iRunFunc(NULL),
186
180
                iNextLink(NULL),
187
181
                iPrevLink(NULL)
205
199
         *
206
200
     * @exception CSSystemException thrown if thread is invalid.
207
201
         */
208
 
        void start(bool detached = false);
 
202
        void start();
209
203
 
210
204
        /*
211
205
         * Stop execution of the thread.
256
250
        void releaseObjects(CSReleasePtr top);
257
251
        void throwException();
258
252
        void caught();
259
 
        bool isMe(CSThread *me) { return (pthread_equal(me->iThread,iThread) != 0);}
 
253
        bool isMe(CSThread *me) { return (me->iThread == iThread);}
260
254
        /* Make this object linkable: */
261
255
        virtual CSObject *getNextLink() { return iNextLink; }
262
256
        virtual CSObject *getPrevLink() { return iPrevLink; }
268
262
private:
269
263
        pthread_t               iThread;
270
264
        bool                    iIsMain;
271
 
        bool                    isDetached;
272
265
        ThreadRunFunc   iRunFunc;
273
266
        CSObject                *iNextLink;
274
267
        CSObject                *iPrevLink;
325
318
 
326
319
        virtual void *run();
327
320
 
328
 
        /* Return false if startup failed, and the thread must quit. */
329
321
        virtual bool initializeWork() { return true; };
330
322
 
331
 
        /* Return true of the thread should sleep before doing more work. */
332
323
        virtual bool doWork();
333
324
 
334
325
        virtual void *completeWork() { return NULL; };
335
326
 
336
 
        /* Return false if the excpetion is not handled and the thread must quit.
337
 
         * Set must_sleep to true of the thread should pause before doing work
338
 
         * again.
339
 
         */
340
327
        virtual bool handleException();
341
328
 
342
329
        virtual void stop();
361
348
        void suspendedWait(time_t milli_sec);
362
349
 
363
350
private:
364
 
        void            try_Run(CSThread *self, const bool must_sleep);
365
 
        bool            iSuspended;
366
 
        uint32_t        iSuspendCount;
 
351
        bool                    iSuspended;
 
352
        uint32_t                        iSuspendCount;
367
353
};
368
354
 
369
355
#endif