Software /
code /
prosody
Diff
util/queue.lua @ 6745:6728ad041761
Merge 0.10->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 25 Jun 2015 18:57:43 +0200 |
parent | 6731:d4a6c9ee4bc5 |
child | 6911:56c9bc4ba247 |
line wrap: on
line diff
--- a/util/queue.lua Thu May 21 22:56:39 2015 +0200 +++ b/util/queue.lua Thu Jun 25 18:57:43 2015 +0200 @@ -11,7 +11,7 @@ local have_utable, utable = pcall(require, "util.table"); -- For pre-allocation of table -local function new(size) +local function new(size, allow_wrapping) -- Head is next insert, tail is next read local head, tail = 1, 1; local items = 0; -- Number of stored items @@ -22,7 +22,12 @@ count = function (self) return items; end; push = function (self, item) if items >= size then - return nil, "queue full"; + if allow_wrapping then + tail = (tail%size)+1; -- Advance to next oldest item + items = items - 1; + else + return nil, "queue full"; + end end t[head] = item; items = items + 1;