aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/utils.c
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2015-01-26 17:58:30 +0100
committerBjörn-Egil Dahlberg <[email protected]>2015-03-12 18:56:42 +0100
commitb530d8b95055c27c737140c5ec2047919d02aeed (patch)
treecd48528245c04d88f6e8e41a2c8c383754ff65a6 /erts/emulator/beam/utils.c
parentb38518ff23477322da221212f29d5ad0d1fb96fa (diff)
downloadotp-b530d8b95055c27c737140c5ec2047919d02aeed.tar.gz
otp-b530d8b95055c27c737140c5ec2047919d02aeed.tar.bz2
otp-b530d8b95055c27c737140c5ec2047919d02aeed.zip
erts: Add PSTACK
A lightweight stack that can be used to store any type. PUSH and POP return pointers into stack slots.
Diffstat (limited to 'erts/emulator/beam/utils.c')
-rw-r--r--erts/emulator/beam/utils.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/erts/emulator/beam/utils.c b/erts/emulator/beam/utils.c
index bd90ec2fba..a54a93b086 100644
--- a/erts/emulator/beam/utils.c
+++ b/erts/emulator/beam/utils.c
@@ -239,6 +239,32 @@ erl_grow_wstack(ErtsWStack* s, UWord* default_wstack, Uint need)
s->wsp = s->wstart + sp_offs;
}
+/*
+ * Helper function for the PSTACK macros defined in global.h.
+ */
+void
+erl_grow_pstack(ErtsPStack* s, void* default_pstack, unsigned need_bytes)
+{
+ Uint old_size = s->pend - s->pstart;
+ Uint new_size;
+ Uint sp_offs = s->psp - s->pstart;
+
+ if (need_bytes < old_size)
+ new_size = 2 * old_size;
+ else
+ new_size = ((need_bytes / old_size) + 2) * old_size;
+
+ if (s->pstart != default_pstack) {
+ s->pstart = erts_realloc(s->alloc_type, s->pstart, new_size);
+ } else {
+ byte* new_ptr = erts_alloc(s->alloc_type, new_size);
+ sys_memcpy(new_ptr, s->pstart, old_size);
+ s->pstart = new_ptr;
+ }
+ s->pend = s->pstart + new_size;
+ s->psp = s->pstart + sp_offs;
+}
+
/* CTYPE macros */
#define LATIN1