@@ -33,15 +33,15 @@ buffer: MemoryMappedList(u8),
33
33
///
34
34
/// layout of the meta file (v0):
35
35
/// [0] [3]u8 file signature + u8 format version
36
- /// [1] u32 for xcmpchg (mutex in the stdlib is not FUTEX_SHARED)
36
+ /// [1] u64 for a lock
37
37
/// [2] u32 deleted bytes
38
38
/// [3] u32 number of strings
39
39
/// [4..] data (string end offsets)
40
40
meta : MemoryMappedList (u32 ),
41
41
42
42
const MetaHeader = packed struct {
43
43
signature_version : u32 ,
44
- lock : u32 ,
44
+ lock : std.Thread.Mutex ,
45
45
deleted_bytes : u32 ,
46
46
number_of_string : u32 ,
47
47
};
@@ -83,7 +83,7 @@ pub fn init(dir: std.fs.Dir, pc_digest: u64) InputPoolPosix {
83
83
if (meta .items .len == 0 ) {
84
84
const header : MetaHeader = .{
85
85
.signature_version = SignatureVersion ,
86
- .lock = Unlocked ,
86
+ .lock = std.Thread.Mutex {} ,
87
87
.deleted_bytes = 0 ,
88
88
.number_of_string = 0 ,
89
89
};
@@ -97,7 +97,6 @@ pub fn init(dir: std.fs.Dir, pc_digest: u64) InputPoolPosix {
97
97
} else {
98
98
const header = getHeader (meta );
99
99
assert (header .signature_version == SignatureVersion );
100
- assert (header .lock == Unlocked or header .lock == Locked );
101
100
}
102
101
103
102
return .{
@@ -111,31 +110,10 @@ pub fn deinit(ip: *InputPoolPosix) void {
111
110
ip .meta .deinit ();
112
111
}
113
112
114
- // Primitive spin lock implementation. There is basically no contention on it.
115
- const Locked : u32 = 1 ;
116
- const Unlocked : u32 = 0 ;
117
-
118
- fn lock (ip : * InputPoolPosix ) void {
119
- const lck : * volatile u32 = & getHeader (ip .meta ).lock ;
120
- while (true ) {
121
- const res = @cmpxchgWeak (u32 , lck , Unlocked , Locked , .acquire , .monotonic );
122
- if (res ) | v | {
123
- assert (v == Locked );
124
- } else {
125
- return ;
126
- }
127
- }
128
- }
129
-
130
- fn unlock (ip : * InputPoolPosix ) void {
131
- const lck : * volatile u32 = & getHeader (ip .meta ).lock ;
132
- const res = @atomicRmw (u32 , lck , .Xchg , Unlocked , .release );
133
- assert (res == Locked );
134
- }
135
-
136
113
pub fn insertString (ip : * InputPoolPosix , str : []const u8 ) void {
137
- ip .lock ();
138
- defer ip .unlock ();
114
+ const header = getHeader (ip .meta );
115
+ header .lock .lock ();
116
+ defer header .lock .unlock ();
139
117
140
118
assert (ip .buffer .items .len + str .len < std .math .maxInt (Index ));
141
119
0 commit comments