return ret;
}
+/**
+ * Creates binding from a thread to VRES; if binding already exists,
+ * it is updated.
+ *
+ * @param id Thread ID bounded to @a vres.
+ * @param vres VRES
+ *
+ * @return Positive number when a new binding was inserted, zero when
+ * binding was changed and -1 on error.
+ */
int fra_insert_thread_vres(const fosa_thread_id_t *id, fres_vres_t *vres)
{
struct fres_thread_vres *th;
return fres_threads_vres_insert(th);
}
+/**
+ * Deletes thread to VRES binding.
+ *
+ * @param id Thread ID to unbind.
+ *
+ * @return Zero on success, -1 on when the thread was not bound.
+ */
int fra_delete_thread_vres(const fosa_thread_id_t *id)
{
struct fres_thread_vres *th;
+ int ret = 0;
- th = fres_threads_vres_find(id);
- if (!th) return -1;
-
- fres_thread_vres_destroy(th);
-
- return 0;
+ fosa_mutex_lock(&fres_threads_vres.mutex);
+ th = fres_threads_vres_nolock_find(&fres_threads_vres, id);
+ if (th) {
+ fres_threads_vres_nolock_delete(&fres_threads_vres, th);
+ } else {
+ ret = -1;
+ }
+ fosa_mutex_unlock(&fres_threads_vres.mutex);
+ if (ret == 0) {
+ fres_thread_vres_destroy(th);
+ }
+ return ret;
}
+/**
+ * Returns VRES bounded to a thread.
+ *
+ * @param id Thread ID
+ *
+ * @return VRES on NULL in the thread is not bound.
+ *
+ * @todo Is this function needed if we have
+ * fra_get_vres_thread_vres()?
+ */
fres_thread_vres_t *fra_get_thread_vres(const fosa_thread_id_t *id)
{
return fres_threads_vres_find(id);
}
+/**
+ * Returns VRES bounded to a thread.
+ *
+ * @param id Thread ID
+ *
+ * @return VRES on NULL in the thread is not bound.
+ */
fres_vres_t *fra_get_vres_thread_vres(const fosa_thread_id_t *id)
{
fres_thread_vres_t *th_vres;
(const frsh_vres_id_t vres,
frsh_contract_t *contract)
{
- if (!vres) return EINVAL;
+ if (!vres) return FRSH_ERR_BAD_ARGUMENT;
+ /* TODO: Reference counting */
*contract = vres->perceived;
return 0;
{
fres_block_basic *basic;
- if (!vres) return EINVAL;
+ if (!vres) return FRSH_ERR_BAD_ARGUMENT;
+ /* TODO: Reference counting */
basic = fres_contract_get_basic(vres->perceived);
+ if (!basic) return FRSH_ERR_NOT_INITIALIZED;
+
if (budget)
*budget = basic->budget;
if (period)