forb_executor_t *executor,
struct fres_allocator *allocator);
-void fra_registry_init(forb_orb orb,
- fres_contract_broker fcb,
- forb_executor_t *executor);
+int fra_registry_init(forb_orb orb,
+ fres_contract_broker fcb,
+ forb_executor_t *executor);
int fra_register(struct fres_allocator *allocator);
int fra_activate(frsh_resource_type_t res_type,
frsh_resource_id_t res_id);
fres_contract_broker fcb;
forb_executor_t *executor;
+ pthread_mutex_t mutex;
gavl_cust_root_field_t allocators;
} registry;
* @param orb
* @param fcb Contract broker object reference
* @param executor Executor for all allocator objects
+ *
+ * @return Zero on success, error number on error.
*/
-void fra_registry_init(forb_orb orb,
+int fra_registry_init(forb_orb orb,
fres_contract_broker fcb,
forb_executor_t *executor)
{
+ int rv;
registry.orb = orb;
registry.fcb = fcb;
registry.executor = executor;
+ pthread_mutexattr_t ma;
+ rv = pthread_mutexattr_init(&ma);
+ rv = pthread_mutexattr_setprotocol(&ma, PTHREAD_PRIO_INHERIT);
+ if (rv) return rv;
+ pthread_mutex_init(®istry.mutex, &ma);
fra_registry_init_root_field(®istry);
+ return 0;
}
/**
{
struct registered_allocator *ra;
int ret;
-
+ pthread_mutex_lock(®istry.mutex);
ra = fra_registry_find(®istry, &allocator);
if (!ra && free_allocator_idx < FRA_MAX_ALLOCATORS) {
ra = &allocators[free_allocator_idx];
} else {
ret = -1;
}
+ pthread_mutex_unlock(®istry.mutex);
return ret;
}
key.res_type = res_type;
key.res_id = res_id;
+ pthread_mutex_lock(®istry.mutex);
ra = fra_registry_find(®istry, &pkey);
if (ra) {
if (ra->registered_with_fcb) {
} else {
ret = FRES_ERR_NO_RESOURCE_ALLOCATOR;
}
+ pthread_mutex_unlock(®istry.mutex);
return ret;
}
pkey->res_type = res_type;
pkey->res_id = res_id;
-
+
+ pthread_mutex_lock(®istry.mutex);
ra = fra_registry_find(®istry, &pkey);
+ pthread_mutex_unlock(®istry.mutex);
if (ra) {
return ra->allocator;
} else {
ret = forb_executor_init(&frsh_forb_global.alloc_executor);
if (ret) goto err;
- fra_registry_init(frsh_forb_global.orb, frsh_forb_global.fcb,
- &frsh_forb_global.alloc_executor);
+ ret = fra_registry_init(frsh_forb_global.orb, frsh_forb_global.fcb,
+ &frsh_forb_global.alloc_executor);
+ if (ret) goto err;
#ifdef CONFIG_AQUOSA
ret = aqcpu_fra_init();