File: main.ih

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (85 lines) | stat: -rw-r--r-- 1,558 bytes parent folder | download | duplicates (3)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <fstream>
#include <syncstream>
#include <string>
#include <thread>
#include <queue>
#include <future>
#include <mutex>
#include <atomic>
#include <vector>

#include "../semaphore/semaphore.h"
#include "../cmdfork/cmdfork.h"

using namespace std;

//task
using PackagedTask = packaged_task<void (string const &fname)>;

class Task
{
    string d_command;
    PackagedTask d_task;

    public:
        Task()  = default;

        Task(string const &command, PackagedTask &&tmp)
        :
            d_command(command),
            d_task(move(tmp))
        {}

        void operator()()
        {
            d_task(d_command);
            d_task.get_future();    // handles potential exceptions
        }
};
//=

class TaskQueue
{
    mutex d_mutex;
    queue<Task> d_queue;

    public:
        void push(Task &&tmp)
        {
            lock_guard<mutex> lk(d_mutex);
            d_queue.push(move(tmp));
        }

        void popFront(Task &dest)
        {
            lock_guard<mutex> lk(d_mutex);
            dest = move(d_queue.front());
            d_queue.pop();
        }

        bool empty() const
        {
            return d_queue.empty();
        }
};

extern atomic_bool g_done;
extern size_t g_sizeofWorkforce;
extern string g_marker;

extern std::vector<std::thread> g_thread;
extern fstream g_out;

extern TaskQueue g_taskQ;

extern Semaphore g_dispatcher;
extern Semaphore g_worker;


void compile(string const &line);
void jobs();
void worker();
void workforce();
string nextCommand();
void results();