]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
Updates to the previous commit: added documentation and fixed bugs
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 1 Mar 2009 18:10:51 +0000 (19:10 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 1 Mar 2009 18:10:51 +0000 (19:10 +0100)
fres/resalloc/fra_generic.c
fres/resalloc/fres_vres.h
frsh_api/frsh_vres.c

index 234aefac05e5d020ebbe67251340cd17b9061caf..876363000ff5f8c8735709e2570c96ae73123291 100644 (file)
@@ -334,6 +334,16 @@ struct fres_thread_vres *fres_threads_vres_find(const fosa_thread_id_t *id)
        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;
@@ -353,23 +363,54 @@ int fra_insert_thread_vres(const fosa_thread_id_t *id, fres_vres_t *vres)
        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;
index 9f280913cbaa6377bfc07b771699dfd731f7caaf..1f64fb0d7f08a8bf0496c2540c8ca34efd6aa6ae 100644 (file)
@@ -105,7 +105,9 @@ typedef struct fres_vres {
 fres_vres_t *fres_vres_new(fres_contract_id_t *id);
 void fres_vres_destroy(fres_vres_t *vres);
 
-
+/**
+ * Representation of thread to VRES binding.
+ */
 typedef struct fres_thread_vres {
        fosa_thread_id_t id;
        fres_vres_t *vres;
index 81e0cbc673ed03ffabb0fa92007268762d58cb83..c1184a0ec4b2cebb687b9eeb11584fd95061755a 100644 (file)
@@ -70,8 +70,9 @@ int frsh_vres_get_contract
   (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;
@@ -108,10 +109,13 @@ int frsh_vres_get_budget_and_period
 {
        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)