-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFutureFreePool.cpp
More file actions
38 lines (33 loc) · 796 Bytes
/
Copy pathFutureFreePool.cpp
File metadata and controls
38 lines (33 loc) · 796 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
#include "mutils-tasks/FutureFreePool.hpp"
#include "mutils-tasks/GlobalPool.hpp"
#include <list>
#include "mutils/AtScopeEnd.hpp"
using namespace std;
namespace mutils{
namespace{
template<typename T> void irritate(const T&){}
}
int FutureFreePool_impl::get_pos(){
int pos = -1;
{
FutureFreePool_impl::lock{m};
pos = available_ids.front();
available_ids.pop_front();
}
assert(pos > -1);
return pos;
}
void FutureFreePool_impl::launch (function<void (int)> fun){
auto pos = get_pos();
auto this_p = this->this_p;
AtScopeEnd ase{[pos,this_p](){
lock{this_p->m};
this_p->available_ids.push_back(pos);
}};
pending[pos] = GlobalPool::push([fun,ase2 = std::move(ase)](int i){
fun(i);
assert(ase2.assert_this());
(void)ase2;
});
}
}