diff options
author | Kim Alvefur <zash@zash.se> | 2015-06-25 18:57:43 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2015-06-25 18:57:43 +0200 |
commit | 6e187489a98a403ae236a9595fbd0f80d3ff6490 (patch) | |
tree | 1b0aa90c356c8219e4165bd4d5136ea99b34e8f1 /util/queue.lua | |
parent | 7b1c9ac2f7a58d8d91124196fec60206facc840e (diff) | |
parent | 7b391bc37acca3a5ed62477f18c9e03348a057f5 (diff) | |
download | prosody-6e187489a98a403ae236a9595fbd0f80d3ff6490.tar.gz prosody-6e187489a98a403ae236a9595fbd0f80d3ff6490.zip |
Merge 0.10->trunk
Diffstat (limited to 'util/queue.lua')
-rw-r--r-- | util/queue.lua | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/util/queue.lua b/util/queue.lua index afdcaf45..203da0e3 100644 --- a/util/queue.lua +++ b/util/queue.lua @@ -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 @@ local function new(size) 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; |