Ver Fonte

review gc threads info access

Nicolas Cannasse há 2 anos atrás
pai
commit
95c2fc7fbe
4 ficheiros alterados com 16 adições e 19 exclusões
  1. 0 1
      src/debugger.c
  2. 2 7
      src/gc.c
  3. 8 0
      src/hl.h
  4. 6 11
      src/profile.c

+ 0 - 1
src/debugger.c

@@ -33,7 +33,6 @@ HL_API hl_socket *hl_socket_accept( hl_socket *s );
 HL_API int hl_socket_send( hl_socket *s, vbyte *buf, int pos, int len );
 HL_API int hl_socket_send( hl_socket *s, vbyte *buf, int pos, int len );
 HL_API int hl_socket_recv( hl_socket *s, vbyte *buf, int pos, int len );
 HL_API int hl_socket_recv( hl_socket *s, vbyte *buf, int pos, int len );
 HL_API void hl_sys_sleep( double t );
 HL_API void hl_sys_sleep( double t );
-HL_API void *hl_gc_threads_info();
 HL_API int hl_sys_getpid();
 HL_API int hl_sys_getpid();
 
 
 HL_API int hl_closure_stack_capture;
 HL_API int hl_closure_stack_capture;

+ 2 - 7
src/gc.c

@@ -160,12 +160,7 @@ static void gc_free_page( gc_pheader *page, int block_count );
 #include "allocator.c"
 #include "allocator.c"
 #endif
 #endif
 
 
-static struct {
-	int count;
-	bool stopping_world;
-	hl_thread_info **threads;
-	hl_mutex *global_lock;
-} gc_threads;
+static hl_threads_info gc_threads;
 
 
 HL_THREAD_STATIC_VAR hl_thread_info *current_thread;
 HL_THREAD_STATIC_VAR hl_thread_info *current_thread;
 
 
@@ -325,7 +320,7 @@ HL_API void hl_unregister_thread() {
 	hl_mutex_release(gc_threads.global_lock);
 	hl_mutex_release(gc_threads.global_lock);
 }
 }
 
 
-HL_API void *hl_gc_threads_info() {
+HL_API hl_threads_info *hl_gc_threads_info() {
 	return &gc_threads;
 	return &gc_threads;
 }
 }
 
 

+ 8 - 0
src/hl.h

@@ -916,7 +916,15 @@ typedef struct {
 	int extra_stack_size;
 	int extra_stack_size;
 } hl_thread_info;
 } hl_thread_info;
 
 
+typedef struct {
+	int count;
+	bool stopping_world;
+	hl_thread_info **threads;
+	hl_mutex *global_lock;
+} hl_threads_info;
+
 HL_API hl_thread_info *hl_get_thread();
 HL_API hl_thread_info *hl_get_thread();
+HL_API hl_threads_info *hl_gc_threads_info();
 
 
 #ifdef HL_TRACK_ENABLE
 #ifdef HL_TRACK_ENABLE
 
 

+ 6 - 11
src/profile.c

@@ -42,17 +42,10 @@
 #define MAX_STACK_COUNT 2048
 #define MAX_STACK_COUNT 2048
 
 
 HL_API double hl_sys_time( void );
 HL_API double hl_sys_time( void );
-HL_API void *hl_gc_threads_info( void );
 HL_API void hl_setup_profiler( void *, void * );
 HL_API void hl_setup_profiler( void *, void * );
 int hl_module_capture_stack_range( void *stack_top, void **stack_ptr, void **out, int size );
 int hl_module_capture_stack_range( void *stack_top, void **stack_ptr, void **out, int size );
 uchar *hl_module_resolve_symbol_full( void *addr, uchar *out, int *outSize, int **r_debug_addr );
 uchar *hl_module_resolve_symbol_full( void *addr, uchar *out, int *outSize, int **r_debug_addr );
 
 
-typedef struct {
-	int count;
-	bool stopping_world;
-	hl_thread_info **threads;
-} hl_gc_threads;
-
 typedef struct _thread_handle thread_handle;
 typedef struct _thread_handle thread_handle;
 typedef struct _profile_data profile_data;
 typedef struct _profile_data profile_data;
 
 
@@ -211,8 +204,8 @@ static void read_thread_data( thread_handle *t ) {
 #endif
 #endif
 	int eventId = count | 0x80000000;
 	int eventId = count | 0x80000000;
 	double time = hl_sys_time();
 	double time = hl_sys_time();
-	struct { int count; bool stop; } *gc = hl_gc_threads_info();
-	if( gc->stop ) eventId |= 0x40000000;
+	hl_threads_info *gc = hl_gc_threads_info();
+	if( gc->stopping_world ) eventId |= 0x40000000;
 	record_data(&time,sizeof(double));
 	record_data(&time,sizeof(double));
 	record_data(&t->tid,sizeof(int));
 	record_data(&t->tid,sizeof(int));
 	record_data(&eventId,sizeof(int));
 	record_data(&eventId,sizeof(int));
@@ -230,7 +223,7 @@ static void hl_profile_loop( void *_ ) {
 			data.waitLoop = false;
 			data.waitLoop = false;
 			continue;
 			continue;
 		}
 		}
-		hl_gc_threads *threads = (hl_gc_threads*)hl_gc_threads_info();
+		hl_threads_info *threads = hl_gc_threads_info();
 		int i;
 		int i;
 		thread_handle *prev = NULL;
 		thread_handle *prev = NULL;
 		thread_handle *cur = data.handles;
 		thread_handle *cur = data.handles;
@@ -254,9 +247,11 @@ static void hl_profile_loop( void *_ ) {
 		}
 		}
 		if( prev ) prev->next = NULL; else data.handles = NULL;
 		if( prev ) prev->next = NULL; else data.handles = NULL;
 		while( cur != NULL ) {
 		while( cur != NULL ) {
+			thread_handle *n;
 			thread_data_free(cur);
 			thread_data_free(cur);
+			n = cur->next;
 			free(cur);
 			free(cur);
-			cur = cur->next;
+			cur = n;
 		}
 		}
 		next += wait_time;
 		next += wait_time;
 	}
 	}