Changeset ceec23


Ignore:
Timestamp:
02/03/12 15:50:04 (3 months ago)
Author:
Micke Prag <micke.prag@…>
Branches:
('master', 'deebf2045e7119c339412580f37a1e653f7d5715')('controller-upgrade', '00f95d22e12d96ef089e0902ef62ae8ce841dc6f')
Children:
868c8b322c052181e36262773192fb03fa02fdea
Parents:
938187b2a652cc6691f5a3b2ec9d0d73fd4e6748
git-author:
Micke Prag <micke.prag@telldus.se>2012-02-03 15:50:04+01:00
git-committer:
Micke Prag <micke.prag@telldus.se>2012-02-03 15:50:04+01:00
Message:

Add function Thread::startAndLock()

Location:
telldus-core/common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • telldus-core/common/Thread.cpp

    r23be1d rceec23  
    1515#include <windows.h> 
    1616#endif 
     17#include "EventHandler.h" 
    1718 
    1819using namespace TelldusCore; 
     
    2122public: 
    2223        bool running; 
     24        EventRef threadStarted; 
     25        Mutex *mutex; 
    2326#ifdef _WINDOWS 
    2427        HANDLE thread; 
     
    3235        d = new ThreadPrivate; 
    3336        d->thread = 0; 
     37        d->mutex = 0; 
    3438} 
    3539 
     
    4549        pthread_create(&d->thread, NULL, &Thread::exec, this ); 
    4650#endif 
     51} 
     52 
     53void Thread::startAndLock(Mutex *lock) { 
     54        EventHandler handler; 
     55        d->threadStarted = handler.addEvent(); 
     56        d->mutex = lock; 
     57        this->start(); 
     58        handler.waitForAny(); 
     59        d->threadStarted.reset(); 
    4760} 
    4861 
     
    6578        Thread *t = reinterpret_cast<Thread *>(ptr); 
    6679        if (t) { 
     80                if (t->d->threadStarted) { 
     81                        t->d->mutex->lock(); 
     82                        t->d->threadStarted->signal(); 
     83                } 
    6784                t->run(); 
     85                if (t->d->mutex) { 
     86                        t->d->mutex->unlock(); 
     87                } 
    6888                t->d->running = false; 
    6989        } 
  • telldus-core/common/Thread.h

    r8105da rceec23  
    1414 
    1515#include <string> 
     16#include "Mutex.h" 
    1617 
    1718namespace TelldusCore { 
     
    2223                        virtual ~Thread(); 
    2324                        void start(); 
     25                        void startAndLock(Mutex *); 
    2426                        bool wait(); 
    2527                                                 
Note: See TracChangeset for help on using the changeset viewer.