forked from Dicklesworthstone/asupersync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.py
More file actions
26 lines (22 loc) · 862 Bytes
/
Copy pathpatch.py
File metadata and controls
26 lines (22 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import re
import sys
with open('src/sync/rwlock.rs', 'r') as f:
content = f.read()
# Replace vec push_back with slab push_back_tagged
content = re.sub(
r'state\.reader_waiters\.push_back\(Waiter \{\s*waker: context\.waker\(\)\.clone\(\),\s*id,\s*\}\);',
r'let slab_index = state.reader_waiters.push_back_tagged(context.waker().clone(), id);',
content
)
# And waiter_id = Some(id) -> Some(slab_index)
content = re.sub(
r'let id = state\.next_waiter_id;[\s\S]*?this\.waiter_id = Some\(id\);',
r'''let id = state.next_waiter_id;
state.next_waiter_id = state.next_waiter_id.wrapping_add(1);
let slab_index = state.reader_waiters.push_back_tagged(context.waker().clone(), id);
drop(state);
this.waiter_id = Some(slab_index);''',
content
)
with open('src/sync/rwlock.rs', 'w') as f:
f.write(content)