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

女性手表网站开发网站做图文水印逻辑

女性手表网站,开发网站做图文水印逻辑,WordPress通讯目录,a站网址是什么本文使用内存屏障来 VolatileRead、VolatileWrite 保证读写重入自旋锁的当前线程ID#xff08;tid#xff09;#xff0c;如果不愿意采用内存屏障的方式来处理#xff0c;人们可以选择使用原子变量读写来代替。 C 置R/W内存屏障#xff1a; static inline void Mem…本文使用内存屏障来 VolatileRead、VolatileWrite 保证读写重入自旋锁的当前线程IDtid如果不愿意采用内存屏障的方式来处理人们可以选择使用原子变量读写来代替。 C 置R/W内存屏障 static inline void MemoryBarrier() noexcept{std::atomic_thread_fence(std::memory_order_seq_cst);} 头文件 #pragma once#include ppp/stdafx.hnamespace ppp {namespace threading{class SpinLock final{public:explicit SpinLock() noexcept;SpinLock(const SpinLock) delete;SpinLock(SpinLock) delete;~SpinLock() noexcept(false);public:SpinLock operator(const SpinLock) delete;public:bool TryEnter() noexcept;bool TryEnter(int loop, int timeout) noexcept;void Enter() noexcept;void Leave();inline bool IsLockTaken() noexcept { return _.load(); }public:inline void lock() noexcept { Enter(); }inline void unlock() noexcept { Leave(); }public:std::atomicbool _;};class RecursiveSpinLock final{public:explicit RecursiveSpinLock() noexcept;RecursiveSpinLock(const RecursiveSpinLock) delete;RecursiveSpinLock(RecursiveSpinLock) delete;~RecursiveSpinLock() default;public:RecursiveSpinLock operator(const RecursiveSpinLock) delete;public:bool TryEnter() noexcept;bool TryEnter(int loop, int timeout) noexcept;void Enter() noexcept;void Leave();inline bool IsLockTaken() noexcept { return lockobj_.IsLockTaken(); }public:inline void lock() noexcept { Enter(); }inline void unlock() noexcept { Leave(); }public:SpinLock lockobj_;volatile int tid_;std::atomicint reentries_;};} } 源文件 #include ppp/threading/SpinLock.h #include ppp/threading/Thread.hnamespace ppp {namespace threading{template class LockObjectstatic constexpr bool Lock_TryEnter(LockObject lock, int loop,int timeout) noexcept{bool lockTaken false;if (loop -1){uint64_t last GetTickCount();for (int i 0; i loop; i){lockTaken lock.TryEnter();if (lockTaken){break;}if (timeout -1){uint64_t now GetTickCount();int64_t diff now - last;if (diff timeout){break;}}}}else{uint64_t last GetTickCount();for (;;){lockTaken lock.TryEnter();if (lockTaken){break;}if (timeout -1){uint64_t now GetTickCount();int64_t diff now - last;if (diff timeout){break;}}}}return lockTaken;}template class LockObject, class LockInternalObject, typename... TryEnterArgumentsstatic constexpr bool RecursiveLock_TryEnter(LockObject lock, LockInternalObject lock_internal, volatile int* tid,std::atomicint reentries, TryEnterArguments... arguments){int n reentries;assert(n 0);int current_tid std::hashstd::thread::id{}(std::this_thread::get_id());if (n 1){bool lockTaken lock_internal.TryEnter(std::forwardTryEnterArguments(arguments)...);if (!lockTaken){reentries--;return false;}Thread::MemoryBarrier();*tid current_tid;Thread::MemoryBarrier();}else{Thread::MemoryBarrier();int lockTaken_tid *tid;Thread::MemoryBarrier();if (lockTaken_tid current_tid){lock.Leave();return false;}}return true;}SpinLock::SpinLock() noexcept: _(false){}SpinLock::~SpinLock() noexcept(false){bool lockTaken IsLockTaken();if (lockTaken){throw std::runtime_error(fail to release the atomic lock.);}}void SpinLock::Enter() noexcept{for (;;) {bool lockTaken TryEnter();if (lockTaken){break;}}}bool SpinLock::TryEnter(int loop, int timeout) noexcept{return Lock_TryEnter(*this, loop, timeout);}bool SpinLock::TryEnter() noexcept{bool expected false;return _.compare_exchange_strong(expected, true, std::memory_order_acquire);}void SpinLock::Leave(){bool expected true;if (!_.compare_exchange_strong(expected, false, std::memory_order_release)){throw std::runtime_error(failed to acquire the atomic lock.);}}RecursiveSpinLock::RecursiveSpinLock() noexcept: lockobj_(), tid_(0), reentries_(0){}bool RecursiveSpinLock::TryEnter() noexcept{return RecursiveLock_TryEnter(*this, lockobj_, tid_, reentries_);}bool RecursiveSpinLock::TryEnter(int loop, int timeout) noexcept{return RecursiveLock_TryEnter(*this, lockobj_, tid_, reentries_, loop, timeout);}void RecursiveSpinLock::Enter() noexcept{for (;;){bool lockTaken TryEnter();if (lockTaken){break;}}}void RecursiveSpinLock::Leave() {int n --reentries_;assert(n 0);if (n 0){lockobj_.Leave();}}} }
http://www.yutouwan.com/news/138083/

相关文章:

  • wordpress视频网站主题免费个人服务器
  • 运行网站需要多少钱餐饮系统的网站应该怎么做
  • 茶叶网站建设策划方案u001f展会信息网
  • jsp书城网站开发网页访问自动跳转中
  • 网站优秀设计站长如何做视频类网站
  • 湖北移动官网网站建设东莞公司网站制作公司
  • 网站关键词排名公司公关是陪吃陪喝的吗
  • 重庆网站建设哪个公司好安徽六安金寨县
  • 外贸鞋的网站建设wordpress要不要套餐
  • 网站建设所需技术wordpress 分类伪静态
  • 手机网站 案例WordPress文章底部广告插件
  • 个人免费网站开发sem优化师底薪一般多少
  • 找个人给我做电影网站seo每天一贴
  • 东莞营销网站建火龙果写作网站
  • 门户网站制作流程博客现在asp做网站
  • 网上做兼职的网站有哪些工作网站备案许可证号查询网站
  • 素材网站可以做淘宝吗网站建设需要考虑的问题
  • 学敏网站建设国际网站建设与维护
  • 怎样在华为云服务器里建设网站沃尔玛超市
  • 网站实名认证功能怎么做做毕业设计的网站设计
  • wordpress 首页描述上海建站 seo
  • 天津非常好的网站建设浙江省网站集约化建设通知
  • 网站后台文章编辑不了最近中国新闻事件
  • 舟山建设银行网站Xammp安装Wordpress
  • wordpress 无法下载主题淄博seo费用
  • 大型网站开发软件网站续费话术
  • 一手楼房可以做哪个网站2022年5月国内重大新闻
  • wordpress 4.0 中文版怀化 优化营商环境
  • 关闭网站后弹窗代码优设网的吉祥物
  • vs2015 asp网站开发中文资源在线官网