~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: lbieber
  • Date: 2010-09-11 16:33:45 UTC
  • mfrom: (1757.1.2 build)
  • Revision ID: lbieber@orisndriz03-20100911163345-na1t8m18at9thsjl
Merge Vijay - added utf 8 tamil test case suite and test case for creating a database in tamil
Merge Brian - Small set of refactoring (includes one case of memset on a table object).

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
30
30
 
31
31
#ifdef OS_WINDOWS
32
32
#include <signal.h>
33
 
//#include "uniwin.h"
34
 
#define SIGUSR1 30
35
 
#define SIGUSR2 31
36
 
 
 
33
#include "uniwin.h"
37
34
#else
38
35
#include <signal.h>
39
36
#include <sys/signal.h>
 
37
#endif
40
38
#include <unistd.h>
41
 
#endif
42
39
#include <errno.h>
43
40
 
44
41
#include "CSGlobal.h"
211
208
void CSThread::removeFromList()
212
209
{
213
210
        if (myThreadList && isRunning) {
214
 
                CSThread *myself = this; // pop_() wants to take a reference to its parameter.
215
211
                enter_();
216
212
                /* Retain the thread in order to ensure
217
213
                 * that after it is removed from the list,
219
215
                 * unlock_() call invalid, because it requires
220
216
                 * on the thread.
221
217
                 */
222
 
                push_(myself);
 
218
                push_(this);
223
219
                lock_(myThreadList);
224
 
                myThreadList->remove(RETAIN(myself));
 
220
                myThreadList->remove(RETAIN(this));
225
221
                unlock_(myThreadList);
226
 
                pop_(myself);
 
222
                pop_(this);
227
223
                outer_();
228
224
        }
229
225
        this->release();
292
288
        return NULL;
293
289
}
294
290
 
295
 
void CSThread::start(bool detached)
 
291
void CSThread::start()
296
292
{
297
293
        int err;
298
294
 
307
303
                        break;
308
304
                usleep(10);
309
305
        }
310
 
        
311
 
        isDetached = detached;
312
 
        if (detached)
313
 
                pthread_detach(iThread);
314
306
}
315
307
 
316
308
void CSThread::stop()
321
313
 
322
314
void *CSThread::join()
323
315
{
324
 
        void    *return_data = NULL;
 
316
        void    *return_data;
325
317
        int             err;
326
318
 
327
319
        enter_();
328
 
        if (isDetached) {
329
 
                while (isRunning && !pthread_kill(iThread, 0)) 
330
 
                        usleep(100);
331
 
        } else if ((err = pthread_join(iThread, &return_data))) {
 
320
        if ((err = pthread_join(iThread, &return_data)))
332
321
                CSException::throwOSError(CS_CONTEXT, err);
333
 
        }
334
 
 
335
322
        return_(return_data);
336
323
}
337
324
 
347
334
 
348
335
void CSThread::signal(unsigned int sig)
349
336
{
350
 
#ifndef OS_WINDOWS // Currently you cannot signal threads on windows.
351
337
        int err;
352
338
 
353
339
        setSignalPending(sig);
357
343
                if (err != ESRCH) /* No such process */
358
344
                        CSException::throwOSError(CS_CONTEXT, err);
359
345
        }
360
 
#endif
361
346
}
362
347
 
363
348
void CSThread::throwSignal()
404
389
                                if (relTop->x.r_pooled)
405
390
                                        relTop->x.r_pooled->returnToPool();
406
391
                                break;
407
 
                        case CS_RELEASE_MEM:
408
 
                                if (relTop->x.r_mem)
409
 
                                        cs_free(relTop->x.r_mem);
410
 
                                break;
411
 
                        case CS_RELEASE_OBJECT_PTR:
412
 
                                if ((relTop->x.r_objectPtr) && (obj = *(relTop->x.r_objectPtr)))
413
 
                                        obj->release();
414
 
                                break;
415
392
                }
416
393
        }
417
394
}
486
463
        isUp = false;
487
464
        if ((err = pthread_key_create(&sThreadKey, NULL))) {
488
465
                CSException::logOSError(CS_CONTEXT, errno);
 
466
                return false;
489
467
        } else
490
468
                isUp = true;
491
469
                
534
512
                return (CSThread*) NULL;
535
513
                
536
514
#ifdef DEBUG
537
 
        /* PMC - Problem is, if this is called when releasing a
538
 
         * thread, then we have the reference count equal to
539
 
         * zero.
540
 
        if (self && !self->iRefCount) {
 
515
        if (self->iRefCount == 0) {
541
516
                pthread_setspecific(sThreadKey, NULL);
542
 
                CSException::throwAssertion(CS_CONTEXT, "Freed self pointer referenced.");
543
 
        }
544
 
        */
 
517
                CSException::throwAssertion(CS_CONTEXT, "Bad self pointer.");
 
518
        }       
545
519
#endif
546
520
 
547
521
        return self;
640
614
{
641
615
}
642
616
 
643
 
void CSDaemon::try_Run(CSThread *self, const bool c_must_sleep)
 
617
void *CSDaemon::run()
644
618
{
 
619
        bool must_sleep = false;
 
620
 
 
621
        CLOBBER_PROTECT(must_sleep);
 
622
 
 
623
        enter_();
 
624
        CLOBBER_PROTECT(self);
 
625
 
 
626
        myMustQuit = !initializeWork();
 
627
 
 
628
        restart:
645
629
        try_(a) {
646
 
                 bool must_sleep = c_must_sleep; // This done to avoid longjmp() clobber.
647
630
                while (!myMustQuit) {
648
631
                        if (must_sleep) {
649
632
                                lock_(this);
663
646
                        myMustQuit = true;
664
647
        }
665
648
        cont_(a);
666
 
}
667
 
 
668
 
void *CSDaemon::run()
669
 
{
670
 
        bool must_sleep = false;
671
 
 
672
 
        enter_();
673
 
 
674
 
        myMustQuit = !initializeWork();
675
 
 
676
 
        while  (!myMustQuit) {
677
 
                try_Run(self, must_sleep);
 
649
        if (!myMustQuit) {
678
650
                must_sleep = true;
 
651
                goto restart;
679
652
        }
680
653
 
681
654
        /* Prevent signals from going off in completeWork! */