]> rtime.felk.cvut.cz Git - frescor/frsh.git/blobdiff - fres/resalloc/fra_generic.h
Implemented support for contract renegotiation
[frescor/frsh.git] / fres / resalloc / fra_generic.h
index cc05b9841bce1e8ba716c0022844a7a73f90ad92..4c58b198de557a32d59bbd1373af83a801dcea30 100644 (file)
@@ -82,6 +82,24 @@ GAVL_CUST_NODE_INT_DEC(fres_vreses_nolock /* cust_prefix */,
 extern struct fres_vreses fres_vreses;
 
 
+/** Registry of all threads in an application that are bound to a VRES. */
+struct fres_threads_vres {
+        fosa_mutex_t mutex;     /**< Mutex for manipulation with vreses tree. If all allocators are executed from one executor, locking can be avoided. */
+        gavl_cust_root_field_t threads; /**< Container of all virtual resources */
+};
+
+GAVL_CUST_NODE_INT_DEC(fres_threads_vres_nolock        /* cust_prefix */,
+                      struct fres_threads_vres /* cust_root_t */,
+                      struct fres_thread_vres  /* cust_item_t */,
+                      fosa_thread_id_t         /* cust_key_t */,
+                      threads                  /* cust_root_node */,
+                      node                     /* cust_item_node */,
+                      id                       /* cust_item_key */,
+                      fres_thread_vres_cmp     /* cust_cmp_fnc */)
+
+extern struct fres_threads_vres fres_threads_vres;
+
+
 /**
  * Structure describing FRES allocator. It is used as a parameter to
  * fra_register(), which registeres this allocator with contract
@@ -99,7 +117,7 @@ struct fres_allocator {
         * fres_vres::new.
         * 
         * @param vres VRES to create.
-        * @param priv
+        * @param priv User supplied pointer registered by fra_register()
         * 
         * @return Zero in case of success, nonzero error code on error.
         */
@@ -114,14 +132,26 @@ struct fres_allocator {
         * the return of this function.
         * 
         * @param vres VRES to change.
-        * @param priv
+        * @param priv User supplied pointer registered by fra_register()
         * 
         * @return Zero in case of success, nonzero error code on error.
         */
        int (*change_vres)(fres_vres_t *vres, void *priv);
+       /** 
+        * Cancel the CRES
+        * 
+        * @param cancel_vres VRES to cancel
+        * 
+        * @return Zero on succaess, non-zero error code on error.
+        */
+       int (*cancel_vres)(fres_vres_t *vres, void *priv);
        /*@}*/
+
        /** @name Full interface
-        * The allocator can influence the order of applying changes. */
+        * 
+        * Full interface provides a way for the allocator to
+        * influence the order of applying changes.
+        */
        /*@{*/
        /**
         * A more general (and more compilcated) allocator
@@ -136,7 +166,8 @@ struct fres_allocator {
         * fres_vres::perceived to @a fres_vres::new at some point in
         * time (depending on the kind of the change) as the
         * fres_vres::allocated parameters will be freed after the
-        * return of this function.
+        * return of this function. When the fres_vres::new contains
+        * no blocks, the VRES should be canceled.
         * 
         * @param vreses Array of pointers to VRESes.
         * @param length The number of elements in @a vreses.
@@ -147,14 +178,6 @@ struct fres_allocator {
        int (*apply_vres_changes)(fres_vres_t *vreses[], unsigned length, void *priv);
        /*@}*/
 
-       /** 
-        * 
-        * 
-        * @param cancel_vres 
-        * 
-        * @return 
-        */
-       int (*cancel_vres)(fres_vres_t *vres, void *priv);
        void *priv;             /**< Pointer to allocator's private data */
 
        /**
@@ -177,4 +200,9 @@ int fra_activate(frsh_resource_type_t res_type,
 
 fres_vres_t *fra_get_vres(fres_contract_id_t *id);
 
+int fra_insert_thread_vres(const fosa_thread_id_t *id, fres_vres_t *vres);
+int fra_delete_thread_vres(const fosa_thread_id_t *id);
+fres_thread_vres_t *fra_get_thread_vres(const fosa_thread_id_t *id);
+fres_vres_t *fra_get_vres_thread_vres(const fosa_thread_id_t *id);
+
 #endif