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>
|
2019-05-09 13:57:51 +08:00
|
|
|
class channel : public noncopyable
|
2018-11-30 14:38:22 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
channel(void)
|
|
|
|
{
|
|
|
|
chan_ = channel_create(sizeof(T), 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
~channel(void)
|
|
|
|
{
|
|
|
|
channel_free(chan_);
|
|
|
|
}
|
|
|
|
|
|
|
|
channel& operator << (T& t)
|
|
|
|
{
|
|
|
|
return put(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
channel& put(T& t)
|
|
|
|
{
|
|
|
|
channel_send(chan_, &t);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pop(T& t)
|
|
|
|
{
|
|
|
|
channel_recv(chan_, &t);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ACL_CHANNEL* chan_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace acl
|