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

做网站搞什么流量wordpress主题绑定域名

做网站搞什么流量,wordpress主题绑定域名,南宁网站建设 醉懂网络,wordpress 重装界面在java开发中#xff0c;习惯使用Handler、Message来处理同步#xff0c;比如对相机的操作(open、setParamters、start、stop、clost)全部抛到同一个线程处理#xff0c;防止并发操作导致异常#xff0c;这样保留给外部的统一接口就是安全的#xff0c;无论外部哪些线程来…在java开发中习惯使用Handler、Message来处理同步比如对相机的操作(open、setParamters、start、stop、clost)全部抛到同一个线程处理防止并发操作导致异常这样保留给外部的统一接口就是安全的无论外部哪些线程来调用最终到控制模块都是在同一线程处理相机操作。这里提供一个C实现的Handler Message封装可以实现类似安卓那样的接口 Handler类封装 #ifndef _CPP_THREADHANDLER_H #define _CPP_THREADHANDLER_H#include algorithm #include chrono #include condition_variable #include functional #include iostream #include list #include map #include memory #include mutex #include thread #include Message.hclass ThreadHandler {public:using TimePoint_t std::chrono::steady_clock::time_point;using Clock_t std::chrono::steady_clock;using MillisDuration_t std::chrono::milliseconds;using Task std::functionvoid(const Message msg);ThreadHandler() : _stoped(false) { initLoop(); }~ThreadHandler() {_stoped true;_cond.notify_all();_looper.join();}void setName(const std::string n) { this-name n; }bool sendEmptyMessageDelay(int what, long delay_millis) {if (what 0 || delay_millis 0)return false;Message msg(what, delay_millis);std::unique_lockstd::mutex lock(_queue_lock);_msg_list.push_back(msg);_msg_list.sort(std::lessMessage());_cond.notify_all();return true;}bool sendEmptyMessageDelay(int what) {return sendEmptyMessageDelay(what, 0);}bool postDelay(std::functionvoid() f, long delay_millis) {if (f nullptr || delay_millis 0) {return false;}std::unique_lockstd::mutex lock(_queue_lock);Message msg(0, delay_millis);msg.onRun(std::move(f));_msg_list.push_back(msg);_msg_list.sort(std::lessMessage());_cond.notify_all();return true;}bool post(std::functionvoid() f) { return postDelay(std::move(f), 0); }void removeMessages(int what) {if (what 0)return;std::unique_lockstd::mutex lock(_queue_lock);if (!_msg_list.empty())_msg_list.remove_if([what](const Message m) { return m.what what; });}void removeAlls() {std::unique_lockstd::mutex lock(_queue_lock);if (!_msg_list.empty())_msg_list.clear();printf(ThreadHandler::removeAlls name: %s,name.c_str());}void stop() {_stoped true;_cond.notify_all();printf(ThreadHandler::stop name: %s, name.c_str());}void handleMessage(Task cb) { _callback cb; }private:void dispatchMessage(const Message msg) const {if (msg.task ! nullptr) {msg.task();} else {if (msg.what 0 || _callback nullptr)return;_callback(msg);}}void initLoop() {_looper std::thread([this]() {while (true) {Message msg;bool isFired false;{std::unique_lockstd::mutex lock(_queue_lock);if (_msg_list.empty()) {_cond.wait(lock, [this] {return _stoped || !_msg_list.empty();});} else {auto front _msg_list.front();// 如果要when 大于 当前时间则休眠否则继续往下执行if (front.when Clock_t::now()) {if (front.when Clock_t::now() maxSleepTime) {printf(ThreadHandler::initLoop time too long name: %s, when: %s ,now: %s , maxSleepTime: %s,name.c_str(),std::to_string(std::chrono::duration_caststd::chrono::seconds(front.when.time_since_epoch()).count()).c_str(),std::to_string(std::chrono::duration_caststd::chrono::seconds(Clock_t::now().time_since_epoch()).count()).c_str(),std::to_string(std::chrono::duration_caststd::chrono::seconds(maxSleepTime).count()).c_str());}_cond.wait_until(lock, front.when, [this] {return _stoped || (!_msg_list.empty() _msg_list.front().when Clock_t::now());});}}if (!_stoped _msg_list.empty())continue;if (_stoped) {_msg_list.clear();return;}// List的头结点的时间小于等于当前时间则执行头结点任务if (_msg_list.front().when Clock_t::now()) {msg std::move(_msg_list.front());_msg_list.pop_front();isFired true;}}if (isFired) {dispatchMessage(msg);}}});}bool _stoped;std::string name;std::listMessage _msg_list;std::mutex _queue_lock;std::condition_variable _cond;std::thread _looper;Task _callback;std::chrono::minutes maxSleepTime{4}; };#endif // _CPP_THREADHANDLER_HMessage实现类 #ifndef _CPP_MESSAGE_H #define _CPP_MESSAGE_H #include chrono #include condition_variable #include functional #include iostream #include list #include map #include memory #include mutex #include threadclass Message {public:using TimePoint_t std::chrono::steady_clock::time_point;using Clock_t std::chrono::steady_clock;using MillisDuration_t std::chrono::milliseconds;int what;int m_arg1;int m_arg2;std::functionvoid() task;TimePoint_t when;Message() : Message(-1, 0) {}Message(int what) : Message(what, 0) {}Message(int what, long delayMillis): what(what), when(Clock_t::now() MillisDuration_t(delayMillis)) {task nullptr;}Message(const Message msg): what(msg.what), task(msg.task), when(msg.when) {}Message(Message msg) : what(msg.what), task(msg.task), when(msg.when) {}~Message() {}Message operator(const Message msg) {this-what msg.what;this-when msg.when;this-task msg.task;return *this;}Message operator(Message msg) {this-what msg.what;this-when msg.when;this-task std::move(msg.task);return *this;}void setWhen(long delayMillis) {when Clock_t::now() MillisDuration_t(delayMillis);}void onRun(std::functionvoid() f) { this-task f; }bool operator(const Message msg) const { return (this-when msg.when); }bool operator(const Message msg) const { return (this-when msg.when); }bool operator(const Message msg) const {return (this-what msg.what) (this-task ! nullptr) (msg.task ! nullptr);}bool operator(int what) const { return (this-what what); } };#endif // _CPP_MESSAGE_H使用方法 //构造函数或类初始化中设置如下 mHandler.setName(classATh); mHandler.handleMessage([](const Message msg) { handleMessage(msg); }); void classATh::handleMessage(const Message msg) { if (msg.what MSG_CODE_QUERY_DEVICE_INFO) { // } else if (msg.what MSG_CODE_TRADE_INIT) { // } else if (msg.what MSG_CODE_DEVICE_HEART_BEAT) { heartBeat(); } } void classATh::startHearBeat() { mHandler.removeMessages(MSG_CODE_DEVICE_HEART_BEAT); mHandler.sendEmptyMessageDelay(MSG_CODE_DEVICE_HEART_BEAT, 60 * 1000); }
http://www.dnsts.com.cn/news/9920.html

相关文章:

  • 电商网站开发的功能拉新工作室在哪里接项目
  • 做网站怎么打不开localhostip网站查询服务器
  • 北京做网站源代码的网站空间大小查询
  • 怎么在电脑上自己做网站wordpress调用视频播放器
  • 网站建设中 敬请期待怎么解决买空间网
  • html5 网站模板下载路桥贝斯特做网站好吗
  • 深圳 网站设计优秀网页设计作品分析ppt
  • 苏州手机网站建设费用wordpress 插件 文章
  • 万网域名中文网站查询asp服装网站源码
  • 销售网站建设工资多少房产网站排行
  • 网站建设经验分享官方网站建设 就问磐石网络专业
  • 什么是网站死链如何做文献ppt模板下载网站
  • WordPress资讯站点源码网店运营培训哪里好
  • 河南省住房城乡建设厅网站苏州有哪些做网站
  • 佛山做公司网站家装设计师个人简介
  • 北京通州住房和城乡建设部网站卫星宽带app
  • 网站空间费装饰工程包括哪些主要内容
  • 城阳网站建设公司电话没文化可以学网络营销吗
  • 做第一个网站什么类型wordpress function
  • 买源码做网站值吗网站死链是什么
  • 微信服务号绑定网站万能视频解析接口网站怎么做
  • 做城市门户网站怎么发展揭西网站建设
  • wordpress金融网站模板游戏开科技软件免费
  • 网站广告推广怎么做的网页新建站点
  • 网站建设捌金手指花总二六免费建网站服务最好的公司
  • 建设网站难吗深投建设深圳有限公司
  • 网站开发者购物支付模板网站建设模板哪里下载
  • 广州vps网站优秀的网站首页
  • 企业网站建设设计西安做网站的公司哪家好
  • 网站seo置顶广州网站建设正规公司