Introducing global context.

Currently the static variables of the allocator are moved into a
global structure.

The future plan is supporting multiple context models with different
advantages and disadvantages. Users can select the most appropriate
context model for their own use case. This context model must be
selected at compile time using compiler defines.

Currently only one model is implemented, which will be the default
context model: the context is stored in global variables, so only
a single context is available which always exists.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2016-07-19 05:10:12 -07:00
parent ca39875690
commit 3a78d30897
7 changed files with 361 additions and 238 deletions
+8 -13
View File
@@ -18,20 +18,15 @@
* Allocator implementation
*/
#include "jrt.h"
#include "jrt-libc-includes.h"
#include "jcontext.h"
#include "jmem-allocator.h"
#include "jmem-heap.h"
#include "jmem-poolman.h"
#include "jrt-libc-includes.h"
#define JMEM_ALLOCATOR_INTERNAL
#include "jmem-allocator-internal.h"
/**
* The 'try to give memory back' callback
*/
static jmem_free_unused_memory_callback_t jmem_free_unused_memory_callback = NULL;
/**
* Initialize memory allocators.
*/
@@ -94,9 +89,9 @@ void
jmem_register_free_unused_memory_callback (jmem_free_unused_memory_callback_t callback) /**< callback routine */
{
/* Currently only one callback is supported */
JERRY_ASSERT (jmem_free_unused_memory_callback == NULL);
JERRY_ASSERT (JERRY_CONTEXT (jmem_free_unused_memory_callback) == NULL);
jmem_free_unused_memory_callback = callback;
JERRY_CONTEXT (jmem_free_unused_memory_callback) = callback;
} /* jmem_register_free_unused_memory_callback */
/**
@@ -106,9 +101,9 @@ void
jmem_unregister_free_unused_memory_callback (jmem_free_unused_memory_callback_t callback) /**< callback routine */
{
/* Currently only one callback is supported */
JERRY_ASSERT (jmem_free_unused_memory_callback == callback);
JERRY_ASSERT (JERRY_CONTEXT (jmem_free_unused_memory_callback) == callback);
jmem_free_unused_memory_callback = NULL;
JERRY_CONTEXT (jmem_free_unused_memory_callback) = NULL;
} /* jmem_unregister_free_unused_memory_callback */
/**
@@ -117,9 +112,9 @@ jmem_unregister_free_unused_memory_callback (jmem_free_unused_memory_callback_t
void
jmem_run_free_unused_memory_callbacks (jmem_free_unused_memory_severity_t severity) /**< severity of the request */
{
if (jmem_free_unused_memory_callback != NULL)
if (JERRY_CONTEXT (jmem_free_unused_memory_callback) != NULL)
{
jmem_free_unused_memory_callback (severity);
JERRY_CONTEXT (jmem_free_unused_memory_callback) (severity);
}
jmem_pools_collect_empty ();