mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-16 17:27:33 +02:00
Use a lock to synchronize writes to symbol table
This commit is contained in:
parent
be13df2abb
commit
9de27c2f98
2 changed files with 8 additions and 4 deletions
|
@ -12,8 +12,6 @@ TODO:
|
||||||
|
|
||||||
- multiple mutators, and threading functions/types. probably want this on a new branch, when ready
|
- multiple mutators, and threading functions/types. probably want this on a new branch, when ready
|
||||||
part of this is implementing the beginnings of srfi-18, to create multiple threads, sync them, etc
|
part of this is implementing the beginnings of srfi-18, to create multiple threads, sync them, etc
|
||||||
TODO items:
|
|
||||||
- lock writes to symbol table
|
|
||||||
|
|
||||||
- need to cooperate when a mutator is blocked
|
- need to cooperate when a mutator is blocked
|
||||||
might be able to stop a thread and do a minor GC on it, but no longjmp until after major GC.
|
might be able to stop a thread and do a minor GC on it, but no longjmp until after major GC.
|
||||||
|
|
10
runtime.c
10
runtime.c
|
@ -102,6 +102,7 @@ static symbol_type __EOF = {{0}, eof_tag, "", nil}; // symbol_type in lieu of cu
|
||||||
const object Cyc_EOF = &__EOF;
|
const object Cyc_EOF = &__EOF;
|
||||||
static ck_hs_t symbol_table;
|
static ck_hs_t symbol_table;
|
||||||
static int symbol_table_size = 65536;
|
static int symbol_table_size = 65536;
|
||||||
|
static pthread_mutex_t symbol_table_lock;
|
||||||
|
|
||||||
// Functions to support concurrency kit hashset
|
// Functions to support concurrency kit hashset
|
||||||
// These are specifically for a table of symbols
|
// These are specifically for a table of symbols
|
||||||
|
@ -168,6 +169,10 @@ void gc_init_heap(long heap_size)
|
||||||
fprintf(stderr, "Unable to initialize symbol table\n");
|
fprintf(stderr, "Unable to initialize symbol table\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
if (pthread_mutex_init(&(symbol_table_lock), NULL) != 0) {
|
||||||
|
fprintf(stderr, "Unable to initialize symbol_table_lock mutex\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gc_heap *gc_get_heap()
|
gc_heap *gc_get_heap()
|
||||||
|
@ -245,13 +250,14 @@ object find_symbol_by_name(const char *name) {
|
||||||
|
|
||||||
object add_symbol(symbol_type *psym) {
|
object add_symbol(symbol_type *psym) {
|
||||||
//printf("Adding symbol %s, table size = %ld\n", symbol_pname(psym), ck_hs_count(&symbol_table));
|
//printf("Adding symbol %s, table size = %ld\n", symbol_pname(psym), ck_hs_count(&symbol_table));
|
||||||
// TODO: lock table here, only allow one writer at a time
|
pthread_mutex_lock(&symbol_table_lock); // Only 1 "writer" allowed
|
||||||
// TODO: grow table if it is not big enough
|
|
||||||
if (ck_hs_count(&symbol_table) == symbol_table_size) {
|
if (ck_hs_count(&symbol_table) == symbol_table_size) {
|
||||||
|
// TODO: grow table if it is not big enough
|
||||||
fprintf(stderr, "Ran out of symbol table entries\n");
|
fprintf(stderr, "Ran out of symbol table entries\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
set_insert(&symbol_table, psym);
|
set_insert(&symbol_table, psym);
|
||||||
|
pthread_mutex_unlock(&symbol_table_lock);
|
||||||
return psym;
|
return psym;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue