summaryrefslogtreecommitdiff
path: root/accel-pppd/triton
diff options
context:
space:
mode:
Diffstat (limited to 'accel-pppd/triton')
-rw-r--r--accel-pppd/triton/triton.c29
-rw-r--r--accel-pppd/triton/triton.h4
-rw-r--r--accel-pppd/triton/triton_p.h8
3 files changed, 41 insertions, 0 deletions
diff --git a/accel-pppd/triton/triton.c b/accel-pppd/triton/triton.c
index df3d5c1c..4d3359bd 100644
--- a/accel-pppd/triton/triton.c
+++ b/accel-pppd/triton/triton.c
@@ -22,6 +22,8 @@ static LIST_HEAD(ctx_queue);
static spinlock_t ctx_list_lock = SPINLOCK_INITIALIZER;
static LIST_HEAD(ctx_list);
+static LIST_HEAD(init_list);
+
static int terminate;
static int need_terminate;
@@ -523,6 +525,24 @@ static void ru_update(struct triton_timer_t *t)
ru_stime = rusage.ru_stime;
}
+void __export triton_register_init(int order, void (*func)(void))
+{
+ struct _triton_init_t *i1, *i = _malloc(sizeof(*i));
+ struct list_head *p = init_list.prev;
+
+
+ i->order = order;
+ i->func = func;
+
+ while (p != &init_list) {
+ i1 = list_entry(p, typeof(*i1), entry);
+ if (order > i1->order)
+ break;
+ p = p->prev;
+ }
+ list_add(&i->entry, p);
+}
+
int __export triton_init(const char *conf_file)
{
ctx_pool = mempool_create(sizeof(struct _triton_context_t));
@@ -548,8 +568,17 @@ int __export triton_init(const char *conf_file)
int __export triton_load_modules(const char *mod_sect)
{
+ struct _triton_init_t *i;
+
if (load_modules(mod_sect))
return -1;
+
+ while (!list_empty(&init_list)) {
+ i = list_entry(init_list.next, typeof(*i), entry);
+ i->func();
+ list_del(&i->entry);
+ _free(i);
+ }
return 0;
}
diff --git a/accel-pppd/triton/triton.h b/accel-pppd/triton/triton.h
index 98ef1113..95851c2d 100644
--- a/accel-pppd/triton/triton.h
+++ b/accel-pppd/triton/triton.h
@@ -106,6 +106,8 @@ void triton_stop_collect_cpu_usage(void);
int triton_module_loaded(const char *name);
+void triton_register_init(int order, void (*func)(void));
+
#define TRITON_OK 0
#define TRITON_ERR_NOCOMP -1
@@ -137,4 +139,6 @@ void triton_terminate(void);
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
+#define DEFINE_INIT(o, func) static void __init __init__(void){triton_register_init(o,func);}
+
#endif
diff --git a/accel-pppd/triton/triton_p.h b/accel-pppd/triton/triton_p.h
index 235eb701..2eb2e62a 100644
--- a/accel-pppd/triton/triton_p.h
+++ b/accel-pppd/triton/triton_p.h
@@ -82,6 +82,14 @@ struct _triton_ctx_call_t
void (*func)(void *);
};
+struct _triton_init_t
+{
+ struct list_head entry;
+
+ int order;
+ void (*func)(void);
+};
+
int log_init(void);
int md_init();
int timer_init();