add name + running (nice_kill) to threads
This commit is contained in:
@ -107,8 +107,8 @@ void kickoff(Thread* object) {
|
|||||||
* Parameter: *
|
* Parameter: *
|
||||||
* stack Stack für die neue Koroutine *
|
* stack Stack für die neue Koroutine *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
Thread::Thread() : stack(new unsigned int[1024]), tid(ThreadCnt++) {
|
Thread::Thread(char* name) : name(name), stack(new unsigned int[1024]), tid(ThreadCnt++) {
|
||||||
Thread::log << INFO << "Initialized thread with ID: " << this->tid << endl;
|
Thread::log << INFO << "Initialized thread with ID: " << this->tid << " (" << name << ")" << endl;
|
||||||
Thread_init(®s, stack + 1024, kickoff, this); // Stack grows from top to bottom
|
Thread_init(®s, stack + 1024, kickoff, this); // Stack grows from top to bottom
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -39,15 +39,18 @@ private:
|
|||||||
struct ThreadState regs;
|
struct ThreadState regs;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Thread(char* name);
|
||||||
|
|
||||||
static Logger log;
|
static Logger log;
|
||||||
|
|
||||||
public:
|
bool running = true; // For soft exit, if thread uses infinite loop inside run(), use this as condition
|
||||||
|
char* name; // For logging
|
||||||
unsigned int tid; // Thread-ID (wird im Konstruktor vergeben)
|
unsigned int tid; // Thread-ID (wird im Konstruktor vergeben)
|
||||||
|
friend class Scheduler; // Scheduler can access tid
|
||||||
|
|
||||||
Thread();
|
public:
|
||||||
|
|
||||||
virtual ~Thread() {
|
virtual ~Thread() {
|
||||||
log << INFO << "Uninitialized thread, ID: " << dec << this->tid << endl;
|
log << INFO << "Uninitialized thread, ID: " << dec << this->tid << " (" << name << ")" << endl;
|
||||||
delete[] this->stack;
|
delete[] this->stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +60,9 @@ public:
|
|||||||
// Umschalten auf Thread 'next'
|
// Umschalten auf Thread 'next'
|
||||||
void switchTo(Thread& next);
|
void switchTo(Thread& next);
|
||||||
|
|
||||||
|
// Ask thread to terminate itself
|
||||||
|
void suicide() { running = false; }
|
||||||
|
|
||||||
// Methode des Threads, muss in Sub-Klasse implementiert werden
|
// Methode des Threads, muss in Sub-Klasse implementiert werden
|
||||||
virtual void run() = 0;
|
virtual void run() = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user