diff options
Diffstat (limited to 'core/shared_queue.js')
-rw-r--r-- | core/shared_queue.js | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/core/shared_queue.js b/core/shared_queue.js index 093cc223f..742a90995 100644 --- a/core/shared_queue.js +++ b/core/shared_queue.js @@ -115,7 +115,8 @@ SharedQueue Binary Layout if (index == 0) { return HEAD_INIT; } else { - return shared32[INDEX_OFFSETS + 2 * (index - 1)]; + const prevEnd = shared32[INDEX_OFFSETS + 2 * (index - 1)]; + return (prevEnd + 3) & ~3; } } else { return null; @@ -125,16 +126,18 @@ SharedQueue Binary Layout function push(opId, buf) { const off = head(); const end = off + buf.byteLength; + const alignedEnd = (end + 3) & ~3; const index = numRecords(); - if (end > shared32.byteLength || index >= MAX_RECORDS) { + if (alignedEnd > shared32.byteLength || index >= MAX_RECORDS) { // console.log("shared_queue.js push fail"); return false; } setMeta(index, end, opId); + assert(alignedEnd % 4 === 0); assert(end - off == buf.byteLength); sharedBytes.set(buf, off); shared32[INDEX_NUM_RECORDS] += 1; - shared32[INDEX_HEAD] = end; + shared32[INDEX_HEAD] = alignedEnd; return true; } |