Changeset 1275 for trunk/MagicSoft/Cosy/base
- Timestamp:
- 04/12/02 16:59:23 (23 years ago)
- Location:
- trunk/MagicSoft/Cosy/base
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/base/MThread.cc
r1273 r1275 1 1 #include <MThread.h> 2 3 #include <iostream.h> 2 4 3 5 #include <pthread.h> … … 12 14 MThread::MThread(bool start, int prio) : fIsRunning(false), fIsDetached(false), fThread(NULL), fReturn(NULL) 13 15 { 14 if ( start)15 {16 SetPriority(prio); 17 Start();18 }16 if (!start) 17 return; 18 19 SetPriority(prio); 20 Start(); 19 21 } 20 22 … … 27 29 MThread::~MThread() 28 30 { 29 if (fIsRunning)30 31 cout << "~MThread::MThread" << endl; 32 Stop(); 31 33 } 32 34 … … 120 122 void MThread::Stop() 121 123 { 124 cout << "MThread::Stop: fThread=" << fThread << ", fIsRunning=" << (int)fIsRunning << endl; 122 125 if (!fThread || !fIsRunning) 123 126 return; … … 125 128 if (fIsDetached) 126 129 { 130 cout << "Stopping detached thread..." << flush; 127 131 pthread_cancel(*fThread); 128 132 fIsRunning = false; … … 130 134 else 131 135 { 136 cout << "Stopping thread..." << flush; 132 137 fStop = true; 133 138 pthread_join(*fThread, &fReturn); 134 139 } 140 cout << "done." << endl; 135 141 136 142 delete fThread; 137 143 fThread = NULL; 144 145 cout << "MThread::Stop() done." << endl; 138 146 } -
trunk/MagicSoft/Cosy/base/msgqueue.cc
r1273 r1275 6 6 #include <sys/resource.h> // PRIO_PROCESS 7 7 8 // -------------------------------------------------------------------------- 9 // 10 // This creates the Message queue thread, 11 // 8 12 MsgQueue::MsgQueue() : fBreak(0) 9 13 { … … 12 16 } 13 17 18 // -------------------------------------------------------------------------- 19 // 20 // The destructor terminates the thread. 21 // 14 22 MsgQueue::~MsgQueue() 15 23 { 24 cout << "~MsgQueue::MsgQueue" << endl; 16 25 pthread_cancel(fThread); 17 26 delete (unsigned char*)fMp; 18 27 } 19 28 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 // 20 41 void *MsgQueue::Proc(int msg, void *mp) 21 42 { … … 23 44 } 24 45 46 // -------------------------------------------------------------------------- 47 // 48 // This is the thread mapper. 49 // 25 50 void *MsgQueue::MapThread(void *arg) 26 51 { … … 34 59 } 35 60 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 // 36 68 void MsgQueue::Thread() 37 69 { … … 56 88 pthread_mutex_unlock(&fMuxMsg); 57 89 90 cout << "Processing Msg 0x" << hex << fMsg << endl; 91 // --- bool quit = fMsg==WM_QUIT; 58 92 fRc=Proc(fMsg, fMp); 93 cout << "Msg 0x" << hex << fMsg << " processed." << endl; 59 94 60 if (fMsg==WM_QUIT) 61 break; 95 // --- if (quit) 96 // --- break; 97 } 62 98 63 } 99 // --- fStart = 0; 100 // --- cout << "WM_QUIT posted... leaving msg queue." << endl; 64 101 } 65 102 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 // 66 110 void *MsgQueue::PostMsg(int msg, void *mp, int size) 67 111 { … … 74 118 // stopped and the messages are processed serialized 75 119 // 120 cout << "Locking MsgQueue mutex..." << flush; 76 121 pthread_mutex_lock(&fMuxMsg); 122 cout << "done." << endl; 77 123 78 124 // … … 101 147 // 102 148 fStart = 1; 149 cout << "Releasing MsgQueue mutex..." << flush; 103 150 pthread_mutex_unlock(&fMuxMsg); 104 while (fStart) usleep(1); 151 cout << "done." << endl; 152 while (fStart) 153 usleep(1); 105 154 155 cout << "Returning rc = 0x" << hex << rc << endl; 106 156 return rc; 107 157 }
Note:
See TracChangeset
for help on using the changeset viewer.