summaryrefslogtreecommitdiffstats
path: root/include/framework/scheduling/Task.h
blob: 94c4d0a1eac8236cb0fca6c99df7f77a05077c9e (plain)
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
/*
 *
 */
#pragma once

#include <variant>
#include <future>
#include <functional>

#include "framework/util/Configuration.h"
#include "framework/scheduling/Epoch.h"

namespace de {

template <RecordInterface R, ShardInterface S, QueryInterface Q, LayoutPolicy L>
struct MergeArgs {
    Epoch<R, S, Q, L> *epoch;
    std::vector<MergeTask> merges;
    std::promise<bool> result;
};

template <RecordInterface R, ShardInterface S, QueryInterface Q, LayoutPolicy L>
struct QueryArgs {
    Epoch<R, S, Q, L> *epoch;
    std::promise<std::vector<R>> result_set;
    void *query_parms;
};

typedef std::function<void(void*)> Job;

struct Task {
    Task(size_t size, size_t ts, Job job, void *args) 
      : m_job(job)
      , m_size(size)
      , m_timestamp(ts)
      , m_args(args)
    {}

    Job m_job;
    size_t m_size;
    size_t m_timestamp;
    void *m_args;

    friend bool operator<(const Task &self, const Task &other) {
        return self.m_timestamp < other.m_timestamp;
    }

    friend bool operator>(const Task &self, const Task &other) {
        return self.m_timestamp > other.m_timestamp;
    }

    void operator()() {
        m_job(m_args);
    }
};

}