forked from rmbianchi/concurrent_framework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AlgoPool.cpp
29 lines (24 loc) · 901 Bytes
/
AlgoPool.cpp
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
//
// AlgoPool.cpp
//
//
// Created by Benedikt Hegner on 4/12/12.
// Copyright (c) 2012 __CERN__. All rights reserved.
//
#include "AlgoPool.h"
AlgoPool::AlgoPool(const std::vector<AlgoBase*>& algos, const std::vector<int> max_instances){
//TODO: use the max_instances structure!
// Fill the data structure holding all available algorithm instances
const unsigned int size = algos.size();
available_algo_instances_.resize(size);
for (unsigned int i = 0; i<size; ++i) {
available_algo_instances_[i] = new tbb::concurrent_queue<AlgoBase*>();
available_algo_instances_[i]->push(algos[i]);
}
}
bool AlgoPool::acquire(AlgoBase*& algo, const unsigned int algo_id){
return available_algo_instances_[algo_id]->try_pop(algo);
}
void AlgoPool::release(AlgoBase*& algo, const unsigned int algo_id){
available_algo_instances_[algo_id]->push(algo);
}