Skip to content

Commit 22c0925

Browse files
committed
Fix enqueue for sure
1 parent 09ce9a4 commit 22c0925

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,13 @@ Example:
226226
.value = 1,
227227
};
228228
229-
try mbox.send(&msg.node);
229+
_ = try mbox.send(&msg.node);
230230
231231
const node: *Node = try mbox.receive(1000);
232232
const rcvdMsg: *Msg = @fieldParentPtr("node", node);
233233
var shouldBeOne: usize = rcvdMsg.*.value;
234234
```
235+
_TypeErasedMailbox_ has exactly the same functionality as former _MailBox_.
235236

236237
## Eat your own dog food
237238

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.name = .mailbox,
44
.version = "0.0.13",
55

6-
.fingerprint = 0xa69fe20b9bc5eb6b,
6+
.fingerprint = 0xa69fe20bd24b00f0,
77

88
.minimum_zig_version = "0.15.2",
99

src/mailbox.zig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ pub fn MailBox(comptime Letter: type) type {
139139
new_Envelope.prev = null;
140140
new_Envelope.next = null;
141141

142+
if (fifo.len == 0) {
143+
std.debug.assert(fifo.first == null);
144+
std.debug.assert(fifo.last == null);
145+
fifo.first = new_Envelope;
146+
}
147+
142148
if (fifo.last) |last| {
143149
last.next = new_Envelope;
144150
new_Envelope.prev = last;
@@ -312,6 +318,12 @@ pub fn MailBoxIntrusive(comptime Envelope: type) type {
312318
new_Envelope.prev = null;
313319
new_Envelope.next = null;
314320

321+
if (fifo.len == 0) {
322+
std.debug.assert(fifo.first == null);
323+
std.debug.assert(fifo.last == null);
324+
fifo.first = new_Envelope;
325+
}
326+
315327
if (fifo.last) |last| {
316328
last.next = new_Envelope;
317329
new_Envelope.prev = last;

0 commit comments

Comments
 (0)