Use a lock to synchronize writes to symbol table

This commit is contained in:
Justin Ethier 2015-12-21 23:06:10 -05:00
parent be13df2abb
commit 9de27c2f98
2 changed files with 8 additions and 4 deletions

View file

@ -12,8 +12,6 @@ TODO:
- 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
TODO items:
- lock writes to symbol table
- 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.

View file

@ -102,6 +102,7 @@ static symbol_type __EOF = {{0}, eof_tag, "", nil}; // symbol_type in lieu of cu
const object Cyc_EOF = &__EOF;
static ck_hs_t symbol_table;
static int symbol_table_size = 65536;
static pthread_mutex_t symbol_table_lock;
// Functions to support concurrency kit hashset
// 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");
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()
@ -245,13 +250,14 @@ object find_symbol_by_name(const char *name) {
object add_symbol(symbol_type *psym) {
//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
// TODO: grow table if it is not big enough
pthread_mutex_lock(&symbol_table_lock); // Only 1 "writer" allowed
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");
exit(1);
}
set_insert(&symbol_table, psym);
pthread_mutex_unlock(&symbol_table_lock);
return psym;
}