acl  3.5.3.0
channel.hpp
浏览该文件的文档.
1 #pragma once
2 
3 #include "fiber_cpp_define.hpp"
4 
5 struct ACL_CHANNEL;
6 
7 namespace acl {
8 
9 ACL_CHANNEL *channel_create(int elemsize, int bufsize);
10 void channel_free(ACL_CHANNEL *c);
11 int channel_send(ACL_CHANNEL *c, void *v);
12 int channel_recv(ACL_CHANNEL *c, void *v);
13 
14 template <typename T>
15 class channel
16 {
17 public:
18  channel(void)
19  {
20  chan_ = channel_create(sizeof(T), 100);
21  }
22 
23  ~channel(void)
24  {
25  channel_free(chan_);
26  }
27 
29  {
30  return put(t);
31  }
32 
33  channel& put(T& t)
34  {
35  channel_send(chan_, &t);
36  return *this;
37  }
38 
39  void pop(T& t)
40  {
41  channel_recv(chan_, &t);
42  }
43 
44 private:
45  ACL_CHANNEL* chan_;
46 
47  channel(const channel&);
48  void operator=(const channel&);
49 };
50 
51 } // namespace acl
int channel_send(ACL_CHANNEL *c, void *v)
void channel_free(ACL_CHANNEL *c)
channel & put(T &t)
Definition: channel.hpp:33
struct ACL_CHANNEL ACL_CHANNEL
Definition: fiber_channel.h:15
int channel_recv(ACL_CHANNEL *c, void *v)
channel & operator<<(T &t)
Definition: channel.hpp:28
ACL_CHANNEL * channel_create(int elemsize, int bufsize)
channel(void)
Definition: channel.hpp:18
void pop(T &t)
Definition: channel.hpp:39
~channel(void)
Definition: channel.hpp:23