mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-15 17:30:53 +08:00
44 lines
831 B
C++
44 lines
831 B
C++
#include "acl_stdafx.hpp"
|
|
#ifndef ACL_PREPARE_COMPILE
|
|
#include "acl_cpp/stdlib/thread_queue.hpp"
|
|
#endif
|
|
|
|
namespace acl
|
|
{
|
|
|
|
thread_queue::thread_queue()
|
|
{
|
|
queue_ = (ACL_AQUEUE*) acl_aqueue_new();
|
|
}
|
|
|
|
static void free_qitem(void* item)
|
|
{
|
|
thread_qitem* qitem = (thread_qitem *) item;
|
|
delete qitem;
|
|
}
|
|
|
|
thread_queue::~thread_queue()
|
|
{
|
|
acl_aqueue_free(queue_, free_qitem);
|
|
}
|
|
|
|
bool thread_queue::push(thread_qitem* item)
|
|
{
|
|
return acl_aqueue_push(queue_, item) == -1 ? false : true;
|
|
}
|
|
|
|
thread_qitem* thread_queue::pop(int wait_ms /* = -1 */)
|
|
{
|
|
int wait_sec = wait_ms / 1000;
|
|
int wait_usec = (wait_ms % 1000) * 1000;
|
|
return (thread_qitem*) acl_aqueue_pop_timedwait(
|
|
queue_, wait_sec, wait_usec);
|
|
}
|
|
|
|
int thread_queue::qlen() const
|
|
{
|
|
return acl_aqueue_qlen(queue_);
|
|
}
|
|
|
|
} // namespace acl
|