~skinny.moey/drizzle/innodb-replication

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2010-11-08 22:35:57 UTC
  • mfrom: (1802.1.114 trunk)
  • Revision ID: brian@tangent.org-20101108223557-w3xzwp9hjjtjhtc1
MergeĀ inĀ trunk.

Show diffs side-by-side

added added

removed removed

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