*refactored gc.

This commit is contained in:
Wang Renxin 2016-07-11 19:28:14 +08:00 committed by GitHub
parent 4ddeb1a0c3
commit 855eb36441

View File

@ -5731,7 +5731,10 @@ static _ref_count_t _ref(_ref_t* ref, void* data) {
static bool_t _unref(_ref_t* ref, void* data) { static bool_t _unref(_ref_t* ref, void* data) {
bool_t result = true; bool_t result = true;
_gc_t* gc = 0; _gc_t* gc = 0;
bool_t cld = false;
cld = *ref->count == _NONE_REF + 1;
do {
gc = &ref->s->gc; gc = &ref->s->gc;
result = --(*ref->count) == _NONE_REF; result = --(*ref->count) == _NONE_REF;
mb_assert(*ref->count >= _NONE_REF); mb_assert(*ref->count >= _NONE_REF);
@ -5741,6 +5744,11 @@ static bool_t _unref(_ref_t* ref, void* data) {
ref->on_unref(ref, data); ref->on_unref(ref, data);
if(result) if(result)
_gc_remove(ref, data, gc); _gc_remove(ref, data, gc);
} while(0);
if(cld) {
_ht_set_or_insert(gc->collected_table, ref, data);
_ht_set_or_insert(gc->collected_table, data, ref);
}
return result; return result;
} }
@ -6052,7 +6060,6 @@ static int _gc_destroy_garbage(void* data, void* extra, _gc_t* gc) {
int result = _OP_RESULT_NORMAL; int result = _OP_RESULT_NORMAL;
_ref_t* ref = 0; _ref_t* ref = 0;
bool_t proc = true; bool_t proc = true;
bool_t cld = false;
#ifdef MB_ENABLE_COLLECTION_LIB #ifdef MB_ENABLE_COLLECTION_LIB
_list_t* lst = 0; _list_t* lst = 0;
_dict_t* dct = 0; _dict_t* dct = 0;
@ -6105,14 +6112,8 @@ static int _gc_destroy_garbage(void* data, void* extra, _gc_t* gc) {
break; break;
} }
if(proc && ref->count) { if(proc && ref->count)
cld = *ref->count == _NONE_REF + 1;
_unref(ref, data); _unref(ref, data);
if(cld) {
_ht_set_or_insert(gc->collected_table, ref, data);
_ht_set_or_insert(gc->collected_table, data, ref);
}
}
if(proc) if(proc)
result = _OP_RESULT_DEL_NODE; result = _OP_RESULT_DEL_NODE;
@ -6126,7 +6127,6 @@ static int _gc_destroy_garbage_class(void* data, void* extra, _gc_t* gc) {
int result = _OP_RESULT_NORMAL; int result = _OP_RESULT_NORMAL;
_ref_t* ref = 0; _ref_t* ref = 0;
bool_t proc = true; bool_t proc = true;
bool_t cld = false;
_class_t* instance = 0; _class_t* instance = 0;
mb_assert(data && extra); mb_assert(data && extra);
@ -6151,14 +6151,8 @@ static int _gc_destroy_garbage_class(void* data, void* extra, _gc_t* gc) {
break; break;
} }
if(proc && ref->count) { if(proc && ref->count)
cld = *ref->count == _NONE_REF + 1;
_unref(ref, data); _unref(ref, data);
if(cld) {
_ht_set_or_insert(gc->collected_table, ref, data);
_ht_set_or_insert(gc->collected_table, data, ref);
}
}
if(proc) if(proc)
result = _OP_RESULT_DEL_NODE; result = _OP_RESULT_DEL_NODE;