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数组去重算法-----3
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Math.round(11.5)等于()Math.round(-11.5)等于()
几天前去面试,这道简单的题目居然做错了,看来基础就是慢慢积累的.并不断使用和复习才会成为高手,假设基础不是那么熟练.恐怕在成为高手的路上会困难重重.所以在做项目的间歇时间.偶尔回顾一下最基础的知识.是 ...
- c++中参数传递和函数返回简析
1.参数传递: 每次调用函数时,都会重新创建该函数所有的形参,此时所传递的实参将会初始化对应的形参.形参的初始化与变量的初始化一样. 非引用类型:如果形参具有非引用类型,则复制实参的值.普通的非引用类 ...
- Oracle视图,序列及同义词、集合操作
一.视图(重点) 视同的功能:一个视图其实就是封装了一个复杂的查询语句.1.创建视图的语法:CREATE VIEW 视图名称 AS 子查询 范例:创建一个包含了20部门的视图CREATE VIEW e ...
- 20151226--easyUI
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- Struts2中ModelDriven的使用
它是Struts2种独有的一种接收用户输入的机制,想在项目中使用模型驱动 (ModelDriven)需要让Action实现com.opensymphony.xwork2.ModelDriven 接口, ...
- select * from (select P.*,ROWNUM RN FROM(select * from Mp_Relatedart where pubbaseid=785 order by ID ASC )P)M WHERE M.RN>2 and M.RN <= 7
select * from (select P.*,ROWNUM RN FROM(select * from Mp_Relatedart where pubbaseid=785 order by ID ...
- jQuery 源码分析和使用心得 - core.js
core是jQuery的核心内容, 包含了最基础的方法, 比如我们常用的 $(selector, context), 用于遍历操作的 each, map, eq, first 识别变量类型的 isAr ...
- Flink资料(1)-- Flink基础概念(Basic Concept)
Flink基础概念 本文描述Flink的基础概念,翻译自https://ci.apache.org/projects/flink/flink-docs-release-1.0/concepts/con ...
- C#学习日志 day8 -------------- async await 异步方法入门(引用博客)以及序列化和反序列化的XML及json实现
首先是异步方法的介绍,这里引用自http://www.cnblogs.com/LoveJenny/archive/2011/11/01/2230933.html async and await 简单的 ...