mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-15 01:10:52 +08:00
49 lines
714 B
C++
49 lines
714 B
C++
#pragma once
|
|
|
|
#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>
|
|
class channel : public noncopyable
|
|
{
|
|
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
|