2017-04-07 20:13:08 +08:00
|
|
|
|
#pragma once
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../acl_cpp_define.hpp"
|
|
|
|
|
#include "noncopyable.hpp"
|
2017-04-07 20:13:08 +08:00
|
|
|
|
|
|
|
|
|
struct ACL_MBOX;
|
|
|
|
|
|
|
|
|
|
namespace acl
|
|
|
|
|
{
|
|
|
|
|
|
2017-09-01 18:59:42 +08:00
|
|
|
|
//class ACL_CPP_API mbox : public noncopyable
|
|
|
|
|
template<typename T>
|
|
|
|
|
class mbox
|
2017-04-07 20:13:08 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
mbox(void);
|
2017-09-01 18:59:42 +08:00
|
|
|
|
~mbox(void) {}
|
2017-04-07 20:13:08 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2017-09-01 18:59:42 +08:00
|
|
|
|
* @param t {T*} <EFBFBD>ǿ<EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2017-04-07 20:13:08 +08:00
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
2017-09-01 18:59:42 +08:00
|
|
|
|
bool push(T* t)
|
|
|
|
|
{
|
|
|
|
|
return push_one((void*) t);
|
|
|
|
|
}
|
2017-04-07 20:13:08 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2017-08-29 11:32:07 +08:00
|
|
|
|
* @param timeout {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 ʱ<EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><EFBFBD>ȴ<EFBFBD><EFBFBD><EFBFBD>ʱʱ<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD>뼶<EFBFBD><EFBFBD>)<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD>Զ<EFBFBD>ȴ<EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2017-04-07 20:13:08 +08:00
|
|
|
|
* @param success {bool*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
2017-09-01 18:59:42 +08:00
|
|
|
|
* @return {T*} <EFBFBD><EFBFBD> NULL <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ NULL ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>
|
2017-04-07 20:13:08 +08:00
|
|
|
|
* success <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
2017-09-01 18:59:42 +08:00
|
|
|
|
T* pop(int timeout = 0, bool* success = NULL)
|
|
|
|
|
{
|
|
|
|
|
return (T*) pop_one(timeout, success);
|
|
|
|
|
}
|
2017-04-07 20:13:08 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ͳ<EFBFBD>Ƶ<EFBFBD>ǰ<EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>
|
|
|
|
|
* @return {size_t}
|
|
|
|
|
*/
|
|
|
|
|
size_t push_count(void) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ͳ<EFBFBD>Ƶ<EFBFBD>ǰ<EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>
|
|
|
|
|
* @return {size_t}
|
|
|
|
|
*/
|
|
|
|
|
size_t pop_count(void) const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ACL_MBOX* mbox_;
|
2017-09-01 18:59:42 +08:00
|
|
|
|
|
|
|
|
|
bool push_one(void* o);
|
|
|
|
|
void* pop_one(int timeout, bool* success);
|
2017-04-07 20:13:08 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|