00001 #ifndef __QOS_QUEUE_H__ 00002 #define __QOS_QUEUE_H__ 00003 00004 #include <linux/aquosa/qos_memory.h> 00005 #include <linux/aquosa/qos_debug.h> 00006 #include <linux/aquosa/qos_types.h> 00007 00022 #define QOS_QUEUE_CHECK_OPS 00023 00025 typedef struct { 00026 qres_time_t *data; 00027 int num_elements; 00028 int max_num_elements; 00029 int ins_pos; 00030 int del_pos; 00031 } qos_queue_t; 00032 00045 static __inline qos_rv qos_queue_init(qos_queue_t *queue, int max_num_elems) { 00046 queue->data = (qres_time_t*) qos_malloc(sizeof(qres_time_t) * max_num_elems); 00047 if (queue->data == 0) 00048 return QOS_E_NO_MEMORY; 00049 queue->num_elements = 0; 00050 queue->max_num_elements = max_num_elems; 00051 queue->ins_pos = queue->del_pos = 0; 00052 return QOS_OK; 00053 } 00054 00055 static __inline void qos_queue_final(qos_queue_t *queue) { 00056 qos_free(queue->data); 00057 } 00058 00059 static __inline qos_rv qos_queue_insert(qos_queue_t *queue, qres_time_t elem) { 00060 #ifdef QOS_QUEUE_CHECK_OPS 00061 if ((queue == 0) || (queue->data == 0) || (queue->num_elements == queue->max_num_elements)) { 00062 return QOS_E_INCONSISTENT_STATE; 00063 } 00064 #endif 00065 queue->data[queue->ins_pos] = elem; 00066 queue->ins_pos = (queue->ins_pos + 1) % queue->max_num_elements; 00067 queue->num_elements++; 00068 return QOS_OK; 00069 } 00070 00077 static __inline qres_time_t qos_queue_extract(qos_queue_t *queue) { 00078 register qres_time_t elem; 00079 #ifdef QOS_QUEUE_CHECK_OPS 00080 if ((queue == 0) || (queue->data == 0) || (queue->num_elements == 0)) 00081 return qos_rv_int(QOS_E_INCONSISTENT_STATE); 00082 #endif 00083 elem = queue->data[queue->del_pos]; 00084 queue->del_pos = (queue->del_pos + 1) % queue->max_num_elements; 00085 queue->num_elements--; 00086 return elem; 00087 } 00088 00095 static __inline qres_time_t qos_queue_shift(qos_queue_t *queue, qres_time_t elem) { 00096 register qres_time_t ret_elem; 00097 #ifdef QOS_QUEUE_CHECK_OPS 00098 if ((queue == 0) || (queue->data == 0)) 00099 return qos_rv_int(QOS_E_INCONSISTENT_STATE); 00100 #endif 00101 ret_elem = queue->data[queue->del_pos]; 00102 queue->del_pos = (queue->del_pos + 1) % queue->max_num_elements; 00103 queue->data[queue->ins_pos] = elem; 00104 queue->ins_pos = (queue->ins_pos + 1) % queue->max_num_elements; 00105 return ret_elem; 00106 } 00107 00114 static __inline qres_time_t qos_queue_peek(qos_queue_t *queue) { 00115 #ifdef QOS_QUEUE_CHECK_OPS 00116 if ((queue == 0) || (queue->data == 0) || (queue->num_elements == 0)) 00117 return qos_rv_int(QOS_E_INCONSISTENT_STATE); 00118 #endif 00119 return queue->data[queue->del_pos]; 00120 } 00121 00135 static __inline qres_time_t qos_queue_get_at(qos_queue_t *queue, int pos) { 00136 #ifdef QOS_QUEUE_CHECK_OPS 00137 if ((queue == 0) || (queue->data == 0) || (pos >= queue->num_elements)) 00138 return qos_rv_int(QOS_E_INCONSISTENT_STATE); 00139 #endif 00140 return queue->data[(queue->del_pos + pos) % queue->max_num_elements]; 00141 } 00142 00151 static __inline qos_rv qos_queue_set_at(qos_queue_t *queue, int pos, qres_time_t elem) { 00152 #ifdef QOS_QUEUE_CHECK_OPS 00153 if ((queue == 0) || (queue->data == 0) || (pos >= queue->num_elements)) 00154 return QOS_E_INCONSISTENT_STATE; 00155 #endif 00156 queue->data[(queue->del_pos + pos) % queue->max_num_elements] = elem; 00157 return QOS_OK; 00158 } 00159 00166 static __inline int qos_queue_get_num_elements(qos_queue_t *queue) { 00167 #ifdef QOS_QUEUE_CHECK_OPS 00168 if ((queue == 0) || (queue->data == 0)) 00169 return qos_rv_int(QOS_E_INCONSISTENT_STATE); 00170 #endif 00171 return queue->num_elements; 00172 } 00173 00180 static __inline int qos_queue_get_max_num_elements(qos_queue_t *queue) { 00181 #ifdef QOS_QUEUE_CHECK_OPS 00182 if ((queue == 0) || (queue->data == 0)) 00183 return qos_rv_int(QOS_E_INCONSISTENT_STATE); 00184 #endif 00185 return queue->max_num_elements; 00186 } 00187 00188 #endif