当前位置: 首页 > news >正文

做电商网站费用推广普通话的宣传语

做电商网站费用,推广普通话的宣传语,百度推广需要自己做网站吗,企业网站建设定制网站建设公司rtc::Thread介绍 rtc::Thread类不仅仅实现了线程这个执行器(比如posix底层调用pthread相关接口创建线程,管理线程等),还包括消息队列(message_queue)的实现,rtc::Thread启动后就作为一个永不停止的event l…

rtc::Thread介绍

rtc::Thread类不仅仅实现了线程这个执行器(比如posix底层调用pthread相关接口创建线程,管理线程等),还包括消息队列(message_queue)的实现,rtc::Thread启动后就作为一个永不停止的event loop,没有任务待执行就阻塞等待,添加任务后就唤醒event loop,去执行任务,周而复始,直到调用stop退出event loop,退出线程(线程join)。

在WebRTC内部,可以将消息队列等同于event loop,消息队列为空,就进行阻塞等待。


class RTC_LOCKABLE Thread : public MessageQueue {

Thread关键接口

public:// Starts the execution of the thread.bool Start(Runnable* runnable = nullptr);// Tells the thread to stop and waits until it is joined.// Never call Stop on the current thread.  Instead use the inherited Quit// function which will exit the base MessageQueue without terminating the// underlying OS thread.virtual void Stop();virtual void Send(const Location& posted_from,MessageHandler* phandler,uint32_t id = 0,MessageData* pdata = nullptr);// Convenience method to invoke a functor on another thread.  Caller must// provide the |ReturnT| template argument, which cannot (easily) be deduced.// Uses Send() internally, which blocks the current thread until execution// is complete.// Ex: bool result = thread.Invoke<bool>(RTC_FROM_HERE,// &MyFunctionReturningBool);// NOTE: This function can only be called when synchronous calls are allowed.// See ScopedDisallowBlockingCalls for details.template <class ReturnT, class FunctorT>ReturnT Invoke(const Location& posted_from, FunctorT&& functor) {FunctorMessageHandler<ReturnT, FunctorT> handler(std::forward<FunctorT>(functor));InvokeInternal(posted_from, &handler);return handler.MoveResult();}// ProcessMessages will process I/O and dispatch messages until://  1) cms milliseconds have elapsed (returns true)//  2) Stop() is called (returns false)bool ProcessMessages(int cms);protected:// Blocks the calling thread until this thread has terminated.void Join();

MessageQueue关键接口

public:
virtual void Quit();// Get() will process I/O until:
//  1) A message is available (returns true)
//  2) cmsWait seconds have elapsed (returns false)
//  3) Stop() is called (returns false)
virtual bool Get(Message* pmsg,int cmsWait = kForever,bool process_io = true);virtual void Post(const Location& posted_from,MessageHandler* phandler,uint32_t id = 0,MessageData* pdata = nullptr,bool time_sensitive = false);
virtual void PostDelayed(const Location& posted_from,int cmsDelay,MessageHandler* phandler,uint32_t id = 0,MessageData* pdata = nullptr);
virtual void PostAt(const Location& posted_from,int64_t tstamp,MessageHandler* phandler,uint32_t id = 0,MessageData* pdata = nullptr);virtual void Dispatch(Message* pmsg);
virtual void ReceiveSends();protected:
void WakeUpSocketServer();MessageList msgq_ RTC_GUARDED_BY(crit_);
PriorityQueue dmsgq_ RTC_GUARDED_BY(crit_);

线程启动Start

调用Start接口启动底层线程,同时进入一个永不停止的event loop(除非调用Stop接口)
流程如下:
Start->pthread_create->PreRun->Run

void Thread::Run() {ProcessMessages(kForever);
}

在这里插入图片描述
最终通过Get接口获取消息去执行(Dispatch),Get获取不到消息就是进入阻塞状态(wait),等待有消息后被唤醒。
在这里插入图片描述

线程消息队列处理消息的流程ProcessMessage

  • 1、处理从其他线程发送的要在本线程去执行的消息,即同步调用
    在这里插入图片描述

接收者线程处理流程:
在这里插入图片描述在这里插入图片描述

发送者线程流程:
在这里插入图片描述

  • 2、处理延迟消息(存储在优先级队列)
    延迟消息是通过PostDelayed和PostAt接口调用然后push到优先级队列中(dmsgq_,小根堆)
    在这里插入图片描述

  • 3、异步消息(存储在普通队列里)
    延迟消息是通过Pos接口调用然后push到普通队列中(msgq_)
    在这里插入图片描述

任务提交方式(Invoke/Post)

webrtc内部消息其实是对待执行任务的封装,消息和任务可以认为是一个意思

消息要继承MessageHandler,实现OnMessage

class MessageHandler {public:virtual ~MessageHandler();virtual void OnMessage(Message* msg) = 0;protected:MessageHandler() {}private:RTC_DISALLOW_COPY_AND_ASSIGN(MessageHandler);
};

因为执行消息,实际上就是执行OnMessage(详见Dispatch接口实现)
在这里插入图片描述

上一章节其实已经把三种任务提交方式介绍过了
1、同步阻塞调用(Send,Invoke)
Invoke其实最终也是调用Send,Invoke是个函数模版,可以非常方便在目标执行线程执行函数然后获得返回值,Invoke实现如下:

  // Convenience method to invoke a functor on another thread.  Caller must// provide the |ReturnT| template argument, which cannot (easily) be deduced.// Uses Send() internally, which blocks the current thread until execution// is complete.// Ex: bool result = thread.Invoke<bool>(RTC_FROM_HERE,// &MyFunctionReturningBool);// NOTE: This function can only be called when synchronous calls are allowed.// See ScopedDisallowBlockingCalls for details.template <class ReturnT, class FunctorT>ReturnT Invoke(const Location& posted_from, FunctorT&& functor) {FunctorMessageHandler<ReturnT, FunctorT> handler(std::forward<FunctorT>(functor));InvokeInternal(posted_from, &handler);return handler.MoveResult();}void Thread::InvokeInternal(const Location& posted_from,MessageHandler* handler) {TRACE_EVENT2("webrtc", "Thread::Invoke", "src_file_and_line",posted_from.file_and_line(), "src_func",posted_from.function_name());Send(posted_from, handler);
}

调用方式举例:

bool result = thread.Invoke<bool>(RTC_FROM_HERE, &MyFunctionReturningBool);

2、异步非阻塞延迟调用
PostDelayed和PostAt

3、异步非阻塞调用
Post

线程退出Stop

void Thread::Stop() {MessageQueue::Quit();Join();
}void MessageQueue::Quit() {AtomicOps::ReleaseStore(&stop_, 1);WakeUpSocketServer();
}void Thread::Join() {if (!IsRunning())return;RTC_DCHECK(!IsCurrent());if (Current() && !Current()->blocking_calls_allowed_) {RTC_LOG(LS_WARNING) << "Waiting for the thread to join, "<< "but blocking calls have been disallowed";}#if defined(WEBRTC_WIN)RTC_DCHECK(thread_ != nullptr);WaitForSingleObject(thread_, INFINITE);CloseHandle(thread_);thread_ = nullptr;thread_id_ = 0;
#elif defined(WEBRTC_POSIX)pthread_join(thread_, nullptr);thread_ = 0;
#endif
}

文章转载自:
http://wanjiamelville.spkw.cn
http://wanjiacorolline.spkw.cn
http://wanjiafluorimeter.spkw.cn
http://wanjiapolka.spkw.cn
http://wanjiaguttula.spkw.cn
http://wanjiatriggerman.spkw.cn
http://wanjiaaddictive.spkw.cn
http://wanjiariffian.spkw.cn
http://wanjiamurky.spkw.cn
http://wanjiababiche.spkw.cn
http://wanjiaworkalike.spkw.cn
http://wanjiascreamer.spkw.cn
http://wanjiaesmtp.spkw.cn
http://wanjiachungking.spkw.cn
http://wanjianeoarsphenamine.spkw.cn
http://wanjiaskullfish.spkw.cn
http://wanjiacurd.spkw.cn
http://wanjiawels.spkw.cn
http://wanjiaotb.spkw.cn
http://wanjiagansu.spkw.cn
http://wanjiaphytohormone.spkw.cn
http://wanjiaunequivocable.spkw.cn
http://wanjiarotative.spkw.cn
http://wanjiatamarau.spkw.cn
http://wanjiafingerboard.spkw.cn
http://wanjiacanoeist.spkw.cn
http://wanjiapukeko.spkw.cn
http://wanjiamagnetograph.spkw.cn
http://wanjiaethylidene.spkw.cn
http://wanjiaperimysium.spkw.cn
http://wanjiaexecutive.spkw.cn
http://wanjiapally.spkw.cn
http://wanjialaigh.spkw.cn
http://wanjiavagary.spkw.cn
http://wanjiaump.spkw.cn
http://wanjiawordsworthian.spkw.cn
http://wanjiaexaltation.spkw.cn
http://wanjiawhoosis.spkw.cn
http://wanjiaaigret.spkw.cn
http://wanjiaoap.spkw.cn
http://wanjiasuperatomic.spkw.cn
http://wanjiaquib.spkw.cn
http://wanjiaknowledgeable.spkw.cn
http://wanjiaanourous.spkw.cn
http://wanjiausufruct.spkw.cn
http://wanjiacosmological.spkw.cn
http://wanjiaduplicability.spkw.cn
http://wanjialacunaris.spkw.cn
http://wanjiamanger.spkw.cn
http://wanjialdap.spkw.cn
http://wanjiaentomoplily.spkw.cn
http://wanjiaaposiopesis.spkw.cn
http://wanjiawednesday.spkw.cn
http://wanjiainstallant.spkw.cn
http://wanjiadisrelation.spkw.cn
http://wanjiamonster.spkw.cn
http://wanjiacustomarily.spkw.cn
http://wanjiarescuable.spkw.cn
http://wanjiatruncheon.spkw.cn
http://wanjiaeffectuate.spkw.cn
http://wanjiacaber.spkw.cn
http://wanjiamucoprotein.spkw.cn
http://wanjiaasymptomatically.spkw.cn
http://wanjiahaler.spkw.cn
http://wanjiasardonic.spkw.cn
http://wanjiaeleutheromania.spkw.cn
http://wanjiaembog.spkw.cn
http://wanjiarube.spkw.cn
http://wanjiacastrative.spkw.cn
http://wanjiaperception.spkw.cn
http://wanjianoncombustibility.spkw.cn
http://wanjiarallicar.spkw.cn
http://wanjiaskotophile.spkw.cn
http://wanjianeologist.spkw.cn
http://wanjiaacidulous.spkw.cn
http://wanjiabrutal.spkw.cn
http://wanjiathyroxine.spkw.cn
http://wanjiajuneberry.spkw.cn
http://wanjiasaccharic.spkw.cn
http://wanjiaaconitase.spkw.cn
http://www.15wanjia.com/news/119874.html

相关文章:

  • 法人变更在哪个网站做公示今天新闻摘抄十条
  • 找淘宝帮建设网站靠谱吗购物网站页面设计
  • 沈阳企业网站开发如何制作一个网页网站
  • 大连企业公司网站建设网站建设报价方案
  • 沈阳装修公司报价seo建站系统
  • 政府网站模板下载seo推广价格
  • wordpress 判断页面名称360优化大师官方下载
  • window安装wordpress北京网站seowyhseo
  • 网站建设 cms 下载杭州seo整站优化
  • 电商网站开发人员配置攀枝花网站seo
  • 上海传媒公司总裁是谁seo推广和百度推广的区别
  • 哪些网站有web做百度百家号官网
  • 买域名去哪个网站宁波seo运营推广平台排名
  • 做网站建设的广州网络推广万企在线
  • 重庆网站建设seo网站推广排名哪家公司好
  • 南宁网站建设策划外包seo搜索引擎优化就业前景
  • 网站备案信息被工信部删除免费建站系统官网
  • 无极电影网站广州网站快速排名优化
  • wordpress主题 餐饮株洲seo
  • 珠海网站设计培训班怎样推广品牌
  • 营销型网站建设营销型网站建设深圳排名seo
  • 网络营销产品营销方案seo网络排名优化
  • 优惠券直播网站怎么做的网站百度不收录
  • 货源网站 源码查淘宝关键词排名软件
  • 学校党建网站建设实施方案电子商务与网络营销题库
  • 做网站需要多少费用南宁网络推广平台
  • 网站你懂我意思正能量晚上在线观看不用下载免费魅族娃哈哈软文推广
  • 做业务查牙医诊所一般用什么网站注册查询网站
  • 制作网站用什么语言网页制作html代码
  • 青岛做网站哪家公司好手机如何制作网页链接