Ignore:
Timestamp:
04/12/02 16:59:23 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy/base
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/base/MThread.cc

    r1273 r1275  
    11#include <MThread.h>
     2
     3#include <iostream.h>
    24
    35#include <pthread.h>
     
    1214MThread::MThread(bool start, int prio) : fIsRunning(false), fIsDetached(false), fThread(NULL), fReturn(NULL)
    1315{
    14     if (start)
    15     {
    16         SetPriority(prio);
    17         Start();
    18     }
     16    if (!start)
     17        return;
     18
     19    SetPriority(prio);
     20    Start();
    1921}
    2022
     
    2729MThread::~MThread()
    2830{
    29     if (fIsRunning)
    30         Stop();
     31    cout << "~MThread::MThread" << endl;
     32    Stop();
    3133}
    3234
     
    120122void MThread::Stop()
    121123{
     124    cout << "MThread::Stop: fThread=" << fThread << ", fIsRunning=" << (int)fIsRunning << endl;
    122125    if (!fThread || !fIsRunning)
    123126        return;
     
    125128    if (fIsDetached)
    126129    {
     130        cout << "Stopping detached thread..." << flush;
    127131        pthread_cancel(*fThread);
    128132        fIsRunning = false;
     
    130134    else
    131135    {
     136        cout << "Stopping thread..." << flush;
    132137        fStop = true;
    133138        pthread_join(*fThread, &fReturn);
    134139    }
     140    cout << "done." << endl;
    135141
    136142    delete fThread;
    137143    fThread = NULL;
     144
     145    cout << "MThread::Stop() done." << endl;
    138146}
  • trunk/MagicSoft/Cosy/base/msgqueue.cc

    r1273 r1275  
    66#include <sys/resource.h>  // PRIO_PROCESS
    77
     8// --------------------------------------------------------------------------
     9//
     10// This creates the Message queue thread,
     11//
    812MsgQueue::MsgQueue() : fBreak(0)
    913{
     
    1216}
    1317
     18// --------------------------------------------------------------------------
     19//
     20// The destructor terminates the thread.
     21//
    1422MsgQueue::~MsgQueue()
    1523{
     24    cout << "~MsgQueue::MsgQueue" << endl;
    1625    pthread_cancel(fThread);
    1726    delete (unsigned char*)fMp;
    1827}
    1928
     29// --------------------------------------------------------------------------
     30//
     31// This is the function which must be overloaded.
     32// Here you process the messages. mp is a pointer which you can
     33// specify when posting the message.
     34//
     35// If a new messages is posted while the old one is not yet
     36// finished the fBreak flag is set. Please test this flag with
     37// Break() and try to finish (or stop) the current action as soon
     38// as possible. This makes sure, that before a new action is started
     39// the old action can be finished correctly by the user.
     40//
    2041void *MsgQueue::Proc(int msg, void *mp)
    2142{
     
    2344}
    2445
     46// --------------------------------------------------------------------------
     47//
     48// This is the thread mapper.
     49//
    2550void *MsgQueue::MapThread(void *arg)
    2651{
     
    3459}
    3560
     61// --------------------------------------------------------------------------
     62//
     63// This is the thread which handles the processing.
     64// As soon as a message is posted the fBreak flag is set (see PostMsg)
     65// And as soon as the current action is finished the new action is executed
     66// in this thread. This makes sure, that the calling program is not stalled.
     67//
    3668void MsgQueue::Thread()
    3769{
     
    5688        pthread_mutex_unlock(&fMuxMsg);
    5789
     90        cout << "Processing Msg 0x" << hex << fMsg << endl;
     91        // --- bool quit = fMsg==WM_QUIT;
    5892        fRc=Proc(fMsg, fMp);
     93        cout << "Msg 0x" << hex << fMsg << " processed." << endl;
    5994
    60         if (fMsg==WM_QUIT)
    61             break;
     95        // --- if (quit)
     96        // ---    break;
     97    }
    6298
    63     }
     99    // --- fStart = 0;
     100    // --- cout << "WM_QUIT posted... leaving msg queue." << endl;
    64101}
    65102
     103// --------------------------------------------------------------------------
     104//
     105// Use this function to post a message.
     106// mp can be a pointer to a data structure. size should be the size of it.
     107// size bytes of this structure are copied and a pointer to the copy
     108// is forwarded to the Proc function.
     109//
    66110void *MsgQueue::PostMsg(int msg, void *mp, int size)
    67111{
     
    74118    // stopped and the messages are processed serialized
    75119    //
     120    cout << "Locking MsgQueue mutex..." << flush;
    76121    pthread_mutex_lock(&fMuxMsg);
     122    cout << "done." << endl;
    77123
    78124    //
     
    101147    //
    102148    fStart = 1;
     149    cout << "Releasing MsgQueue mutex..." << flush;
    103150    pthread_mutex_unlock(&fMuxMsg);
    104     while (fStart) usleep(1);
     151    cout << "done." << endl;
     152    while (fStart)
     153        usleep(1);
    105154
     155    cout << "Returning rc = 0x" << hex << rc << endl;
    106156    return rc;
    107157}
Note: See TracChangeset for help on using the changeset viewer.