static struct instance*
learner_get_instance(struct learner* l, iid_t iids)
{
struct instance * h = NULL;
HASH_FIND_IID( l->instances, &iids, h);
return h;
}
static struct instance*
learner_get_instance_or_create(struct learner* l, iid_t iids)
{
struct instance* inst = learner_get_instance(l, iids);
if (inst == NULL) {
printk(KERN_WARNING "Instance is null, creating new one");
inst = instance_new(l->acceptors); // Creates and allocates a new instance with iid = 0
HASH_ADD_IID(l->instances, iid, inst); // does not work! why?
struct instance * h = NULL;
HASH_FIND_IID( l->instances, &iids, h);
if(h == NULL){
printk(KERN_ERR "Instance is null, YOU HAVE A PROBLEM"); // it always goes here
}
}else{
printk(KERN_WARNING "Instance is NOT null");
}
return inst;
}
If I call 3 times the learner_get_instance_or_create() with the same learner and same iid, it prints 3 times: