HepLib
Loading...
Searching...
No Matches
PoolPipe.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <vector>
9#include <memory>
10#include <mutex>
11#include <condition_variable>
12#include <functional>
13#include <sys/wait.h>
14#include <sys/stat.h>
15
16namespace HepLib {
17
18 class Pool {
19 public:
20 explicit Pool(const std::vector<void*> & vec);
21 void* acquire();
22 void release(void* obj);
23 private:
24 std::vector<void*> ava;
25 std::mutex mtx;
26 std::condition_variable cv;
27 };
28
29 class iPool {
30 public:
31 explicit iPool(int tot);
32 explicit iPool();
33 int acquire();
34 void release(int obj);
35 void init(int tot);
36 private:
37 std::vector<int> ava;
38 std::mutex mtx;
39 std::condition_variable cv;
40 bool inited = false;
41 };
42
43
44 class Pipe {
45 public:
46 explicit Pipe(const std::function<std::string(const std::string &)> & fi);
47 ~Pipe();
48 std::string run(const std::string &code);
49 private:
50 int p2c[2], c2p[2];
51 pid_t pid;
52 std::function<std::string(const std::string &)> f;
53 };
54
55 class PipePool {
56 public:
57 explicit PipePool(int size, const std::function<std::string(const std::string &)> & f);
58 std::string run(const std::string & code);
59 std::vector<std::string> run_all(const std::string &code);
60 ~PipePool();
61 private:
62 Pool* pool;
63 std::vector<Pipe*> pipe_ptr_vec;
64 };
65
66
67}
std::string run(const std::string &code)
Definition PoolPipe.cpp:148
std::vector< std::string > run_all(const std::string &code)
Definition PoolPipe.cpp:155
std::string run(const std::string &code)
Definition PoolPipe.cpp:116
void * acquire()
Definition PoolPipe.cpp:18
void release(void *obj)
Definition PoolPipe.cpp:26
void init(int tot)
Definition PoolPipe.cpp:41
void release(int obj)
Definition PoolPipe.cpp:55
HepLib namespace.
Definition BASIC.cpp:17