载入中...
搜索中...
未找到
Channel.h
浏览该文件的文档.
1#pragma once
2
3#include <condition_variable>
4#include <memory>
5#include <mutex>
6#include <queue>
7#include <string>
8
9namespace eve {
10namespace thread {
11
17class Channel {
18public:
19 Channel();
20 explicit Channel(std::string name);
22
23 std::string getName() const;
24
25 void push(std::string value);
27 std::string pop();
29 std::string demand();
31 std::string supply(int timeoutMs);
32
33 bool hasData() const;
34 int getCount() const;
35 void clear();
36
37private:
38 struct State {
39 explicit State(std::string channelName = {}) : name(std::move(channelName)) {}
40
41 std::string name;
42 mutable std::mutex mu;
43 std::condition_variable cv;
44 std::queue<std::string> queue;
45 };
46
47 std::shared_ptr<State> state_;
48
49 friend class ThreadPool;
50};
51
52} // namespace thread
53} // namespace eve
std::string value
const char * name
Definition RockMesh.cpp:21
Thread-safe message queue (love2d-style Channel). Values are strings so the API stays overload-free f...
Definition Channel.h:17
void push(std::string value)
Definition Channel.cpp:16
bool hasData() const
Definition Channel.cpp:54
std::string pop()
Non-blocking pop; returns "" if empty.
Definition Channel.cpp:24
std::string demand()
Block until a value is available, then pop it.
Definition Channel.cpp:33
int getCount() const
Definition Channel.cpp:59
std::string getName() const
Definition Channel.cpp:14
std::string supply(int timeoutMs)
Block up to timeoutMs; returns "" on timeout.
Definition Channel.cpp:42
Fixed-size worker pool. Owns worker std::threads; tasks run FIFO. Squirrel VM is not thread-safe — do...
Definition ThreadPool.h:24
Definition Build.cpp:11