google base之LockImpl
为了兼容不同的平台,这个类采用了impl模式,win平台通过CRITICAL_SECTION, 这样的话还是相对比较简单,具体就不详解了,不过不得不说boost的实现方式就要复杂到哪里去了,当然,好处就是功能强大,坏处就是学习成本高,会用的人少。
#if defined(OS_WIN)
#include <windows.h>
#elif defined(OS_POSIX)
#include <pthread.h>
#endif #include "base/base_export.h"
#include "base/basictypes.h" namespace base {
namespace internal { // This class implements the underlying platform-specific spin-lock mechanism
// used for the Lock class. Most users should not use LockImpl directly, but
// should instead use Lock.
class BASE_EXPORT LockImpl {
public:
#if defined(OS_WIN)
typedef CRITICAL_SECTION NativeHandle;
#elif defined(OS_POSIX)
typedef pthread_mutex_t NativeHandle;
#endif LockImpl();
~LockImpl(); // If the lock is not held, take it and return true. If the lock is already
// held by something else, immediately return false.
bool Try(); // Take the lock, blocking until it is available if necessary.
void Lock(); // Release the lock. This must only be called by the lock's holder: after
// a successful call to Try, or a call to Lock.
void Unlock(); // Return the native underlying lock.
// TODO(awalker): refactor lock and condition variables so that this is
// unnecessary.
NativeHandle* native_handle() { return &native_handle_; } private:
NativeHandle native_handle_; DISALLOW_COPY_AND_ASSIGN(LockImpl);
}; } // namespace internal
} // namespace base #endif // BASE_SYNCHRONIZATION_LOCK_IMPL_H_
google base之LockImpl的更多相关文章
- colmap编译过程中出现,无法解析的外部符号错误 “__cdecl google::base::CheckOpMessageBuilder::ForVar1(void)”
错误提示: >colmap.lib(matching.obj) : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: cl ...
- google base库之simplethread
// This is the base SimpleThread. You can derive from it and implement the // virtual Run method, or ...
- google base 之MessagePumpForUI
base库中比较有意思就是这个类了,如同很多界面库一样,创建了一个隐藏窗口来处理需要在界面线程处理的消息,大体原理也就是需要执行task的时候发送一个自定义的消息,当窗口接收到task的时候调用保存起 ...
- google base之IncomingTaskQueue
如同名称描述的那样,这个类就是个taskqueue,也就是任务队列,添加任务到队列,然后由MessageLoop去执行task,比较关心的函数如下: bool IncomingTaskQueue::A ...
- google base库中的WaitableEvent
这个类说白了就是对windows event的封装,没有什么特别的,常规做法,等侍另一线程无非就是等侍事件置信waitsingleobject,通知事件无非就是setevent,一看就明白,不就详解, ...
- 谷歌 google
google Google是搜索引擎名,也是一家美国上市公司名称.Google公司于1998年9月7日以私有股份公司的形式创立,以设计并管理一个互联网的搜索引擎.Google公司的总部称作“Googl ...
- Windows平台下和跨平台的相关公共库
以下主要包含windows下公共库以及跨平台公共库: 1. google base库:google下chromium项目的跨平台公共库: 2. vc_common_src:即HP_SOCKET项目中的 ...
- Caffe+CUDA7.5+CuDNNv3+OpenCV3.0+Ubuntu14.04 配置参考文献 以及 常见编译问题总结
Caffe+CUDA7.5+CuDNNv3+OpenCV3.0+Ubuntu14.04 配置参考文献 ---- Wang Xiao Warning: Please make sure the cud ...
- web2.0最全的国外API应用集合
web2.0最全的国外API应用集合 原文地址:http://www.buguat.com/post/98.html 2.0时代,越来越多的API被大家广泛应用,如果你还不了解API是何物,请看这里的 ...
随机推荐
- STL的移动算法
要在自己定义类型中使用移动算法.须要在元素中提供移动赋值运算符.移动赋值运算符和std::move()详见<c++高级编程>第9章 class mystring { public: str ...
- jcenter那些事儿
jcenter是一个server托管在bintray.com的maven仓库. in project's build.gradle file allprojects { repositories { ...
- C#格式化成小数
datagridview某列格式化成两位小数 ............................................................................. ...
- 检索算法 -- 数据结构与算法的javascript描述 第13章
检索算法-如何在列表中查找特定的值. 顺序查找 从列表的第一个元素开始对列表元素逐个进行判断,直到找到了想要的结果,它属于暴力查找技巧的一种,在执行查找时可能会访问到数据结构里的所有元素. 代码: / ...
- javascript高级知识点——指定上下文实现
代码信息来自于http://ejohn.org/apps/learn/. 当我们将一个对象的点击事件绑定到一个事件触发元素时会发生什么? <ul id="results"&g ...
- iphone--有关日历中NSDateFormatter中英文
在使用日历使用中,获取星期的时候 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFo ...
- DOM缘起
DOM是现在按W3C标准的浏览器均实现的标准.HTML.CSS.DOM共同在结构.表现.交互上共同支撑起一个页面.当然,必须以用户为中心.平稳退化.逐渐增强.DOM的操作是通过JS来实现的.JS最初在 ...
- maven 引用自己的jar
<build> <plugins> <plugin> <groupId>org.apache.maven.pl ...
- 实现ModelDriver接口的功能
ModelDriver接口 来自com.opensymphony.xwork2.ModelDriven.是xwork-2.1.2-750.jar包的东西. 下面是源码: package com.ope ...
- (转)设置 UILabel 和 UITextField 的 Padding 或 Insets (理解UIEdgeInsets)
转自http://unmi.cc/uilable-uitextfield-padding-insets 主要是理解下UIEdgeInsets在IOS UI里的意义.靠,这货其实就是间隔,起个名字这么让 ...