1 消息隊列函數
ACE消息隊列由三個部分組成:消息隊列(ACE_Message_Queue)、消息塊(ACE_Message_Block)、數據塊(ACE_Data_Block)this
1.1 ACE_Data_Block:經過計數器來決定數據塊釋放時是否被刪除。只有計數器爲0時,對象纔會被刪除。spa
1.1.1 構造函數:.net
1 ACE_Data_Block (size_t size, 2 3 ACE_Message_Block::ACE_Message_Type msg_type, 4 5 const char *msg_data, 6 7 ACE_Allocator *allocator_strategy, 8 9 ACE_Lock *locking_strategy, 10 11 ACE_Message_Block::Message_Flags flags, 12 13 ACE_Allocator *data_block_allocator)
能夠由對象本身分配內存(msg_data=0),也能夠由使用者分配內存(賦值給msg_data),ACE_Data_Block進行管理。指針
1.1.2 獲得數據塊指針:code
char *base (void) const;
1.1.3 引用數據塊:計算器加1對象
ACE_Data_Block *duplicate (void);
1.1.4 釋放數據塊:當計算器減1,當計數器變成0後,就銷燬數據塊。blog
ACE_Data_Block *release (ACE_Lock *lock = 0);
1.2 ACE_Message_Block:數據塊的引用。由消息隊列管理。隊列
1.2.1 構造函數:內存
由數據塊構造消息塊:
ACE_Message_Block (ACE_Data_Block *data_block, Message_Flags flags = 0, ACE_Allocator *message_block_allocator = 0);
直接引用數據:
1 ACE_Message_Block (const char *data, 2 3 size_t size, 4 5 unsigned long priority) 6 7 8 9 ACE_Message_Block (size_t size, 10 11 ACE_Message_Type msg_type, 12 13 ACE_Message_Block *msg_cont, 14 15 const char *msg_data, 16 17 ACE_Allocator *allocator_strategy, 18 19 ACE_Lock *locking_strategy, 20 21 unsigned long priority, 22 23 const ACE_Time_Value &execution_time, 24 25 const ACE_Time_Value &deadline_time, 26 27 ACE_Allocator *data_block_allocator, 28 29 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
1 ACE_Message_Block::~ACE_Message_Block (void) 2 3 { 4 5 ACE_TRACE ("ACE_Message_Block::~ACE_Message_Block"); 6 7 8 9 if (ACE_BIT_DISABLED (this->flags_, 10 11 ACE_Message_Block::DONT_DELETE)&& 12 13 this->data_block ()) 14 15 this->data_block ()->release (); 16 17 18 19 this->prev_ = 0; 20 21 this->next_ = 0; 22 23 this->cont_ = 0; 24 25 }
1.3 ACE_Message_Queue:消息隊列
1.3.1 入列
1 enqueue (ACE_Message_Block *new_item, ACE_Time_Value *timeout) 2 3 enqueue_head (ACE_Message_Block *new_item, ACE_Time_Value *timeout) 4 5 enqueue_tail (ACE_Message_Block *new_item, ACE_Time_Value *timeout)
1.3.2 出列
1 dequeue (ACE_Message_Block *&first_item, ACE_Time_Value *timeout = 0); 2 3 dequeue_head (ACE_Message_Block *&first_item, ACE_Time_Value *timeout = 0); 4 5 dequeue_tail (ACE_Message_Block *&dequeued, ACE_Time_Value *timeout = 0);
1.4 ACE_Task:封裝了消息隊列:
1 // For the following five method if @a timeout == 0, the caller will 2 3 // block until action is possible, else will wait until the 4 5 // <{absolute}> time specified in *@a timeout elapses). These calls 6 7 // will return, however, when queue is closed, deactivated, when a 8 9 // signal occurs, or if the time specified in timeout elapses, (in 10 11 // which case errno = EWOULDBLOCK). 12 13 14 15 /// Insert message into the message queue. Note that @a timeout uses 16 17 /// <{absolute}> time rather than <{relative}> time. 18 19 int putq (ACE_Message_Block *, ACE_Time_Value *timeout = 0); 20 21 22 23 /** 24 25 * Extract the first message from the queue (blocking). Note that 26 27 * @a timeout uses <{absolute}> time rather than <{relative}> time. 28 29 * Returns number of items in queue if the call succeeds or -1 otherwise. 30 31 */ 32 33 int getq (ACE_Message_Block *&mb, ACE_Time_Value *timeout = 0); 34 35 36 37 /// Return a message to the queue. Note that @a timeout uses 38 39 /// <{absolute}> time rather than <{relative}> time. 40 41 int ungetq (ACE_Message_Block *, ACE_Time_Value *timeout = 0); 42 43 44 45 /** 46 47 * Turn the message around, sending it in the opposite direction in 48 49 * the stream. To do this, the message is put onto the task next in 50 51 * the stream after this task's sibling. 52 53 * 54 55 * @param mb Pointer to the block that is used in the reply. 56 57 * @param tv The absolute time at which the put operation used to 58 59 * send the message block to the next module in the stream 60 61 * will time out. If 0, this call blocks until it can be 62 63 * completed. 64 65 */ 66 67 int reply (ACE_Message_Block *mb, ACE_Time_Value *tv = 0); 68 69 70 71 /** 72 73 * Transfer message to the adjacent ACE_Task in a ACE_Stream. Note 74 75 * that @a timeout uses <{absolute}> time rather than <{relative}> 76 77 * time. 78 79 */ 80 81 int put_next (ACE_Message_Block *msg, ACE_Time_Value *timeout = 0);