1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-10 15:50:50 +02:00

More API-ification

This commit is contained in:
Andy Wingo 2022-08-09 11:35:31 +02:00
parent 4ccb489869
commit d8bcbf2d74
5 changed files with 30 additions and 25 deletions

14
bdw.h
View file

@ -211,8 +211,8 @@ static int gc_init(int argc, struct gc_option argv[],
return 1; return 1;
} }
static struct mutator* initialize_gc_for_thread(uintptr_t *stack_base, static struct mutator* gc_init_for_thread(uintptr_t *stack_base,
struct heap *heap) { struct heap *heap) {
pthread_mutex_lock(&heap->lock); pthread_mutex_lock(&heap->lock);
if (!heap->multithreaded) { if (!heap->multithreaded) {
GC_allow_register_threads(); GC_allow_register_threads();
@ -224,15 +224,13 @@ static struct mutator* initialize_gc_for_thread(uintptr_t *stack_base,
GC_register_my_thread(&base); GC_register_my_thread(&base);
return add_mutator(heap); return add_mutator(heap);
} }
static void finish_gc_for_thread(struct mutator *mut) { static void gc_finish_for_thread(struct mutator *mut) {
GC_unregister_my_thread(); GC_unregister_my_thread();
} }
static void* call_without_gc(struct mutator *mut, void* (*f)(void*), static void* gc_call_without_gc(struct mutator *mut,
void *data) NEVER_INLINE; void* (*f)(void*),
static void* call_without_gc(struct mutator *mut, void *data) {
void* (*f)(void*),
void *data) {
return GC_do_blocking(f, data); return GC_do_blocking(f, data);
} }

View file

@ -7,6 +7,9 @@
#define GC_DEBUG 0 #define GC_DEBUG 0
#endif #endif
#define GC_ALWAYS_INLINE __attribute__((always_inline))
#define GC_NEVER_INLINE __attribute__((noinline))
#define GC_UNLIKELY(e) __builtin_expect(e, 0) #define GC_UNLIKELY(e) __builtin_expect(e, 0)
#define GC_LIKELY(e) __builtin_expect(e, 1) #define GC_LIKELY(e) __builtin_expect(e, 1)
@ -52,7 +55,7 @@ struct gc_edge {
static inline struct gc_edge gc_edge(void* addr) { static inline struct gc_edge gc_edge(void* addr) {
return (struct gc_edge){addr}; return (struct gc_edge){addr};
} }
static struct gc_ref gc_edge_ref(struct gc_edge edge) { static inline struct gc_ref gc_edge_ref(struct gc_edge edge) {
return *edge.dst; return *edge.dst;
} }
static inline void gc_edge_update(struct gc_edge edge, struct gc_ref ref) { static inline void gc_edge_update(struct gc_edge edge, struct gc_ref ref) {
@ -82,4 +85,10 @@ GC_API_ int gc_option_from_string(const char *str);
GC_API_ int gc_init(int argc, struct gc_option argv[], GC_API_ int gc_init(int argc, struct gc_option argv[],
struct heap **heap, struct mutator **mutator); struct heap **heap, struct mutator **mutator);
GC_API_ struct mutator* gc_init_for_thread(uintptr_t *stack_base,
struct heap *heap);
GC_API_ void gc_finish_for_thread(struct mutator *mut);
GC_API_ void* gc_call_without_gc(struct mutator *mut, void* (*f)(void*),
void *data) GC_NEVER_INLINE;
#endif // GC_API_H_ #endif // GC_API_H_

View file

@ -307,9 +307,9 @@ struct call_with_gc_data {
}; };
static void* call_with_gc_inner(uintptr_t *stack_base, void *arg) { static void* call_with_gc_inner(uintptr_t *stack_base, void *arg) {
struct call_with_gc_data *data = arg; struct call_with_gc_data *data = arg;
struct mutator *mut = initialize_gc_for_thread(stack_base, data->heap); struct mutator *mut = gc_init_for_thread(stack_base, data->heap);
void *ret = data->f(mut); void *ret = data->f(mut);
finish_gc_for_thread(mut); gc_finish_for_thread(mut);
return ret; return ret;
} }
static void* call_with_gc(void* (*f)(struct mutator *), static void* call_with_gc(void* (*f)(struct mutator *),
@ -434,7 +434,7 @@ int main(int argc, char *argv[]) {
run_one_test(mut); run_one_test(mut);
for (size_t i = 1; i < nthreads; i++) { for (size_t i = 1; i < nthreads; i++) {
struct join_data data = { 0, threads[i] }; struct join_data data = { 0, threads[i] };
call_without_gc(mut, join_thread, &data); gc_call_without_gc(mut, join_thread, &data);
if (data.status) { if (data.status) {
errno = data.status; errno = data.status;
perror("Failed to join thread"); perror("Failed to join thread");

10
semi.h
View file

@ -370,17 +370,17 @@ static int gc_init(int argc, struct gc_option argv[],
return 1; return 1;
} }
static struct mutator* initialize_gc_for_thread(uintptr_t *stack_base, static struct mutator* gc_init_for_thread(uintptr_t *stack_base,
struct heap *heap) { struct heap *heap) {
fprintf(stderr, fprintf(stderr,
"Semispace copying collector not appropriate for multithreaded use.\n"); "Semispace copying collector not appropriate for multithreaded use.\n");
exit(1); exit(1);
} }
static void finish_gc_for_thread(struct mutator *space) { static void gc_finish_for_thread(struct mutator *space) {
} }
static void* call_without_gc(struct mutator *mut, void* (*f)(void*), static void* gc_call_without_gc(struct mutator *mut, void* (*f)(void*),
void *data) { void *data) {
// Can't be threads, then there won't be collection. // Can't be threads, then there won't be collection.
return f(data); return f(data);
} }

View file

@ -2079,8 +2079,8 @@ static int gc_init(int argc, struct gc_option argv[],
return 1; return 1;
} }
static struct mutator* initialize_gc_for_thread(uintptr_t *stack_base, static struct mutator* gc_init_for_thread(uintptr_t *stack_base,
struct heap *heap) { struct heap *heap) {
struct mutator *ret = calloc(1, sizeof(struct mutator)); struct mutator *ret = calloc(1, sizeof(struct mutator));
if (!ret) if (!ret)
abort(); abort();
@ -2088,7 +2088,7 @@ static struct mutator* initialize_gc_for_thread(uintptr_t *stack_base,
return ret; return ret;
} }
static void finish_gc_for_thread(struct mutator *mut) { static void gc_finish_for_thread(struct mutator *mut) {
remove_mutator(mutator_heap(mut), mut); remove_mutator(mutator_heap(mut), mut);
mutator_mark_buf_destroy(&mut->mark_buf); mutator_mark_buf_destroy(&mut->mark_buf);
free(mut); free(mut);
@ -2118,11 +2118,9 @@ static void reactivate_mutator(struct heap *heap, struct mutator *mut) {
heap_unlock(heap); heap_unlock(heap);
} }
static void* call_without_gc(struct mutator *mut, void* (*f)(void*), static void* gc_call_without_gc(struct mutator *mut,
void *data) NEVER_INLINE; void* (*f)(void*),
static void* call_without_gc(struct mutator *mut, void *data) {
void* (*f)(void*),
void *data) {
struct heap *heap = mutator_heap(mut); struct heap *heap = mutator_heap(mut);
deactivate_mutator(heap, mut); deactivate_mutator(heap, mut);
void *ret = f(data); void *ret = f(data);