mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 04:25:06 +02:00
Refactoring
This commit is contained in:
parent
be0384cd98
commit
86bdf0c5aa
1 changed files with 26 additions and 14 deletions
40
gc.c
40
gc.c
|
@ -702,6 +702,29 @@ void vpbuffer_free(void **buf)
|
||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
// GC functions called by the Mutator threads
|
// GC functions called by the Mutator threads
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear thread data read/write fields
|
||||||
|
*/
|
||||||
|
void gc_zero_read_write_counts(gc_thread_data *thd)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&(thd->lock));
|
||||||
|
thd->last_write = 0;
|
||||||
|
thd->last_read = 0;
|
||||||
|
thd->pending_writes = 0;
|
||||||
|
pthread_mutex_unlock(&(thd->lock));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move pending writes to last_write
|
||||||
|
*/
|
||||||
|
void gc_sum_pending_writes(gc_thread_data *thd)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&(thd->lock));
|
||||||
|
thd->last_write += thd->pending_writes;
|
||||||
|
thd->pending_writes = 0;
|
||||||
|
pthread_mutex_unlock(&(thd->lock));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if object lives on the thread's stack
|
* Determine if object lives on the thread's stack
|
||||||
*/
|
*/
|
||||||
|
@ -761,10 +784,7 @@ void gc_mut_cooperate(gc_thread_data *thd, int buf_len)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Handle any pending marks from write barrier
|
// Handle any pending marks from write barrier
|
||||||
pthread_mutex_lock(&(thd->lock));
|
gc_sum_pending_writes(thd);
|
||||||
thd->last_write += thd->pending_writes;
|
|
||||||
thd->pending_writes = 0;
|
|
||||||
pthread_mutex_unlock(&(thd->lock));
|
|
||||||
|
|
||||||
// I think below is thread safe, but this code is tricky.
|
// I think below is thread safe, but this code is tricky.
|
||||||
// Worst case should be that some work is done twice if there is
|
// Worst case should be that some work is done twice if there is
|
||||||
|
@ -777,11 +797,7 @@ void gc_mut_cooperate(gc_thread_data *thd, int buf_len)
|
||||||
ck_pr_cas_int(&(thd->gc_status), status_m, status_c);
|
ck_pr_cas_int(&(thd->gc_status), status_m, status_c);
|
||||||
if (status_m == STATUS_ASYNC) {
|
if (status_m == STATUS_ASYNC) {
|
||||||
// Async is done, so clean up old mark data from the last collection
|
// Async is done, so clean up old mark data from the last collection
|
||||||
pthread_mutex_lock(&(thd->lock));
|
gc_zero_read_write_counts(thd);
|
||||||
thd->last_write = 0;
|
|
||||||
thd->last_read = 0;
|
|
||||||
thd->pending_writes = 0;
|
|
||||||
pthread_mutex_unlock(&(thd->lock));
|
|
||||||
}
|
}
|
||||||
else if (status_m == STATUS_SYNC2) {
|
else if (status_m == STATUS_SYNC2) {
|
||||||
#if GC_DEBUG_VERBOSE
|
#if GC_DEBUG_VERBOSE
|
||||||
|
@ -1061,11 +1077,7 @@ void gc_wait_handshake()
|
||||||
if (statusm == STATUS_ASYNC) { // Prev state
|
if (statusm == STATUS_ASYNC) { // Prev state
|
||||||
ck_pr_cas_int(&(m->gc_status), statusm, statusc);
|
ck_pr_cas_int(&(m->gc_status), statusm, statusc);
|
||||||
// Async is done, so clean up old mark data from the last collection
|
// Async is done, so clean up old mark data from the last collection
|
||||||
pthread_mutex_lock(&(m->lock));
|
gc_zero_read_write_counts(m);
|
||||||
m->last_write = 0;
|
|
||||||
m->last_read = 0;
|
|
||||||
m->pending_writes = 0;
|
|
||||||
pthread_mutex_unlock(&(m->lock));
|
|
||||||
}else if (statusm == STATUS_SYNC1) {
|
}else if (statusm == STATUS_SYNC1) {
|
||||||
ck_pr_cas_int(&(m->gc_status), statusm, statusc);
|
ck_pr_cas_int(&(m->gc_status), statusm, statusc);
|
||||||
} else if (statusm == STATUS_SYNC2) {
|
} else if (statusm == STATUS_SYNC2) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue