add test code in mbox.hpp

This commit is contained in:
zhengshuxin 2017-09-02 17:59:32 +08:00
parent e31ae6c7d8
commit 7dadf786df
2 changed files with 35 additions and 2 deletions

View File

@ -78,8 +78,7 @@ int acl_mbox_send(ACL_MBOX *mbox, void *msg)
mbox->nsend++;
if (acl_vstream_writen(mbox->out, __key, sizeof(__key) - 1)
== ACL_VSTREAM_EOF)
{
== ACL_VSTREAM_EOF) {
return -1;
} else
return 0;

View File

@ -13,6 +13,40 @@ void* mbox_read(void*, int, bool*);
size_t mbox_nsend(void*);
size_t mbox_nread(void*);
/**
* 线 + IO
*
*
* :
*
* class myobj
* {
* public:
* myobj(void) {}
* ~myobj(void) {}
*
* void run(void)
* {
* printf("hello world!\r\n");
* }
* };
*
* acl::mbox<myobj> mbox;
*
* void thread_producer(void)
* {
* myobj* o = new myobj;
* mbox.push(o);
* }
*
* void thread_consumer(void)
* {
* myobj* o = mbox.pop();
* o->run();
* delete o;
* }
*/
template<typename T>
class mbox
{