diff options
author | Nikolaos S. Papaspyrou <[email protected]> | 2012-06-08 22:21:02 +0300 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2015-11-16 14:36:19 +0100 |
commit | dad527f55b51d60e75a0d19aa0f4f42c1065777f (patch) | |
tree | 931b7f865a37a68412f236755008efdafaff3b07 /erts/emulator/beam/utils.c | |
parent | 9bdd69a560765931cdd5dac50c8c8389263a2f6b (diff) | |
download | otp-dad527f55b51d60e75a0d19aa0f4f42c1065777f.tar.gz otp-dad527f55b51d60e75a0d19aa0f4f42c1065777f.tar.bz2 otp-dad527f55b51d60e75a0d19aa0f4f42c1065777f.zip |
An implementation of lightweight unbounded queues
Diffstat (limited to 'erts/emulator/beam/utils.c')
-rw-r--r-- | erts/emulator/beam/utils.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/erts/emulator/beam/utils.c b/erts/emulator/beam/utils.c index c3735683bb..184477c36b 100644 --- a/erts/emulator/beam/utils.c +++ b/erts/emulator/beam/utils.c @@ -258,6 +258,31 @@ erl_grow_pstack(ErtsPStack* s, void* default_pstack, unsigned need_bytes) s->psp = s->pstart + sp_offs; } +/* + * Helper function for the EQUEUE macros defined in global.h. + */ + +void +erl_grow_equeue(ErtsEQueue* q, Eterm* default_equeue) +{ + Uint old_size = (q->end - q->start); + Uint new_size = old_size * 2; + Uint first_part = (q->end - q->front); + Uint second_part = (q->back - q->start); + Eterm* new_ptr = erts_alloc(q->alloc_type, new_size*sizeof(Eterm)); + ASSERT(q->back == q->front); // of course the queue is full now! + if (first_part > 0) + sys_memcpy(new_ptr, q->front, first_part*sizeof(Eterm)); + if (second_part > 0) + sys_memcpy(new_ptr+first_part, q->start, second_part*sizeof(Eterm)); + if (q->start != default_equeue) + erts_free(q->alloc_type, q->start); + q->start = new_ptr; + q->end = q->start + new_size; + q->front = q->start; + q->back = q->start + old_size; +} + /* CTYPE macros */ #define LATIN1 |