|
|
|
@ -34,7 +34,7 @@ static void work_finish(struct mf_work* j) { |
|
|
|
while (*link && *link != j) link = &(*link)->next; |
|
|
|
while (*link && *link != j) link = &(*link)->next; |
|
|
|
if (*link) *link = j->next; |
|
|
|
if (*link) *link = j->next; |
|
|
|
w->count--; |
|
|
|
w->count--; |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_DEBUG, "member_files: worker callback owner=%p task=%p remaining=%u pid=%ld", |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_MEDIA, "member_files: worker callback owner=%p task=%p remaining=%u pid=%ld", |
|
|
|
(void*)w, (void*)j, w->count, (long)getpid()); |
|
|
|
(void*)w, (void*)j, w->count, (long)getpid()); |
|
|
|
mf_done_fn done = j->done; void* arg = j->arg; |
|
|
|
mf_done_fn done = j->done; void* arg = j->arg; |
|
|
|
u_free(j); done(arg, 0); |
|
|
|
u_free(j); done(arg, 0); |
|
|
|
@ -57,11 +57,11 @@ static void* disk_thread(void* arg) { |
|
|
|
struct mf_work* j = w->queue; w->queue = j->queued_next; |
|
|
|
struct mf_work* j = w->queue; w->queue = j->queued_next; |
|
|
|
if (!w->queue) w->tail = NULL; |
|
|
|
if (!w->queue) w->tail = NULL; |
|
|
|
pthread_mutex_unlock(&w->mutex); |
|
|
|
pthread_mutex_unlock(&w->mutex); |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_DEBUG, "member_files: worker execute owner=%p task=%p pid=%ld", (void*)w, (void*)j, (long)getpid()); |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_MEDIA, "member_files: worker execute owner=%p task=%p pid=%ld", (void*)w, (void*)j, (long)getpid()); |
|
|
|
j->work(j->data); |
|
|
|
j->work(j->data); |
|
|
|
pthread_mutex_lock(&w->mutex); |
|
|
|
pthread_mutex_lock(&w->mutex); |
|
|
|
j->completed = 1; |
|
|
|
j->completed = 1; |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_DEBUG, "member_files: worker posting owner=%p task=%p pid=%ld", (void*)w, (void*)j, (long)getpid()); |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_MEDIA, "member_files: worker posting owner=%p task=%p pid=%ld", (void*)w, (void*)j, (long)getpid()); |
|
|
|
uasync_post_reserved(w->ua, j->completion); |
|
|
|
uasync_post_reserved(w->ua, j->completion); |
|
|
|
pthread_cond_broadcast(&w->condition); |
|
|
|
pthread_cond_broadcast(&w->condition); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -85,7 +85,7 @@ struct mf_worker* mf_worker_create(struct UASYNC* ua) { |
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "member_files: disk thread failed rc=%d", rc); |
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, "member_files: disk thread failed rc=%d", rc); |
|
|
|
pthread_cond_destroy(&w->condition); pthread_mutex_destroy(&w->mutex); u_free(w); return NULL; |
|
|
|
pthread_cond_destroy(&w->condition); pthread_mutex_destroy(&w->mutex); u_free(w); return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "member_files: worker created owner=%p pid=%ld ua=%p limit=64", |
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_MEDIA, "member_files: worker created owner=%p pid=%ld ua=%p limit=64", |
|
|
|
(void*)w, w->creator_pid, (void*)ua); |
|
|
|
(void*)w, w->creator_pid, (void*)ua); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_MEDIA, "member_files: disk thread started queue_limit=64"); return w; |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_MEDIA, "member_files: disk thread started queue_limit=64"); return w; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -102,12 +102,12 @@ void mf_worker_unreserve(struct mf_work* j) { if (j) { u_free(j->completion); u_ |
|
|
|
|
|
|
|
|
|
|
|
void mf_worker_submit_reserved(struct mf_worker* w, struct mf_work* j, |
|
|
|
void mf_worker_submit_reserved(struct mf_worker* w, struct mf_work* j, |
|
|
|
mf_work_fn work, void* data, mf_done_fn done, void* arg) { |
|
|
|
mf_work_fn work, void* data, mf_done_fn done, void* arg) { |
|
|
|
if (w->creator_pid != (long)getpid()) DEBUG_ERROR(DEBUG_CATEGORY_DEBUG, |
|
|
|
if (w->creator_pid != (long)getpid()) DEBUG_ERROR(DEBUG_CATEGORY_MEDIA, |
|
|
|
"member_files: worker inherited after fork creator_pid=%ld current_pid=%ld; disk thread is missing", |
|
|
|
"member_files: worker inherited after fork creator_pid=%ld current_pid=%ld; disk thread is missing", |
|
|
|
w->creator_pid, (long)getpid()); |
|
|
|
w->creator_pid, (long)getpid()); |
|
|
|
j->owner = w; j->work = work; j->data = data; j->done = done; j->arg = arg; |
|
|
|
j->owner = w; j->work = work; j->data = data; j->done = done; j->arg = arg; |
|
|
|
j->next = w->jobs; w->jobs = j; w->count++; |
|
|
|
j->next = w->jobs; w->jobs = j; w->count++; |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_DEBUG, "member_files: worker queued owner=%p task=%p current_pid=%ld creator_pid=%ld active=%u", |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_MEDIA, "member_files: worker queued owner=%p task=%p current_pid=%ld creator_pid=%ld active=%u", |
|
|
|
(void*)w, (void*)j, (long)getpid(), w->creator_pid, w->count); |
|
|
|
(void*)w, (void*)j, (long)getpid(), w->creator_pid, w->count); |
|
|
|
pthread_mutex_lock(&w->mutex); |
|
|
|
pthread_mutex_lock(&w->mutex); |
|
|
|
if (w->tail) w->tail->queued_next = j; |
|
|
|
if (w->tail) w->tail->queued_next = j; |
|
|
|
@ -137,7 +137,7 @@ void mf_worker_drain(struct mf_worker* w) { |
|
|
|
|
|
|
|
|
|
|
|
void mf_worker_destroy(struct mf_worker* w) { |
|
|
|
void mf_worker_destroy(struct mf_worker* w) { |
|
|
|
if (!w) return; |
|
|
|
if (!w) return; |
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "member_files: worker stop owner=%p current_pid=%ld creator_pid=%ld active=%u", |
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_MEDIA, "member_files: worker stop owner=%p current_pid=%ld creator_pid=%ld active=%u", |
|
|
|
(void*)w, (long)getpid(), w->creator_pid, w->count); |
|
|
|
(void*)w, (long)getpid(), w->creator_pid, w->count); |
|
|
|
mf_worker_drain(w); |
|
|
|
mf_worker_drain(w); |
|
|
|
pthread_mutex_lock(&w->mutex); w->stopping = 1; pthread_cond_signal(&w->condition); pthread_mutex_unlock(&w->mutex); |
|
|
|
pthread_mutex_lock(&w->mutex); w->stopping = 1; pthread_cond_signal(&w->condition); pthread_mutex_unlock(&w->mutex); |
|
|
|
|