mirror of
https://github.com/opnsense/src.git
synced 2026-06-09 08:43:19 -04:00
Add kobj_class_compile_static() to allow classes to be initialised
statically (i.e. without calling malloc). This allows kobj to be used very early in the boot sequence.
This commit is contained in:
parent
a4f9b116e3
commit
f80e454726
2 changed files with 33 additions and 7 deletions
|
|
@ -77,10 +77,9 @@ kobj_unregister_method(struct kobjop_desc *desc)
|
|||
{
|
||||
}
|
||||
|
||||
void
|
||||
kobj_class_compile(kobj_class_t cls)
|
||||
static void
|
||||
kobj_class_compile_common(kobj_class_t cls, kobj_ops_t ops)
|
||||
{
|
||||
kobj_ops_t ops;
|
||||
kobj_method_t *m;
|
||||
int i;
|
||||
|
||||
|
|
@ -97,14 +96,35 @@ kobj_class_compile(kobj_class_t cls)
|
|||
kobj_register_method(m->desc);
|
||||
|
||||
/*
|
||||
* Then allocate the compiled op table.
|
||||
* Then initialise the ops table.
|
||||
*/
|
||||
bzero(ops, sizeof(struct kobj_ops));
|
||||
ops->cls = cls;
|
||||
cls->ops = ops;
|
||||
}
|
||||
|
||||
void
|
||||
kobj_class_compile(kobj_class_t cls)
|
||||
{
|
||||
kobj_ops_t ops;
|
||||
|
||||
/*
|
||||
* Allocate space for the compiled ops table.
|
||||
*/
|
||||
ops = malloc(sizeof(struct kobj_ops), M_KOBJ, M_NOWAIT);
|
||||
if (!ops)
|
||||
panic("kobj_compile_methods: out of memory");
|
||||
bzero(ops, sizeof(struct kobj_ops));
|
||||
ops->cls = cls;
|
||||
cls->ops = ops;
|
||||
kobj_class_compile_common(cls, ops);
|
||||
}
|
||||
|
||||
void
|
||||
kobj_class_compile_static(kobj_class_t cls, kobj_ops_t ops)
|
||||
{
|
||||
/*
|
||||
* Increment refs to make sure that the ops table is not freed.
|
||||
*/
|
||||
cls->refs++;
|
||||
kobj_class_compile_common(cls, ops);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -104,6 +104,12 @@ struct kobj_class name ## _class = { \
|
|||
*/
|
||||
void kobj_class_compile(kobj_class_t cls);
|
||||
|
||||
/*
|
||||
* Compile the method table, with the caller providing the space for
|
||||
* the ops table.(for use before malloc is initialised).
|
||||
*/
|
||||
void kobj_class_compile_static(kobj_class_t cls, kobj_ops_t ops);
|
||||
|
||||
/*
|
||||
* Free the compiled method table in a class.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue