-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathipi.hh
More file actions
50 lines (40 loc) · 945 Bytes
/
Copy pathipi.hh
File metadata and controls
50 lines (40 loc) · 945 Bytes
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
#pragma once
#include <atomic>
#include "bitset.hh"
#include "percpu.hh"
struct ipi_call
{
void run_on(const bitset<NCPU> &);
protected:
virtual void run() = 0;
private:
void start(unsigned cpu);
// next[i] must be valid before this call is linked in to the
// myipi[i] queue and must not change until the call is done.
struct ipi_call* next[NCPU];
__mpalign__ atomic<int> waiting;
__padout__;
friend void on_ipicall();
};
template<class CB>
struct ipi_call_callable : public ipi_call
{
private:
const CB &cb;
public:
ipi_call_callable(const CB &cb) : cb(cb) { }
protected:
void run() override
{
cb();
}
};
// Invoke @c cb ASAP on all CPUs in @c cpu_set. @c cb will be called
// from the IPI interrupt handler with interrupts disabled, so it
// should be lightweight.
template<class CB>
void run_on_cpus(const bitset<NCPU> &cpu_set, CB cb)
{
ipi_call_callable<CB> call(cb);
call.run_on(cpu_set);
}