loop_job.c   loop_job.c 
skipping to change at line 33 skipping to change at line 33
#include <qb/qbdefs.h> #include <qb/qbdefs.h>
#include <qb/qblist.h> #include <qb/qblist.h>
#include <qb/qbloop.h> #include <qb/qbloop.h>
#include "loop_int.h" #include "loop_int.h"
struct qb_loop_job { struct qb_loop_job {
struct qb_loop_item item; struct qb_loop_item item;
qb_loop_job_dispatch_fn dispatch_fn; qb_loop_job_dispatch_fn dispatch_fn;
}; };
static void job_dispatch(struct qb_loop_item * item, static void
enum qb_loop_priority p) job_dispatch(struct qb_loop_item *item, enum qb_loop_priority p)
{ {
struct qb_loop_job *job = qb_list_entry(item, struct qb_loop_job, it em); struct qb_loop_job *job = qb_list_entry(item, struct qb_loop_job, it em);
job->dispatch_fn(job->item.user_data); job->dispatch_fn(job->item.user_data);
free(job); free(job);
// this is a one-shot so don't re-add /*
* this is a one-shot so don't re-add
*/
} }
static int32_t get_more_jobs(struct qb_loop_source* s, int32_t ms_timeout) static int32_t
get_more_jobs(struct qb_loop_source *s, int32_t ms_timeout)
{ {
int32_t p; int32_t p;
int32_t new_jobs = 0; int32_t new_jobs = 0;
// this is simple, move jobs from wait_head to job_head /*
* this is simple, move jobs from wait_head to job_head
*/
for (p = QB_LOOP_LOW; p <= QB_LOOP_HIGH; p++) { for (p = QB_LOOP_LOW; p <= QB_LOOP_HIGH; p++) {
if (!qb_list_empty(&s->l->level[p].wait_head)) { if (!qb_list_empty(&s->l->level[p].wait_head)) {
new_jobs += qb_list_length(&s->l->level[p].wait_head ); new_jobs += qb_list_length(&s->l->level[p].wait_head );
qb_list_splice(&s->l->level[p].wait_head, &s->l->lev qb_list_splice(&s->l->level[p].wait_head,
el[p].job_head); &s->l->level[p].job_head);
qb_list_init(&s->l->level[p].wait_head); qb_list_init(&s->l->level[p].wait_head);
} }
} }
return new_jobs; return new_jobs;
} }
struct qb_loop_source * struct qb_loop_source *
qb_loop_jobs_create(struct qb_loop *l) qb_loop_jobs_create(struct qb_loop *l)
{ {
struct qb_loop_source *s = malloc(sizeof(struct qb_loop_source)); struct qb_loop_source *s = malloc(sizeof(struct qb_loop_source));
if (s == NULL) {
return NULL;
}
s->l = l; s->l = l;
s->dispatch_and_take_back = job_dispatch; s->dispatch_and_take_back = job_dispatch;
s->poll = get_more_jobs; s->poll = get_more_jobs;
return s; return s;
} }
void qb_loop_jobs_destroy(struct qb_loop *l) void
qb_loop_jobs_destroy(struct qb_loop *l)
{ {
free(l->job_source); free(l->job_source);
} }
int32_t qb_loop_job_add(struct qb_loop *l, int32_t
enum qb_loop_priority p, qb_loop_job_add(struct qb_loop *l,
void *data, enum qb_loop_priority p,
qb_loop_job_dispatch_fn dispatch_fn) void *data, qb_loop_job_dispatch_fn dispatch_fn)
{ {
struct qb_loop_job *job; struct qb_loop_job *job;
if (l == NULL || dispatch_fn == NULL) { if (l == NULL || dispatch_fn == NULL) {
return -EINVAL; return -EINVAL;
} }
if (p < QB_LOOP_LOW || p > QB_LOOP_HIGH) { if (p < QB_LOOP_LOW || p > QB_LOOP_HIGH) {
return -EINVAL; return -EINVAL;
} }
job = malloc(sizeof(struct qb_loop_job)); job = malloc(sizeof(struct qb_loop_job));
if (job == NULL) {
return -ENOMEM;
}
job->dispatch_fn = dispatch_fn; job->dispatch_fn = dispatch_fn;
job->item.user_data = data; job->item.user_data = data;
job->item.source = l->job_source; job->item.source = l->job_source;
qb_list_init(&job->item.list); qb_list_init(&job->item.list);
qb_list_add_tail(&job->item.list, &l->level[p].wait_head); qb_list_add_tail(&job->item.list, &l->level[p].wait_head);
return 0; return 0;
} }
 End of changes. 9 change blocks. 
12 lines changed or deleted 24 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/