Skip to content

Commit db545ac

Browse files
committed
Merge pull request kevints#8 from andrewmains12/global_queue_offer
Some small fixes
2 parents dab9b1d + 6be3345 commit db545ac

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

gc-test/simple.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#require 'GC'
2+
3+
#gc.disable
4+
#Shallow graph
5+
1000000.times do
6+
Hash.new
7+
end
8+
# GC.enable
9+
# GC.start

gc.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ typedef struct deque_struct {
437437

438438

439439
static void deque_init(deque_t* deque, int max_length);
440-
static void deque_init_with_buf(deque_t* deque, VALUE* buffer, int max_length);
440+
static void deque_destroy(deque_t* deque);
441441
/* Push val onto the front of deque. Returns 1 if successful, 0 if the stack is
442442
already full.
443443
*/
@@ -450,14 +450,19 @@ static int deque_full_p(deque_t* deque);
450450
static void deque_init(deque_t* deque, int max_length) {
451451
//TODO: check error and handle this reasonably
452452
VALUE* buffer = (VALUE*) malloc(sizeof(VALUE)*max_length);
453-
deque_init_with_buf(deque, buffer, max_length);
454-
}
455453

456-
static void deque_init_with_buf(deque_t* deque, VALUE* buffer, int max_length) {
457454
deque->buffer = buffer;
458455
deque->max_length = max_length;
459456
deque->length = 0;
460-
deque->head = deque->tail = -1;
457+
deque->head = deque->tail = -1;
458+
}
459+
460+
static void deque_destroy(deque_t* deque) {
461+
free(deque->buffer);
462+
}
463+
464+
static void deque_destroy_callback(void* deque) {
465+
deque_destroy((deque_t*) deque);
461466
}
462467

463468
static int deque_push(deque_t* deque, VALUE val) {
@@ -565,6 +570,7 @@ void global_queue_init(global_queue_t* global_queue) {
565570
}
566571

567572
void global_queue_destroy(global_queue_t* global_queue) {
573+
deque_destroy(&(global_queue->deque));
568574
pthread_mutex_destroy(&global_queue->lock);
569575
pthread_cond_destroy(&global_queue->wait_condition);
570576
}
@@ -647,7 +653,7 @@ void gc_mark_parallel(rb_objspace_t* objspace) {
647653
global_queue = &queuedata;
648654
global_queue_init(global_queue);
649655

650-
pthread_key_create(&thread_local_deque_k, NULL);
656+
pthread_key_create(&thread_local_deque_k, deque_destroy_callback);
651657

652658
pthread_attr_init(&attr);
653659
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
@@ -2450,8 +2456,8 @@ gc_lazy_sweep(rb_objspace_t *objspace)
24502456
return TRUE;
24512457
}
24522458
}
2453-
2454-
gc_marks(objspace);
2459+
// gc_marks(objspace);
2460+
gc_mark_parallel(objspace);
24552461

24562462
before_gc_sweep(objspace);
24572463
if (objspace->heap.free_min > (heaps_used * HEAP_OBJ_LIMIT - objspace->heap.live_num)) {

0 commit comments

Comments
 (0)