-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread.cpp
34 lines (34 loc) · 1020 Bytes
/
thread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include"thread.h"
#include"stdarg.h"
extern"C"{
extern volatile bool g_halted;
void calc();
void emit_warning(const char*str){emit calculation.warning(str);}
void emit_output(const char*str){emit calculation.output(str);}
void emit_maximum(int max){emit calculation.maximum(max);}
void emit_progress(int prg){emit calculation.progress(prg);}
void emit_completed1st(){emit calculation.completed1st();}
void*emit_error(const char*str,...){//accepts a null-terminated list of strings to output
QString string = "";
va_list v;
va_start(v,str);
while(str){
string += str;
str = va_arg(v,const char*);
}
va_end(v);
bool calc = QThread::currentThread() == calculation.currentThread();
if(calc) string += "<br>Halting Calculation";
emit calculation.error(string);//connected to handling slot in window.cpp
if(calc) calculation.sleep(~0UL);
return 0;
}}
void Thread::begin(){
if(!isRunning()){
emit starting();
start();
}
}
void Thread::run(){calc();}
void Thread::stop(){g_halted=true;}
Thread calculation;