为了兼容不同的平台,这个类采用了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的更多相关文章

  1. colmap编译过程中出现,无法解析的外部符号错误 “__cdecl google::base::CheckOpMessageBuilder::ForVar1(void)”

    错误提示: >colmap.lib(matching.obj) : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: cl ...

  2. google base库之simplethread

    // This is the base SimpleThread. You can derive from it and implement the // virtual Run method, or ...

  3. google base 之MessagePumpForUI

    base库中比较有意思就是这个类了,如同很多界面库一样,创建了一个隐藏窗口来处理需要在界面线程处理的消息,大体原理也就是需要执行task的时候发送一个自定义的消息,当窗口接收到task的时候调用保存起 ...

  4. google base之IncomingTaskQueue

    如同名称描述的那样,这个类就是个taskqueue,也就是任务队列,添加任务到队列,然后由MessageLoop去执行task,比较关心的函数如下: bool IncomingTaskQueue::A ...

  5. google base库中的WaitableEvent

    这个类说白了就是对windows event的封装,没有什么特别的,常规做法,等侍另一线程无非就是等侍事件置信waitsingleobject,通知事件无非就是setevent,一看就明白,不就详解, ...

  6. 谷歌 google

    google Google是搜索引擎名,也是一家美国上市公司名称.Google公司于1998年9月7日以私有股份公司的形式创立,以设计并管理一个互联网的搜索引擎.Google公司的总部称作“Googl ...

  7. Windows平台下和跨平台的相关公共库

    以下主要包含windows下公共库以及跨平台公共库: 1. google base库:google下chromium项目的跨平台公共库: 2. vc_common_src:即HP_SOCKET项目中的 ...

  8. Caffe+CUDA7.5+CuDNNv3+OpenCV3.0+Ubuntu14.04 配置参考文献 以及 常见编译问题总结

    Caffe+CUDA7.5+CuDNNv3+OpenCV3.0+Ubuntu14.04  配置参考文献 ---- Wang Xiao Warning: Please make sure the cud ...

  9. web2.0最全的国外API应用集合

    web2.0最全的国外API应用集合 原文地址:http://www.buguat.com/post/98.html 2.0时代,越来越多的API被大家广泛应用,如果你还不了解API是何物,请看这里的 ...

随机推荐

  1. deferred initcalls与模块化

    deferred initcalls与模块化 有两个技术可以加快kernel的启动速度: 1.deferred initcalls 2.模块化 它们的思想类似,都是将非必要的模块初始化推迟到内核启动之 ...

  2. JavaScript字符串插入、删除、替换函数

    JavaScript字符串插入.删除.替换函数 说明: 以下函数中前两个函数取出查找字符串的前一部分和后一部分,以用于其他函数.注意,调用一次 replaceString(mainStr,search ...

  3. SQL Server表和字段说明的增加和更新

    1. 增加字段说明 EXEC sp_addextendedproperty     'MS_Description',     'some description',     'user',      ...

  4. Linux下包含头文件的路径问题与动态库链接路径问题

    C/C++程序在linux下被编译和连接时,GCC/G++会查找系统默认的include和link的路径,以及自己在编译命令中指定的路径.自己指定的路径就不说了,这里说明一下系统自动搜索的路径. [1 ...

  5. Java中Overload和Override的区别

    由于项目正式收工,闲来无事突然发现以前的文档上有一个问题介绍的不是很详细 override(重写,覆盖) ​​ 1.方法名.参数.返回值相同. ​2.子类方法不能缩小父类方法的访问权限. 3.子类方法 ...

  6. vvv

    すぎやま(杉山) ハイコンテンツコンテスト assortedアクセント・音節as・sórt・ed 発音記号/‐ṭɪd/音声を聞く [形容詞]1分類した,仕分けした.2〈ビスケットなど〉詰め合わせの.用 ...

  7. hibernate中多对多关联

    hibernate中多对多关联 “计应134(实验班) 凌豪” 在关系数据库中有一种常见的关系即多对多关系,例如课程和学生的关系,一个学生可以选择多门课程,同时一门课程也可以被多个学生选择, 因此课程 ...

  8. try.jquery-5-styling里的各种css样式操作

    你好,这里是我的http://try.jquery.com/学习笔记: 这次来学习操作各种css. 主要对这段html元素进行操作. <div id="all-tours"& ...

  9. 3000本IT书籍下载地址

    http://www.shouce.ren/post/d/id/112300    黑客攻防实战入门与提高.pdfhttp://www.shouce.ren/post/d/id/112299    黑 ...

  10. 导出excel java实现

    1.前台页面代码: <tr> <td><input dataId="excel" type="button" value=&quo ...