chromium之ThreadLocalStorage
看看头文件怎么用
// Wrapper for thread local storage. This class doesn't do much except provide
// an API for portability.
class ThreadLocalStorage {
public: // Prototype for the TLS destructor function, which can be optionally used to
// cleanup thread local storage on thread exit. 'value' is the data that is
// stored in thread local storage.
typedef void (*TLSDestructorFunc)(void* value); // A key representing one value stored in TLS.
class Slot {
public:
Slot(TLSDestructorFunc destructor = NULL); // This constructor should be used for statics.
// It returns an uninitialized Slot.
explicit Slot(base::LinkerInitialized x) {} // Set up the TLS slot. Called by the constructor.
// 'destructor' is a pointer to a function to perform per-thread cleanup of
// this object. If set to NULL, no cleanup is done for this TLS slot.
// Returns false on error.
bool Initialize(TLSDestructorFunc destructor); // Free a previously allocated TLS 'slot'.
// If a destructor was set for this slot, removes
// the destructor so that remaining threads exiting
// will not free data.
void Free(); // Get the thread-local value stored in slot 'slot'.
// Values are guaranteed to initially be zero.
void* Get() const; // Set the thread-local value stored in slot 'slot' to
// value 'value'.
void Set(void* value); bool initialized() const { return initialized_; } private:
// The internals of this struct should be considered private.
bool initialized_;
#if defined(OS_WIN)
int slot_;
#elif defined(OS_POSIX)
pthread_key_t key_;
#endif DISALLOW_COPY_AND_ASSIGN(Slot);
}; #if defined(OS_WIN)
// Function called when on thread exit to call TLS
// destructor functions. This function is used internally.
static void ThreadExit();
ThreadLocalStorage::Slot slot = new ThreadLocalStorage::Slot(..)
slot->Initialize
slot->Set slot->Get 有个测试用例,蛮看一看
TEST(ThreadLocalStorageTest, Basics) {
ThreadLocalStorage::Slot slot;
slot.Set(reinterpret_cast<void*>());
int value = reinterpret_cast<intptr_t>(slot.Get());
EXPECT_EQ(value, );
}
chromium之ThreadLocalStorage的更多相关文章
- chromium之tracked_objects
// For each thread, we have a ThreadData that stores all tracking info generated // on this thread. ...
- QT5利用chromium内核与HTML页面交互
在QT5.4之前,做QT开发浏览器只能选择QWebkit,但是有过使用的都会发现,这个webkit不是出奇的慢,简直是慢的令人发指,Release模式下还行,debug下你就无语了,但是webkit毕 ...
- Google之Chromium浏览器源码学习——base公共通用库(一)
Google的优秀C++开源项目繁多,其中的Chromium浏览器项目可以说是很具有代表性的,此外还包括其第三开发开源库或是自己的优秀开源库,可以根据需要抽取自己感兴趣的部分.在研究.学习该项目前的时 ...
- 如何在windows上编译Chromium (CEF3) 并加入MP3支持(二)
时隔一年,再次编译cef3,独一无二的目的仍为加入mp3支持.新版本的编译环境和注意事项都已经发生了变化,于是再记录一下. 一.编译版本 cef版本号格式为X.YYYY.A.gHHHHHHH X为主版 ...
- 如何在Windows上从源码编译Chromium (CEF3) 加入mp3支持
一.什么是CEF CEF即Chromium Embeded Framework,由谷歌的开源浏览器项目Chromium扩展而来,可方便地嵌入其它程序中以得到浏览器功能. CEF包括CEF1和CEF3两 ...
- 构建基于Chromium的应用程序
chromium是google chrome浏览器所采用的内核,最开始由苹果的webkit发展而出,由于webkit在发展上存在分歧,而google希望在开发上有更大的自由度,2013年google决 ...
- ubuntu中chromium无法播放flash,安装flash
ubuntu14.0.4中系统自带的chromium无法播放flash,后来查了下,得知chromium已经不支持adobe flash了,用户可使用pepper flash替代.安装pepper f ...
- windows下编译chromium浏览器的15个流程整理
编译chromium 系统为windows, 国内在windows上编译chromium的资料比较少, 我这篇文章只能作为参考, 记录我遇到的一些问题,因为chromium团队也会修改了代码,或者编译 ...
- Google之Chromium浏览器源码学习——base公共通用库(二)
上次提到Chromium浏览器中base公共通用库中的内存分配器allocator,其中用到了三方库tcmalloc.jemalloc:对于这两个内存分配器,个人建议,对于内存,最好是自己维护内存池: ...
随机推荐
- Spring课程 Spring入门篇 4-4 Spring bean装配(下)之Autowired注解说明3 多选一 qualifier
本节主要讲述以下内容: 1 简述 2 代码演练 2.1 注解qualifier运用 1 简述 1.1 何种情况使用qualifier注解? a 按类型自动装配多个bean实例,可以用@qualifie ...
- 对象大小对比之Comparable与Comparator
一 概述 1.Comparable与Comparator使用背景 数值型数据(byte int short long float double)天生可对比大小,可排序,String实现了Compara ...
- 【Linux】Linux入门及常见基本操作命令详解
本文基于 Red Hat Enterprise Linux 6 一.Linux 入门体验 1.1 root用户登陆 1.2 图形化与纯字符模式切换 init 5 - 图形模式 init 3 - 纯字符 ...
- java:反射机制
Java反射机制及IoC原理:https://www.cnblogs.com/Eason-S/p/5851078.html Java中反射机制详解:https://www.cnblogs.com/wh ...
- 【java开发系列】—— 深克隆和浅克隆
Java支持我们对一个对象进行克隆,通常用在装饰模式和原型模式中.那么什么是深克隆,什么是浅克隆呢. [浅克隆],通常只是对克隆的实例进行复制,但里面的其他子对象,都是共用的. [深克隆],克隆的时候 ...
- python实现oracle数据泵导出功能
脚本如下:[oracle@ycr python]$ more dump.py #/usr/bin/python#coding:utf8 import sysimport osimport time n ...
- March 3 2017 Week 9 Friday
Each time you love, love as deeply as if it were forever. 如果爱,请深爱,就像能到地老天荒. If we can only encounter ...
- March 27 2017 Week 13 Monday
A book that remains shut is but a block. 有书闭卷不阅读,无异于一块木头. I had planned to buy a book and read it ev ...
- c++利用互斥锁实现读写锁
很简单就是在读的时候把写的锁锁住就好了 class readwrite_lock { public: readwrite_lock() : read_cnt(0) { } void readLock( ...
- BZOJ3262:陌上花开(CDQ分治)
Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),用三个整数表示. 现在要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量. 定义一朵花A比另一朵花B要美 ...