ACE消息队列(转)
2024-09-04 13:14:59
1 消息队列
ACE消息队列由三个部分组成:消息队列(ACE_Message_Queue)、消息块(ACE_Message_Block)、数据块(ACE_Data_Block)
1.1 ACE_Data_Block:通过计数器来决定数据块释放时是否被删除。只有计数器为0时,对象才会被删除。
1.1.1 构造函数:
ACE_Data_Block (size_t size, ACE_Message_Block::ACE_Message_Type msg_type, const char *msg_data, ACE_Allocator *allocator_strategy, ACE_Lock *locking_strategy, ACE_Message_Block::Message_Flags flags, ACE_Allocator *data_block_allocator)
可以由对象自己分配内存(msg_data=0),也可以由使用者分配内存(赋值给msg_data),ACE_Data_Block进行管理。
1.1.2 得到数据块指针:
char *base (void) const;
1.1.3 引用数据块:计算器加1
ACE_Data_Block *duplicate (void);
1.1.4 释放数据块:当计算器减1,当计数器变成0后,就销毁数据块。
ACE_Data_Block *release (ACE_Lock *lock = );
1.2 ACE_Message_Block:数据块的引用。由消息队列管理。
1.2.1 构造函数:
由数据块构造消息块:
ACE_Message_Block (ACE_Data_Block *data_block, Message_Flags flags = , ACE_Allocator *message_block_allocator = );
直接引用数据:
ACE_Message_Block (const char *data, size_t size, unsigned long priority) ACE_Message_Block (size_t size, ACE_Message_Type msg_type, ACE_Message_Block *msg_cont, const char *msg_data, ACE_Allocator *allocator_strategy, ACE_Lock *locking_strategy, unsigned long priority, const ACE_Time_Value &execution_time, const ACE_Time_Value &deadline_time, ACE_Allocator *data_block_allocator, ACE_Allocator *message_block_allocator)
1.2.2 得到数据块指针:
ACE_Data_Block *data_block()
1.2.3 释放消息块:
ACE_Message_Block *release (void)
1.2.4 析构函数:
会调用内部数据块的release
ACE_Message_Block::~ACE_Message_Block (void) { ACE_TRACE ("ACE_Message_Block::~ACE_Message_Block"); if (ACE_BIT_DISABLED (this->flags_, ACE_Message_Block::DONT_DELETE)&& this->data_block ()) this->data_block ()->release (); this->prev_ = ; this->next_ = ; this->cont_ = ; }
1.3 ACE_Message_Queue:消息队列
1.3.1 入列
enqueue (ACE_Message_Block *new_item, ACE_Time_Value *timeout) enqueue_head (ACE_Message_Block *new_item, ACE_Time_Value *timeout) enqueue_tail (ACE_Message_Block *new_item, ACE_Time_Value *timeout)
1.3.2 出列
dequeue (ACE_Message_Block *&first_item, ACE_Time_Value *timeout = ); dequeue_head (ACE_Message_Block *&first_item, ACE_Time_Value *timeout = ); dequeue_tail (ACE_Message_Block *&dequeued, ACE_Time_Value *timeout = );
1.4 ACE_Task:封装了消息队列:
// For the following five method if @a timeout == 0, the caller will // block until action is possible, else will wait until the // <{absolute}> time specified in *@a timeout elapses). These calls // will return, however, when queue is closed, deactivated, when a // signal occurs, or if the time specified in timeout elapses, (in // which case errno = EWOULDBLOCK). /// Insert message into the message queue. Note that @a timeout uses /// <{absolute}> time rather than <{relative}> time. int putq (ACE_Message_Block *, ACE_Time_Value *timeout = ); /** * Extract the first message from the queue (blocking). Note that * @a timeout uses <{absolute}> time rather than <{relative}> time. * Returns number of items in queue if the call succeeds or -1 otherwise. */ int getq (ACE_Message_Block *&mb, ACE_Time_Value *timeout = ); /// Return a message to the queue. Note that @a timeout uses /// <{absolute}> time rather than <{relative}> time. int ungetq (ACE_Message_Block *, ACE_Time_Value *timeout = ); /** * Turn the message around, sending it in the opposite direction in * the stream. To do this, the message is put onto the task next in * the stream after this task's sibling. * * @param mb Pointer to the block that is used in the reply. * @param tv The absolute time at which the put operation used to * send the message block to the next module in the stream * will time out. If 0, this call blocks until it can be * completed. */ int reply (ACE_Message_Block *mb, ACE_Time_Value *tv = ); /** * Transfer message to the adjacent ACE_Task in a ACE_Stream. Note * that @a timeout uses <{absolute}> time rather than <{relative}> * time. */ int put_next (ACE_Message_Block *msg, ACE_Time_Value *timeout = );
转自:http://blog.csdn.net/kl222/article/details/8159812
最新文章
- MySQL下全文索引
- CSS盒子模型学习记录2
- Web app 的性能瓶颈与性能调优方法
- bzoj 2730: [HNOI2012]矿场搭建
- HDU1151Air Raid(二分图的最大匹配)
- css中的:before与:after的简单使用
- qt helper
- 20151221jqueryUI---日历UI代码备份
- 模拟dispatch_once
- HDU 5740 - Glorious Brilliance
- 浏览器与服务器间的交互(客服端 <;--->; 服务器)
- 基于visual Studio2013解决面试题之1408桶排序
- getResources提取资源文件
- shell参数处理模板
- Python cmp() 函数
- BeanUtils 日期转换(本地格式yyyy-MM-dd)转换成date
- [物理学与PDEs]第1章习题11 各向同性导体中电荷分布的指数衰减
- Linux启动过程简述
- Spring(mvc)思维导图
- directive例子1
热门文章
- CentOS 7 安装PHP7+Nginx+Mysql5.7开发环境
- foreach 与 Linq的 Select 效率问题
- [Jquery]斑马线表格
- HDU 1308 What Day Is It?(模拟,日期)
- HDU 1856 More is better (并查集)
- 15、Flask实战第15天:Flask-WTF
- [CF441E]Valera and Number
- 【动态规划】bzoj1613 [Usaco2007 Jan]Running贝茜的晨练计划
- 【mybatis】idea中 mybatis的mapper类去找对应的mapper.xml中的方法,使用插件mybatis-plugin
- Mysql -- Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’解决方法