主要用到TLS,首次进入gHaveTLS为false,锁保护说明此函数很多其他函数在调用。
通过if (pthread_key_create(&gTLS, threadDestructor) != 0),中threadDestructor(void *st)
调用IPCThreadState::IPCThreadState()创建IPCThreadState对象,并将对象的索引设置为gTLS。再次进入后通过gTLS获取到IPCThreadState对象。
 IPCThreadState* IPCThreadState::self()
{
if (gHaveTLS) {
restart:
const pthread_key_t k = gTLS;
IPCThreadState* st = (IPCThreadState*)pthread_getspecific(k);
if (st) return st;
return new IPCThreadState;
} if (gShutdown) return NULL; pthread_mutex_lock(&gTLSMutex);
if (!gHaveTLS) {
if (pthread_key_create(&gTLS, threadDestructor) != ) {
pthread_mutex_unlock(&gTLSMutex);
return NULL;
}
gHaveTLS = true;
}
pthread_mutex_unlock(&gTLSMutex);
goto restart;
}

通pthread_setspecific(gTLS, this);gTLS与IPCThreadState对象关联了。

 IPCThreadState::IPCThreadState()
: mProcess(ProcessState::self()),
mMyThreadId(androidGetTid()),
mStrictModePolicy(),
mLastTransactionBinderFlags()
{
pthread_setspecific(gTLS, this);
clearCaller();
mIn.setDataCapacity();
mOut.setDataCapacity();
}

IPC thread写法太晦涩的更多相关文章

  1. Thread.Sleep太久,界面卡死

    在Winform程序的UI界面使用Thread.Sleep,窗体界面会被卡死,如图1所示,程序sleep 5000毫秒,时间到了之后,按钮的名称才更改过来,窗体也能被鼠标拖动.而用Delay方法,就能 ...

  2. (转)Ext.Button点击事件的三种写法

    转自:http://maidini.blog.163.com/blog/static/377627042008111061844345/ ExtJs的写法太灵活了,现在收集了关于Button点击事件的 ...

  3. IPC的使用

    IPC,Inter-Processor Communication是SYS/BIOS处理核间通信的组件: IPC的几种应用方式: 1.最小使用(Minimal use) 这种情况是通过核间的通知机制( ...

  4. 不是广告--如何学Java,我说点不太一样的学习方式

    首先声明,这篇文章不是卖课程.介绍培训班的广告. 最近有不少读者通过微信问我:小白应该怎么学好 Java? 提问的人里有在校大学生.有刚参加工作的.有想转行做程序员的,还有一部分是最近找工作不顺的. ...

  5. Android深入浅出之Binder机制

    一说明 Android系统最常见也是初学者最难搞明白的就是Binder了,很多很多的Service就是通过Binder机制来和客户端通讯交互的.所以搞明白Binder的话,在很大程度上就能理解程序运行 ...

  6. Android深入浅出之Binder机制(转)

    Android深入浅出之Binder机制 一 说明 Android系统最常见也是初学者最难搞明白的就是Binder了,很多很多的Service就是通过Binder机制来和客户端通讯交互的.所以搞明白B ...

  7. ZT-Android深入浅出之Binder机 制

    转贴 不是原创! Android深入浅出之Binder机 制 一说明 Android系统最常见也是初学者最难搞明白的就是Binder了,很多很多的Service就是通过Binder机制来和客户端通讯交 ...

  8. RunLoop 总结:RunLoop的应用场景(一)

    参考资料 好的书籍都是值得反复看的,那好的文章,好的资料也值得我们反复看.我们在不同的阶段来相同的文章或资料或书籍都能有不同的收获,那它就是好文章,好书籍,好资料.关于iOS 中的RunLoop资料非 ...

  9. Google C++ Style Guide

    Background C++ is one of the main development languages used by many of Google's open-source project ...

随机推荐

  1. 牛客寒假算法基础集训营1B题

    链接:https://ac.nowcoder.com/acm/contest/317/B 来源:牛客网 题目描述 小a非常喜欢204204这个数字,因为′a′+′k′=204′a′+′k′=204. ...

  2. Angular(三)

    Angular开发者指南(三)数据绑定   数据绑定AngularJS应用程序中的数据绑定是模型和视图组件之间的数据的自动同步. AngularJS实现数据绑定的方式可以将模型视为应用程序中的单一来源 ...

  3. dubbo的重试原则

    验证思路.使用超时来验证重试次数 XML 注解

  4. html title属性内容换行方法(静态页面)

    鼠标经过悬停于对象时提示内容(title属性内容)换行排版方法,html title 换行方法总结. html的title属性默认是显示一行的,这里介绍两种换行方法为大家分享使用. 一.直接title ...

  5. CodeForces 990B Micro-World(思维、STL)

    http://codeforces.com/problemset/problem/990/B 题意: 有n个细菌,每个细菌的尺寸为ai,现在有以常数k,如果细菌i的尺寸ai大于细菌j的尺寸aj,并且a ...

  6. Scipy优化算法--scipy.optimize.fmin_tnc()/minimize()

    scipy中的optimize子包中提供了常用的最优化算法函数实现,我们可以直接调用这些函数完成我们的优化问题. scipy.optimize包提供了几种常用的优化算法. 该模块包含以下几个方面 使用 ...

  7. $.proxy和$.extend

    $.proxy用法详解 参考:https://www.cnblogs.com/alice626/p/6004864.html jQuery中的$.proxy官方描述为: 描述:接受一个函数,然后返回一 ...

  8. nginx+tomcat配置集群

    安装nginx以及两个以上tomcat,并启动 配置集群nginx/conf/nginx.conf文件 说明:server_list为名字,可以在每台服务器ip后面添加weight number,设置 ...

  9. UIView 的Transform属性以及 CGAffineTransform的使用

    什么是Transform? Transform是一个3×3的矩阵,如下图所示: 通过这个矩阵我们可以对一个坐标系统进行缩放,平移,旋转以及这两者的任意组着操作.而且矩阵的操作不具备交换律,即矩阵的操作 ...

  10. BOM(Broswer Object Model)

    BOM(Broswer Object Model) 方法:    框窗     1.警告框    window.alert("msg");     2.确认框     window ...