1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-25 22:53:16 +00:00

Make global state thread local. This means multiple threads

of dst can run, but cannot yet share state.
This commit is contained in:
Calvin Rose 2018-03-30 16:12:30 -04:00
parent 9dabc6bee3
commit 507f9f9c57
6 changed files with 36 additions and 28 deletions

View File

@ -1,9 +1,9 @@
# Dst Bytecode Interpreter
# Dst Bytecode Reference
### Dst alpha 0.0.0
This document outlines the Dst bytecode format, and core ideas in the runtime.
the are closely related to the bytecode. It should enable the reader
This document outlines the Dst bytecode format, and core ideas in the runtime
that are closely related to the bytecode. It should enable the reader
to write dst assembly code and hopefully understand the dst internals better.
It will also talk about the C abstractions used to implement some of these ideas.
Some experience with basic computer organization is helpful for understanding

View File

@ -25,15 +25,15 @@
#include "gc.h"
/* GC State */
void *dst_vm_blocks;
uint32_t dst_vm_gc_interval;
uint32_t dst_vm_next_collection;
int dst_vm_gc_suspend = 0;
DST_THREAD_LOCAL void *dst_vm_blocks;
DST_THREAD_LOCAL uint32_t dst_vm_gc_interval;
DST_THREAD_LOCAL uint32_t dst_vm_next_collection;
DST_THREAD_LOCAL int dst_vm_gc_suspend = 0;
/* Roots */
Dst *dst_vm_roots;
uint32_t dst_vm_root_count;
uint32_t dst_vm_root_capacity;
DST_THREAD_LOCAL Dst *dst_vm_roots;
DST_THREAD_LOCAL uint32_t dst_vm_root_count;
DST_THREAD_LOCAL uint32_t dst_vm_root_capacity;
/* Helpers for marking the various gc types */
static void dst_mark_funcenv(DstFuncEnv *env);

View File

@ -30,10 +30,10 @@
#include "util.h"
/* Cache state */
const uint8_t **dst_vm_cache = NULL;
uint32_t dst_vm_cache_capacity = 0;
uint32_t dst_vm_cache_count = 0;
uint32_t dst_vm_cache_deleted = 0;
DST_THREAD_LOCAL const uint8_t **dst_vm_cache = NULL;
DST_THREAD_LOCAL uint32_t dst_vm_cache_capacity = 0;
DST_THREAD_LOCAL uint32_t dst_vm_cache_count = 0;
DST_THREAD_LOCAL uint32_t dst_vm_cache_deleted = 0;
/* Initialize the cache (allocate cache memory) */
void dst_symcache_init() {

View File

@ -27,7 +27,7 @@
#include "symcache.h"
/* VM state */
int dst_vm_stackn = 0;
DST_THREAD_LOCAL int dst_vm_stackn = 0;
/* Start running the VM from where it left off. */
Dst dst_run(DstFiber *fiber) {

View File

@ -27,7 +27,6 @@
extern "C" {
#endif
#define DST_VERSION "0.0.0 alpha"
/*
@ -90,6 +89,15 @@ extern "C" {
#define DST_LITTLE_ENDIAN 1
#endif
/* Check compiler */
#if defined(__GNUC__)
#define DST_THREAD_LOCAL __thread
#elif defined(_MSC_BUILD)
#define DST_THREAD_LOCAL __declspec(thread)
#else
#define DST_THREAD_LOCAL
#endif
/* Include default headers */
#include <stdint.h>

View File

@ -38,24 +38,24 @@ extern const char *dst_type_names[16];
* around, the vm state is global for simplicity. */
/* How many VM stacks have been entered */
extern int dst_vm_stackn;
extern DST_THREAD_LOCAL int dst_vm_stackn;
/* Garbage collection */
extern void *dst_vm_blocks;
extern uint32_t dst_vm_gc_interval;
extern uint32_t dst_vm_next_collection;
extern int dst_vm_gc_suspend;
extern DST_THREAD_LOCAL void *dst_vm_blocks;
extern DST_THREAD_LOCAL uint32_t dst_vm_gc_interval;
extern DST_THREAD_LOCAL uint32_t dst_vm_next_collection;
extern DST_THREAD_LOCAL int dst_vm_gc_suspend;
/* Immutable value cache */
extern const uint8_t **dst_vm_cache;
extern uint32_t dst_vm_cache_capacity;
extern uint32_t dst_vm_cache_count;
extern uint32_t dst_vm_cache_deleted;
extern DST_THREAD_LOCAL const uint8_t **dst_vm_cache;
extern DST_THREAD_LOCAL uint32_t dst_vm_cache_capacity;
extern DST_THREAD_LOCAL uint32_t dst_vm_cache_count;
extern DST_THREAD_LOCAL uint32_t dst_vm_cache_deleted;
/* GC roots */
extern Dst *dst_vm_roots;
extern uint32_t dst_vm_root_count;
extern uint32_t dst_vm_root_capacity;
extern DST_THREAD_LOCAL Dst *dst_vm_roots;
extern DST_THREAD_LOCAL uint32_t dst_vm_root_count;
extern DST_THREAD_LOCAL uint32_t dst_vm_root_capacity;
#ifdef __cplusplus
}