-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathspirepool.h
More file actions
48 lines (39 loc) · 935 Bytes
/
Copy pathspirepool.h
File metadata and controls
48 lines (39 loc) · 935 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
#ifndef SPIREPOOL_H_
#define SPIREPOOL_H_
#include <atomic>
#include <list>
#include <mutex>
#include "types.h"
class Layout;
class Pool
{
public:
typedef Number ScoreFunc(const Layout &);
private:
unsigned max_size;
ScoreFunc *score_func;
std::list<Layout> layouts;
mutable std::mutex layouts_mutex;
std::atomic<unsigned> isolated_until;
public:
Pool(unsigned, ScoreFunc *);
void reset(ScoreFunc * = 0);
void add_layout(const Layout &);
Layout get_best_layout() const;
bool get_best_layout(Layout &) const;
Layout get_random_layout(Random &) const;
Number get_best_score() const;
void set_isolated_until(unsigned);
bool check_isolation(unsigned) const;
template<typename F>
void visit_layouts(const F &) const;
};
template<typename F>
void Pool::visit_layouts(const F &func) const
{
std::lock_guard<std::mutex> lock(layouts_mutex);
for(const auto &layout: layouts)
if(!func(layout))
return;
}
#endif