Handle continous jobs via new subsystem - CJob
This commit is contained in:
36
kernel/cjob/cjob.c
Normal file
36
kernel/cjob/cjob.c
Normal file
@ -0,0 +1,36 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "spinlock/spinlock.h"
|
||||
#include "cjob/cjob.h"
|
||||
#include "dlmalloc/malloc.h"
|
||||
#include "util/util.h"
|
||||
|
||||
CJobs CJOBS;
|
||||
static uint64_t cjobids = 0;
|
||||
|
||||
void cjob_init(void) {
|
||||
spinlock_init(&CJOBS.spinlock);
|
||||
CJOBS.cjobs = NULL;
|
||||
}
|
||||
|
||||
int32_t cjob_register(CJobFn fn, void *arg) {
|
||||
CJob *cjob = dlmalloc(sizeof(*cjob));
|
||||
cjob->fn = fn;
|
||||
cjob->arg = arg;
|
||||
int32_t id = cjob->id = cjobids++;
|
||||
|
||||
spinlock_acquire(&CJOBS.spinlock);
|
||||
LL_APPEND(CJOBS.cjobs, cjob);
|
||||
spinlock_release(&CJOBS.spinlock);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void cjob_runjobs(void) {
|
||||
CJob *cjob, *cjobtmp;
|
||||
spinlock_acquire(&CJOBS.spinlock);
|
||||
LL_FOREACH_SAFE(CJOBS.cjobs, cjob, cjobtmp) {
|
||||
cjob->fn(cjob->arg);
|
||||
}
|
||||
spinlock_release(&CJOBS.spinlock);
|
||||
}
|
||||
Reference in New Issue
Block a user