ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

muduo¿âÈçºÎÖ§³Ö¶àÏß³Ì(Ò»)
2013-11-20 14:23:42 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:959´Î
Tags£ºmuduo ÈçºÎ Ö§³Ö Ïß³Ì

    muduo¿âÈçºÎÖ§³Ö¶àÏß³Ì
    EventLoopThread£¨IOÏß³ÌÀࣩ
    EventLoopThreadPool£¨IOÏ̳߳ØÀࣩ
    IOÏ̳߳صŦÄÜÊÇ¿ªÆôÈô¸É¸öIOỊ̈߳¬²¢ÈÃÕâЩIOÏ̴߳¦ÓÚʼþÑ­»·µÄ״̬
    ÏÂÃæµÄÕâЩ´úÂë¿ÉÄܺÍÇ°Ãæ¸ø³öµÄÔ´´úÂëÓÐЩ²»Ò»Ñù£¬ÔĶÁµÄͬѧÇë×¢ÒâÁË
    EventLoopThreadPoolÍ·Îļþ
    eventloopthreadpool.h
    [cpp
    // Copyright 2010, Shuo Chen.  All rights reserved.
    // http://code.google.com/p/muduo/
    //
    // Use of this source code is governed by a BSD-style license
    // that can be found in the License file.
    // Author: Shuo Chen £¨chenshuo at chenshuo dot com£©
    //
    // This is an internal header file, you should not include this.
    #ifndef MUDUO_NET_EVENTLOOPTHREADPOOL_H
    #define MUDUO_NET_EVENTLOOPTHREADPOOL_H
    #include <muduo/base/Condition.h>
    #include <muduo/base/Mutex.h>
    #include <vector>
    #include <boost/function.hpp>
    #include <boost/noncopyable.hpp>
    #include <boost/ptr_container/ptr_vector.hpp>
    namespace muduo
    {
    namespace net
    {
    class EventLoop;
    class EventLoopThread;
    class EventLoopThreadPool : boost::noncopyable
    {
    public:
    typedef boost::function<void£¨EventLoop*£©> ThreadInitCallback;
    EventLoopThreadPool£¨EventLoop* baseLoop£©£»
    ~EventLoopThreadPool£¨£©£»
    void setThreadNum£¨int numThreads£© { numThreads_ = numThreads; }
    void start£¨const ThreadInitCallback& cb = ThreadInitCallback£¨£©£©£»
    EventLoop* getNextLoop£¨£©£»
    private:
    EventLoop* baseLoop_; // ÓëAcceptorËùÊôEventLoopÏàͬ
    bool started_;        /*ÊÇ·ñÆô¶¯*/
    int numThreads_;      // Ïß³ÌÊý
    int next_;            // ÐÂÁ¬½Óµ½À´£¬ËùÑ¡ÔñµÄEventLoop¶ÔÏóϱê
    boost::ptr_vector<EventLoopThread> threads_;        // IOÏß³ÌÁбí
    std::vector<EventLoop*> loops_;                 // EventLoopÁбí
    };
    }
    }
    #endif  // MUDUO_NET_EVENTLOOPTHREADPOOL_H
    EventLoopThreadPoolÔ´Îļþ
    eventloopthreadpool.cc
    [cpp]
    // Copyright 2010, Shuo Chen.  All rights reserved.
    // http://code.google.com/p/muduo/
    //
    // Use of this source code is governed by a BSD-style license
    // that can be found in the License file.
    // Author: Shuo Chen £¨chenshuo at chenshuo dot com£©
    #include <muduo/net/EventLoopThreadPool.h>
    #include <muduo/net/EventLoop.h>
    #include <muduo/net/EventLoopThread.h>
    #include <boost/bind.hpp>
    using namespace muduo;
    using namespace muduo::net;
    EventLoopThreadPool::EventLoopThreadPool£¨EventLoop* baseLoop£©
    : baseLoop_£¨baseLoop£©£¬  // ÓëAcceptorËùÊôEventLoopÏàͬ
    started_£¨false£©£¬
    numThreads_£¨0£©£¬
    next_£¨0£©
    {
    }
    EventLoopThreadPool::~EventLoopThreadPool£¨£©
    {
    // Don't delete loop, it's stack variable
    }

     

Ê×Ò³ ÉÏÒ»Ò³ 1 2 3 4 5 6 7 ÏÂÒ»Ò³ βҳ 1/13/13
¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£º¶þ²æÊ÷µÄ´´½¨ÓëµÝ¹é±éÀú ÏÂһƪ£º¿ìËÙÃݺÍÅ·À­º¯ÊýµÄÓÅ»¯Çó½â

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Linuxϵͳ¼ò½é (2025-12-25 21:55:25)
¡¤Linux°²×°MySQL¹ý³Ì (2025-12-25 21:55:22)
¡¤Linuxϵͳ°²×°½Ì³Ì£¨ (2025-12-25 21:55:20)
¡¤HTTP Åc HTTPS µÄ²î„ (2025-12-25 21:19:45)
¡¤ÍøÕ¾°²È«±ØÐ޿ΣºÍ¼ (2025-12-25 21:19:42)