of 12 /12
Half-Sync/Half-Async 아키텍트를 꿈꾸는 사람들 발표 : 김연기

Half sync/Half Async

Embed Size (px)

Text of Half sync/Half Async

  • 1. Half-Sync/Half-Async :

2. Context IO IO ?? 3. Problem IO IO . IO IO . 4. Solution IO Layer IOLayer , Queueinglayer Layer . 5. StructureClass : Asynchronous LayerClass : Synchronous LayerResponsibility: IOResponsibility: IO Collaborator : Queueing Collaborator : Queueing Layer Layer External Event SourceClass : Queueing LayerClass : External EventSourceResponsibility: Layer Responsibility: Layer. IO Collaborator : Layer . LayerCollaborator : Layer 6. Structure (2)Synchronous Sync Service 1 Sync Service 2 Sync Service 3Service LayerQueueing QueueLayerAsynchronous External Async ServiceService LayerEvent Source 7. Dynamics 8. Implementation IO Layer IO Layer . IO Layer IO Layer External Event Source Queueing Layer Queue Thread Safe !! Sync Layer Async Layer ?? 9. Implementation(2)intACE_Message_Queue_NT::enqueue (ACE_Message_Block *new_item, ACE_Time_Value *){ACE_TRACE ("ACE_Message_Queue_NT::enqueue");ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1);if (this->state_ != ACE_Message_Queue_Base::DEACTIVATED){size_t const msize = new_item->total_size ();size_t const mlength = new_item->total_length ();// Note - we send ACTIVATED in the 3rd arg to tell the completion// routine its _NOT_ being woken up because of deactivate().ULONG_PTR state_to_post;state_to_post = ACE_Message_Queue_Base::ACTIVATED; if (::PostQueuedCompletionStatus (this->completion_port_,static_cast (msize),state_to_post,reinterpret_cast (new_item))) { // Update the states once I succeed. this->cur_bytes_ += msize; this->cur_length_ += mlength; return ACE_Utils::truncate_cast (++this->cur_count_); }}elseerrno = ESHUTDOWN;// Fail to enqueue the message.return -1;} 10. Implementation(2)intACE_Message_Queue_NT::dequeue (ACE_Message_Block *&first_item,ACE_Time_Value *timeout){ACE_TRACE ("ACE_Message_Queue_NT::dequeue_head"); {ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1);// Get a message from the completion port.int retv = ::GetQueuedCompletionStatus (this->completion_port_, &msize, &queue_state, reinterpret_cast (&first_item), (timeout == 0 ? INFINITE : timeout->msec ()));{ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1);--this->cur_thrs_; // Decrease waiting thread count.if (retv){if (queue_state == ACE_Message_Queue_Base::ACTIVATED){ // Really get a valid MB from the queue.--this->cur_count_;this->cur_bytes_ -= msize;this->cur_length_ -= first_item->total_length ();return ACE_Utils::truncate_cast (this->cur_count_);}else // Woken up by deactivate () or pulse ().errno = ESHUTDOWN;}}return -1;} 11. Conclusion .Sync IO Async IO . Copy Thread . . 12. ACEhttp://www.cs.wustl.edu/~schmidt/ACE.html