blob: 9c767e801b3d321c0e1877a0f8eceee9348eba45 (
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
58
59
60
61
62
63
64
65
66
67
|
/*
* include/framework/scheduling/SerialScheduler.h
*
* Copyright (C) 2023 Douglas B. Rumbaugh <drumbaugh@psu.edu>
*
* All rights reserved. Published under the Modified BSD License.
*
* IMPORTANT: This "scheduler" is a shim implementation for allowing
* strictly serial, single-threaded operation of the framework. It should
* never be used in multi-threaded contexts. A call to the schedule_job
* function will immediately run the job and block on its completion before
* returning.
*
*/
#pragma once
#include <vector>
#include <memory>
#include <queue>
#include <thread>
#include <condition_variable>
#include <future>
#include "util/types.h"
#include "framework/interface/Shard.h"
#include "framework/interface/Query.h"
#include "framework/interface/Record.h"
#include "framework/structure/MutableBuffer.h"
#include "framework/util/Configuration.h"
#include "framework/structure/ExtensionStructure.h"
#include "framework/scheduling/Task.h"
namespace de {
class SerialScheduler {
public:
SerialScheduler(size_t memory_budget, size_t thread_cnt)
: m_memory_budget((memory_budget) ? memory_budget : UINT64_MAX)
, m_thrd_cnt((thread_cnt) ? thread_cnt: UINT64_MAX)
, m_used_memory(0)
, m_used_thrds(0)
, m_counter(0)
{}
~SerialScheduler() = default;
void schedule_job(std::function<void(void*)> job, size_t size, void *args) {
size_t ts = m_counter++;
auto t = Task(size, ts, job, args);
t();
}
void shutdown() {
/* intentionally left blank */
}
private:
size_t m_memory_budget;
size_t m_thrd_cnt;
size_t m_used_thrds;
size_t m_used_memory;
size_t m_counter;
};
}
|