-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEventLoopManager.cpp
More file actions
37 lines (32 loc) · 868 Bytes
/
EventLoopManager.cpp
File metadata and controls
37 lines (32 loc) · 868 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
//
// EventLoopManager.cpp
//
//
// Created by Benedikt Hegner on 4/12/12.
// Copyright (c) 2012 CERN. All rights reserved.
//
#include "EventLoopManager.h"
#include "tbb/compat/thread"
EventLoopManager::EventLoopManager(const unsigned int n_parallel) :
in_flight_(), processed_(),
max_concurrent_events_(n_parallel), events_(0)
{
}
void EventLoopManager::initialise(int events, Scheduler* scheduler){
events_ = events;
scheduler_ = scheduler;
}
void EventLoopManager::finished_event(){
++processed_;
--in_flight_;
}
void EventLoopManager::operator()(){
do {
if (in_flight_ < max_concurrent_events_ && processed_+in_flight_ < events_) {
scheduler_->start_event(processed_+in_flight_);
++in_flight_;
}
std::this_thread::yield();
} while (processed_ < events_);
scheduler_->stop();
}