00001
00008 #ifndef __RRES_READY_QUEUE_EHEAP_H__
00009 #define __RRES_READY_QUEUE_EHEAP_H__
00010
00011 #include "rres_config.h"
00012 #include "kal_timer.h"
00013 #include "qos_types.h"
00014 #include "qos_func.h"
00015
00016 #define kal_eheap_key_lt kal_time_lt
00017 #include "kal_eheap.h"
00018
00019 kal_define_eheap(kal_time_t, server_p);
00020
00025 typedef kal_eheap_iterator_t(kal_time_t, server_p) rq_placeholder_t;
00026
00027 #include "rres_server.h"
00028
00029 #define RRES_MAX_NUM_SERVERS_BITS 12
00030 #define RRES_MAX_NUM_SERVERS (1 << RRES_MAX_NUM_SERVERS_BITS)
00031
00033 #define rq_placeholder_init(p_it) kal_eheap_iterator_init(p_it)
00034
00036 extern kal_eheap_t(kal_time_t, server_p) eheap;
00037
00039 static inline server_t *get_highest_priority_server(void) {
00040 server_t * srv = NULL;
00041 kal_time_t dl;
00042 if (kal_eheap_get_min(&eheap, &dl, &srv) == QOS_E_EMPTY)
00043 return NULL;
00044 return srv;
00045 }
00046
00051 #define for_each_ready_server(srv, p_it) \
00052 for ( \
00053 kal_eheap_begin(&eheap, (p_it)); \
00054 kal_eheap_next(&eheap, (p_it), NULL, &(srv)) == QOS_OK); \
00055 \
00056 )
00057
00059 static inline int ready_queue_empty(void) {
00060 return kal_eheap_size(&eheap) == 0;
00061 }
00062
00064 static inline int srv_alone(server_t *srv) {
00065 kal_time_t dl;
00066 server_t *top_srv;
00067 qos_chk_ok(kal_eheap_get_min(&eheap, &dl, &top_srv));
00068 return (srv == top_srv) && (kal_eheap_size(&eheap) == 1);
00069 }
00070
00072 static inline int in_ready_queue(server_t *srv) {
00073 return kal_eheap_iterator_valid(&srv->rq_ph);
00074 }
00075
00076 static void ready_queue_remove(server_t *srv) __attribute__((unused));
00077
00079 static qos_func_define(void, ready_queue_remove, server_t *srv) {
00080 qos_log_debug("(s:%d): Removing from ready queue", srv->id);
00081
00082 qos_chk_do_msg(in_ready_queue(srv), return, "Attempt to remove (s:%d) from ready queue while it is not in rq. IGNORED", srv->id);
00083
00084 qos_chk_ok(kal_eheap_del(&eheap, &srv->rq_ph));
00085 qos_chk(! kal_eheap_iterator_valid(&srv->rq_ph));
00086 qos_chk(! in_ready_queue(srv));
00087 }
00088
00089 static inline qos_rv rres_edf_init(void) {
00090 qos_chk_ok_ret(kal_eheap_init(&eheap, RRES_MAX_NUM_SERVERS_BITS));
00091 return QOS_OK;
00092 }
00093
00094 static inline void rres_edf_cleanup(void) {
00095 kal_eheap_cleanup(&eheap);
00096 }
00097
00098 static qos_rv ready_queue_add(server_t *srv) __attribute__((unused));
00099
00101 static qos_func_define(qos_rv, ready_queue_add, server_t *srv) {
00102 qos_log_debug("(s:%d): Adding to ready queue", srv->id);
00103
00104 qos_chk_do_msg(! in_ready_queue(srv), return QOS_E_INTERNAL_ERROR, "(s:%d) already in ready queue", srv->id);
00105 qos_chk_ok_ret(kal_eheap_add(&eheap, srv->deadline, srv, &srv->rq_ph));
00106 return QOS_OK;
00107 }
00108
00109 #endif
00110