2019-07-28 10:31:56 +08:00
|
|
|
#pragma once
|
2018-11-30 14:38:22 +08:00
|
|
|
|
|
|
|
#include "fiber_cpp_define.hpp"
|
|
|
|
|
|
|
|
struct ACL_CHANNEL;
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
|
|
ACL_CHANNEL *channel_create(int elemsize, int bufsize);
|
|
|
|
void channel_free(ACL_CHANNEL *c);
|
|
|
|
int channel_send(ACL_CHANNEL *c, void *v);
|
|
|
|
int channel_recv(ACL_CHANNEL *c, void *v);
|
|
|
|
|
|
|
|
template <typename T>
|
2023-06-11 18:34:41 +08:00
|
|
|
class channel {
|
2018-11-30 14:38:22 +08:00
|
|
|
public:
|
2023-06-11 18:34:41 +08:00
|
|
|
channel(void) {
|
2018-11-30 14:38:22 +08:00
|
|
|
chan_ = channel_create(sizeof(T), 100);
|
|
|
|
}
|
|
|
|
|
2023-06-11 18:34:41 +08:00
|
|
|
~channel(void) {
|
2018-11-30 14:38:22 +08:00
|
|
|
channel_free(chan_);
|
|
|
|
}
|
|
|
|
|
2023-06-11 18:34:41 +08:00
|
|
|
channel& operator << (T& t) {
|
2018-11-30 14:38:22 +08:00
|
|
|
return put(t);
|
|
|
|
}
|
|
|
|
|
2023-06-11 18:34:41 +08:00
|
|
|
channel& put(T& t) {
|
2018-11-30 14:38:22 +08:00
|
|
|
channel_send(chan_, &t);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2023-06-11 18:34:41 +08:00
|
|
|
void pop(T& t) {
|
2018-11-30 14:38:22 +08:00
|
|
|
channel_recv(chan_, &t);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ACL_CHANNEL* chan_;
|
2020-06-24 16:46:05 +08:00
|
|
|
|
|
|
|
channel(const channel&);
|
|
|
|
void operator=(const channel&);
|
2018-11-30 14:38:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace acl
|