Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARC 的 retainCount 怎么存储的? #10

Open
tbfungeek opened this issue Jan 5, 2020 · 0 comments
Open

ARC 的 retainCount 怎么存储的? #10

tbfungeek opened this issue Jan 5, 2020 · 0 comments

Comments

@tbfungeek
Copy link
Owner

tbfungeek commented Jan 5, 2020

这个分两种情况,一种是存储在NONPOINTER_ISA 中的extra_rc中,如果引用计数超过了extra_rc所能存储的值,就会将引用计数值存储在SideTables中,一般我们的设备中SideTables是由8张或者64张SideTable 构成,每个SideTable单独加锁,这种使用分离锁的方式可以避免在操作一个SideTable的时候,不允许操作其他的对象。从而加快了处理速度。每个SideTable有三个部分组成,slock是自旋锁,在对该SideTable操作之前会将锁锁上,refcnts是一个哈希表,就是用于存储retainCount的值。它使用对象的地址进行散列获得对应的hash值来寻找该对象的retainCount。weak_table 是用来存储弱引用信息的哈希表。具体的结构如下所示:

struct SideTable {
    // 使用自旋锁来防止操作表结构时可能的竞态条件。
    spinlock_t slock;
    // 引用计数的 hash 表
    RefcountMap refcnts;
    // weak 引用全局 hash 表
    weak_table_t weak_table;
};

Artboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant