Added image output to manager, added plots to results pages
[progcomp2012.git] / judge / manager / thread_util.cpp
1 #include "thread_util.h"
2
3 #include <sstream>
4 #include <string>
5
6 using namespace std;
7
8 pthread_mutex_t GetterThread::mutex = PTHREAD_MUTEX_INITIALIZER;
9
10 void * GetterThread::GetMessage(void * p)
11 {
12         
13         GetterThread * getter = (GetterThread*)(p);
14         
15         stringstream inputStream;
16
17         char s = fgetc(getter->stream);
18         while (s != '\n' && s != EOF)
19         {
20                 
21                 inputStream << s;
22                 s = fgetc(getter->stream);
23         }
24         if (s == EOF)
25         {
26                 getter->buffer = "";
27                 getter->buffer += s;
28                 return NULL;
29         }       
30
31         pthread_mutex_lock(&mutex);
32                 getter->buffer = inputStream.str();
33         pthread_mutex_unlock(&mutex);
34         
35         getter->finished = true;
36
37         return NULL;
38 }
39
40 void * TimerThread::Timeout(void * p)
41 {
42         TimerThread * timer = (TimerThread*)(p);
43         usleep(timer->count);
44         timer->finished = true;
45         return NULL;
46 }
47

UCC git Repository :: git.ucc.asn.au