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是何物,请看这里的 ...
随机推荐
- javascript的模块开发方法;
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 用python处理文本数据 学到的一些东西
最近写了一个python脚本,用TagMe的api标注文本,并解析返回的json数据.在这个过程中遇到了很多问题,学到了一些新东西,总结一下. 1. csv文件处理 csv是一种格式化的文件,由行和列 ...
- php中有用插件集合
1. NuSOAP NuSOAP提供一组PHP类用于帮助开发者创建和调用基于SOAP1.1.WSDL1.1与HTTP1.0/1.1的Web Services, 可以跨平台.跨语言的请求服务.
- sdut 3-5 学生成绩统计
3-5 学生成绩统计 Time Limit: 1000MS Memory limit: 65536K 题目描写叙述 通过本题目练习能够掌握对象数组的使用方法,主要是对象数组中数据的输入输出操作. 设计 ...
- alimama open source mdrill启动后访问蓝鲸任务时出错:Caused by:org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss
启动后,访问:http://IP:1107/mdrill.jsp 蓝鲸任务
- JavaScript习题
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- 20151120 jsp相关
jsp 声明表示.代码片段及引用 <%@ page language="java" contentType="text/html; charset=UTF-8&qu ...
- javascript 学习笔记(权威指南)
1.数组的sort()方法默认是按照字母排序的,下面举个栗子说明: 1)全是字母: var arr =["zu","fan","an",&q ...
- 写一个jq插件
本文章摘自博客园的http://www.cnblogs.com/JustinYoung/archive/2010/03/30/jquery-chajian.html,写此文章只是方便自己记载技术 一个 ...
- 利用JSP编程技术实现一个简单的购物车程序
实验二 JSP编程 一.实验目的1. 掌握JSP指令的使用方法:2. 掌握JSP动作的使用方法:3. 掌握JSP内置对象的使用方法:4. 掌握JavaBean的编程技术及使用方法:5. 掌握JSP ...