void testLL() { int i; int storeUs[6] = {5,10,15,7,2,2}; struct list_head *head = NULL; head=create_new_ll(); printf("Is the list empty? %s\n",is_list_empty(head) ? "Yes" : "No"); for(i=0; i<6; i++) { add_new_node_ll(head,storeUs[i]); } printf("The number 2 occurs: %d time(s)\n",find_elements_ll(head,2)); print_out_ll(head); remove_node_ll(head,5); print_out_ll(head); remove_node_ll(head,7); print_out_ll(head); printf("Total Elements %d\n",total_elements_ll(head)); remove_node_ll(head,2); print_out_ll(head); printf("Total Elements %d\n",total_elements_ll(head)); printf("The number 2 occurs: %d time(s)\n",find_elements_ll(head,2)); printf("Does the element 10 exist in the list: %s\n", \ does_element_exist_ll(head,10) ? "Yes!" : "No"); printf("Does the element 100 exist in the list: %s\n", \ does_element_exist_ll(head,100) ? "Yes!" : "No"); printf("Is the list empty? %s\n",is_list_empty(head) ? "Yes" : "No"); free_ll(head); }
void sem_yield(sem_t *sp) { sem *sema = (sem*)sp; ucontext_t *curr = NULL, *next = NULL; tcb *running = NULL, *tcbnext = NULL; struct list_elem *e = NULL; int queueflag = -1; running = list_entry(list_begin(&q_running), thread_p, elem)->p; if (is_list_empty(&q_ready_H) && is_list_empty(&q_ready_L)) { printf("Q_ready_H and L are both empty!\n"); return; } thread_p *tmp_p = (thread_p *)calloc(1, sizeof(thread_p)); tmp_p->p = running; list_insert_tail(&sema->waiters, &tmp_p->elem); curr = &running->context; e = list_begin(&q_running); tmp_p = list_entry(e, thread_p, elem); list_remove(e); free(tmp_p); if (!is_list_empty(&q_ready_H)) { tcbnext = list_entry(list_begin(&q_ready_H), thread_p, elem)->p; queueflag = 0; } else if (!is_list_empty(&q_ready_L)) { tcbnext = list_entry(list_begin(&q_ready_L), thread_p, elem)->p; queueflag = 1; } tmp_p = (thread_p *)calloc(1, sizeof(thread_p)); tmp_p->p = tcbnext; list_insert_head(&q_running, &tmp_p->elem); next = &tcbnext->context; if (queueflag == 0) e = list_begin(&q_ready_H); else if (queueflag == 1) e = list_begin(&q_ready_L); tmp_p = list_entry(e, thread_p, elem); list_remove(e); free(tmp_p); assert(curr); assert(next); if (swapcontext(curr, next) == -1) { printf("Swapcontext error: %s\n", strerror(errno)); } }
uint state_remove( uint state ) { STATE_DIS *tmp = state_obj_copy; while(!is_list_empty(&(tmp->node))) { if ( tmp->state == state ) { list_delete(&(tmp->node)); tmp->state = 10000; tmp->func = NULL; tmp->name = ""; return 0; } tmp = (STATE_DIS *)(&(tmp->node))->next; } if ( tmp->state == state ) { list_delete(&(tmp->node)); tmp->state = 10000; tmp->func = NULL; tmp->name = ""; return 0; } printf("State no fund\n"); }
uint state_tran( uint state ) { STATE_DIS *tmp = state_obj_copy; while( !is_list_empty(&(tmp->node)) ) { if ( tmp->state == state ) { fsm_obj->func = tmp->func; fsm_obj->name = tmp->name; fsm_obj->state = state; return 0; } tmp = (STATE_DIS *)(&(tmp->node))->next; } if ( tmp->state == state ) { fsm_obj->name = tmp->name; fsm_obj->state = state; fsm_obj->func = tmp->func; return 0; } state_default(fsm_default.state, fsm_default.func, fsm_default.name); printf("state is no found, and fsm will transfer to default, It is name: %s\n", fsm_obj->name); }
vod_status_t write_buffer_queue_flush(write_buffer_queue_t* queue) { buffer_header_t* cur_buffer; vod_status_t rc; while (!is_list_empty(&queue->buffers)) { cur_buffer = (buffer_header_t*)queue->buffers.next; remove_entry_list(&cur_buffer->link); if (cur_buffer->cur_pos <= cur_buffer->start_pos) { continue; } rc = queue->write_callback(queue->write_context, cur_buffer->start_pos, cur_buffer->cur_pos - cur_buffer->start_pos); if (rc != VOD_OK) { vod_log_debug1(VOD_LOG_DEBUG_LEVEL, queue->request_context->log, 0, "write_buffer_queue_flush: write_callback failed %i", rc); return rc; } // no reason to reuse the buffer here } return VOD_OK; }
/* Rather than use stdlib qsort() (quicksort), implement merge sort based upon wikipedia pseudo code entry. https://en.wikipedia.org/wiki/Merge_sort General idea Recursively divide the list into smaller sublists until the sublists are trivially sorted and then merge the sublists. */ list_t *merge_sort(list_t *pList) { list_t *pListLeft; list_t *pListRight; int i=0; node_t *pNode; // Base case. A zero or one element list is sorted by definition if (is_list_empty(pList)) { return pList; } if (is_list_singleton(pList)) { return pList; } // The wikipedia entry assumes the number of items in the list // is maintained and uses a for loop. It still requires // the list to be iterated. I'm simply using a while not // empty as I build the sublists. // // Create the two sublists // // int (*pfCompare)(node_t,node_t); pListLeft = init_list(pList->pfCompare); if (NULL == pListLeft) { printf("Failed to init left sublist.\n"); } pListRight = init_list(pList->pfCompare); if (NULL == pListRight) { printf("Failed to init right sublist.\n"); } // alternatively add each item of the list to the sublists. pNode = pList->pFirst; while ( NULL != pNode) { if (i % 2) { if ( append(pListLeft, pNode->pData) ) { printf("Failed to append number to left list.\n"); } } else { if ( append(pListRight, pNode->pData) ) { printf("Failed to append number to right list.\n"); } } pNode = pNode->pNext; i++; } // Recursively sort both sublists pListLeft = merge_sort(pListLeft); pListRight = merge_sort(pListRight); return ( merge(pListLeft,pListRight) ); }
void list_init(struct list *list) { assert(list); list->head.prev = NULL; list->head.next = &list->tail; list->tail.prev = &list->head; list->tail.next = NULL; assert(is_list_empty(list)); }
/* Note we can't trim distinguished_csn (even during regular trimming) because in some cases we would not be able to figure out whether a value was distinguished or not at the time of deletion. Example 1: Example2: csn order operation csn order operation 1 1 make V distinguished 1 1 make V distinguished 3 3 delete V 2 2 make V non distinguished 4 2 make V non-distinguished 3 4 delete V 4 3 make V non distinguished (on another server) if the csns up to 2 were triimed, when delete operation is received, the state is exactly the same in both examples but in example one delete should not go through while in example 2 it should */ int value_distinguished_at_delete (Value_State *value, int attr_delete_csn) { if (value->distinguished_csn >= 0 && (is_list_empty (value->non_distinguished_csns) || min_list_val (value->non_distinguished_csns) > max_val (value->delete_csn, attr_delete_csn))) return 1; else return 0; }
void calculate_time_slice(RAW_U8 task_prio) { RAW_TASK_OBJ *task_ptr; LIST *head; RAW_SR_ALLOC(); head = &raw_ready_queue.task_ready_list[task_prio]; RAW_CRITICAL_ENTER(); /*if ready list is empty then just return because nothing is to be caculated*/ if (is_list_empty(head)) { RAW_CRITICAL_EXIT(); return; } /*Always look at the first task on the ready list*/ task_ptr = list_entry(head->next, RAW_TASK_OBJ, task_list); /*SCHED_FIFO does not has timeslice, just return*/ if (task_ptr->sched_way == SCHED_FIFO) { RAW_CRITICAL_EXIT(); return; } /*there is only one task on this ready list, so do not need to caculate time slice*/ /*idle task must satisfy this condition*/ if (head->next->next == head) { RAW_CRITICAL_EXIT(); return; } if (task_ptr->time_slice) { task_ptr->time_slice--; } /*if current active task has time_slice, just return*/ if (task_ptr->time_slice) { RAW_CRITICAL_EXIT(); return; } /*Move current active task to the end of ready list for the same priority*/ move_to_ready_list_end(&raw_ready_queue, task_ptr); /*restore the task time slice*/ task_ptr->time_slice = task_ptr->time_total; RAW_CRITICAL_EXIT(); }
RAW_OS_ERROR raw_semaphore_set(RAW_SEMAPHORE *semaphore_ptr, RAW_U32 sem_count) { LIST *block_list_head; RAW_SR_ALLOC(); block_list_head = &semaphore_ptr->common_block_obj.block_list; #if (RAW_SEMA_FUNCTION_CHECK > 0) if (semaphore_ptr == 0) { return RAW_NULL_OBJECT; } if (raw_int_nesting) { return RAW_NOT_CALLED_BY_ISR; } #endif RAW_CRITICAL_ENTER(); if (semaphore_ptr->common_block_obj.object_type != RAW_SEM_OBJ_TYPE) { RAW_CRITICAL_EXIT(); return RAW_ERROR_OBJECT_TYPE; } if (semaphore_ptr->count) { semaphore_ptr->count = sem_count; } else { if (is_list_empty(block_list_head)) { semaphore_ptr->count = sem_count; } else { RAW_CRITICAL_EXIT(); return RAW_SEMAPHORE_TASK_WAITING; } } RAW_CRITICAL_EXIT(); return RAW_SUCCESS; }
/* * Release the lock and delete it from list, and then adjust the * priority of task. * Set the highest priority between listed below: * (A) The highest priority in all mutexes in which 'tcb' task locks. * (B) The base priority of 'tcb' task. */ static void release_mutex(RAW_TASK_OBJ *tcb, RAW_MUTEX *relmtxcb) { RAW_MUTEX *mtxcb, **prev; RAW_U8 newpri, pri; RAW_TASK_OBJ *first_block_task; LIST *block_list_head; /* (B) The base priority of task */ newpri = tcb->bpriority; /* (A) The highest priority in mutex which is locked */ pri = newpri; prev = &tcb->mtxlist; while ((mtxcb = *prev) != 0) { if (mtxcb == relmtxcb) { /* Delete self from list and tcb->mtxlist point to next*/ *prev = mtxcb->mtxlist; continue; } switch (mtxcb->policy) { case RAW_MUTEX_CEILING_POLICY: pri = mtxcb->ceiling_prio; break; case RAW_MUTEX_INHERIT_POLICY: block_list_head = &mtxcb->common_block_obj.block_list; if (!is_list_empty(block_list_head)) { first_block_task = raw_list_entry(block_list_head->next, RAW_TASK_OBJ, task_list); pri = first_block_task->priority; } break; default: break; } if (newpri > pri) { newpri = pri; } prev = &mtxcb->mtxlist; } if ( newpri != tcb->priority ) { /* Change priority of lock get task */ change_internal_task_priority(tcb, newpri); TRACE_MUTEX_RELEASE(raw_task_active, tcb, newpri); } }
/* * Delete from free queue */ static void removeFreeQue( LIST *fq ) { if ( !is_list_empty(fq + 1) ) { LIST *nq = (fq + 1)->next; list_delete(fq + 1); list_insert(nq,nq + 1); list_delete(nq); list_insert(fq,nq); } list_delete(fq); }
//Before running run: "ulimit -s unlimited" int main(int argc, char* argv[]) { parse_opts(argc, argv); srand(time(NULL)); int tick = 0; struct list **chunks_lifetime = (struct list **)malloc(sizeof(struct list*) * max_ticks);// The stack memory has somee restrictions for (int i = 0; i < max_ticks; i++) { chunks_lifetime[i] = create_list(); } struct memory *mem = create_memory(memory_size); printf("Starting\n"); while (1) { if (need_trace) { printf("Tick %d:\n", tick); } while (!is_list_empty(chunks_lifetime[tick])) { int8_t *ptr = get_and_remove(chunks_lifetime[tick]); if (need_trace) { printf(" Removing chunk with size %d bytes\n", get_chunk_size(ptr)); } free_chunk(mem, ptr); } SIZE_TYPE chunk_size = rand_range(min_chunk_size, max_chunk_size) / 4 * 4; int8_t *ptr = allocate_chunk(mem, chunk_size); if (ptr == NULL) { printf("Oops. We have no free memory to allocate %d bytes on tick %d. Exiting\n", chunk_size, tick); break; } int chunk_lifetime = rand_range(min_lifetime, max_lifetime); if (tick + chunk_lifetime >= max_ticks) { printf("The maximum number of ticks(%d) reached. Exiting\n", max_ticks); break; } add_to_list(chunks_lifetime[tick + chunk_lifetime], ptr); if (need_trace){ printf(" Allocating chunk with size %d bytes. Its lifetime is %d ticks\n", chunk_size, chunk_lifetime); } tick++; } for (int i = 0; i < max_ticks; i++) { free_list(chunks_lifetime[i]); } free_memory(mem); free(chunks_lifetime); return 0; }
void sem_signal(sem_t *sp) { while(sem_try_lock(sp) != 0); int yield = 0; ((sem*)sp)->value++; if ( ((sem*)sp)->value <= 0 ) { assert(!is_list_empty(&((sem*)sp)->waiters)); sem_unblock(sp); yield = 1; } sem_unlock(sp); if (yield == 1) t_yield(); }
/* * Frees all allocated timers, and timer queues */ void timer_free_all(void) { while (!is_list_empty(passive_timers)) { Any_Type a = list_pop(passive_timers); free(a.vp); } list_free(passive_timers); passive_timers = NULL; while (!is_list_empty(active_timers)) { Any_Type a = list_pop(active_timers); free(a.vp); } list_free(active_timers); active_timers = NULL; while (!is_list_empty(persistent_timers)) { Any_Type a = list_pop(persistent_timers); free(a.vp); } list_free(persistent_timers); persistent_timers = NULL; }
RAW_U16 raw_event_delete(RAW_EVENT *event_ptr) { LIST *block_list_head; RAW_SR_ALLOC(); #if (RAW_EVENT_FUNCTION_CHECK > 0) if (event_ptr == 0) { return RAW_NULL_OBJECT; } if (raw_int_nesting) { return RAW_NOT_CALLED_BY_ISR; } #endif RAW_CRITICAL_ENTER(); if (event_ptr->common_block_obj.object_type != RAW_EVENT_OBJ_TYPE) { RAW_CRITICAL_EXIT(); return RAW_ERROR_OBJECT_TYPE; } block_list_head = &event_ptr->common_block_obj.block_list; event_ptr->common_block_obj.object_type = 0u; /*All task blocked on this queue is waken up until list is empty*/ while (!is_list_empty(block_list_head)) { delete_pend_obj(list_entry(block_list_head->next, RAW_TASK_OBJ, task_list)); } event_ptr->flags = 0u; RAW_CRITICAL_EXIT(); TRACE_EVENT_DELETE(raw_task_active, event_ptr); raw_sched(); return RAW_SUCCESS; }
void sem_destroy(sem_t **sp) { struct list_elem *e = NULL; sem *sema = (sem*)*sp; tcb *tcbtmp = NULL; struct list *list = &sema->waiters; while (!is_list_empty(list)) { e = list_begin(list); tcbtmp = list_entry(e, tcb, elem); list_remove(e); free(tcbtmp->context.uc_stack.ss_sp); free(tcbtmp); } sp = NULL; }
static struct cmd_obj *_dequeue_cmd(struct __queue *queue) { unsigned long irqL; struct cmd_obj *obj; spin_lock_irqsave(&(queue->lock), irqL); if (is_list_empty(&(queue->queue))) obj = NULL; else { obj = LIST_CONTAINOR(get_next(&(queue->queue)), struct cmd_obj, list); list_delete(&obj->list); } spin_unlock_irqrestore(&(queue->lock), irqL); return obj; }
RAW_U16 raw_queue_delete(RAW_QUEUE *p_q) { LIST *block_list_head; RAW_SR_ALLOC(); #if (RAW_QUEUE_FUNCTION_CHECK > 0) if (p_q == 0) { return RAW_NULL_OBJECT; } if (raw_int_nesting) { return RAW_NOT_CALLED_BY_ISR; } #endif RAW_CRITICAL_ENTER(); if (p_q->common_block_obj.object_type != RAW_QUEUE_OBJ_TYPE) { RAW_CRITICAL_EXIT(); return RAW_ERROR_OBJECT_TYPE; } block_list_head = &p_q->common_block_obj.block_list; p_q->common_block_obj.object_type = 0u; /*All task blocked on this queue is waken up*/ while (!is_list_empty(block_list_head)) { delete_pend_obj(list_entry(block_list_head->next, RAW_TASK_OBJ, task_list)); } RAW_CRITICAL_EXIT(); TRACE_QUEUE_DELETE(raw_task_active, p_q); raw_sched(); return RAW_SUCCESS; }
static struct slab_header *get_new_slab_header(void) { struct slab_header_table *table = &pslab->table; struct list_head *free = &table->free_header; struct slab_header *header = NULL; struct page *pg = table->table_page_current; unsigned long base; /* * find if there are headers in free list freed * by other slab */ if (!is_list_empty(free)) { header = list_first_entry(free, struct slab_header, header_list); list_del(&header->header_list); return header; }
struct cmd_obj *_dequeue_cmd(_queue *queue) { struct cmd_obj *obj; _func_enter_; _spinlock(&(queue->lock)); if (is_list_empty(&(queue->queue))) obj = NULL; else { obj = LIST_CONTAINOR(get_next(&(queue->queue)), struct cmd_obj, list); list_delete(&obj->list); } _spinunlock(&(queue->lock)); _func_exit_; return obj; }
RAW_OS_ERROR raw_semaphore_delete(RAW_SEMAPHORE *semaphore_ptr) { LIST *block_list_head; RAW_SR_ALLOC(); #if (RAW_SEMA_FUNCTION_CHECK > 0) if (semaphore_ptr == 0) { return RAW_NULL_OBJECT; } if (raw_int_nesting) { return RAW_NOT_CALLED_BY_ISR; } #endif RAW_CRITICAL_ENTER(); if (semaphore_ptr->common_block_obj.object_type != RAW_SEM_OBJ_TYPE) { RAW_CRITICAL_EXIT(); return RAW_ERROR_OBJECT_TYPE; } block_list_head = &semaphore_ptr->common_block_obj.block_list; semaphore_ptr->common_block_obj.object_type = RAW_OBJ_TYPE_NONE; /*All task blocked on this queue is waken up*/ while (!is_list_empty(block_list_head)) { delete_pend_obj(raw_list_entry(block_list_head->next, RAW_TASK_OBJ, task_list)); } RAW_CRITICAL_EXIT(); TRACE_SEMAPHORE_DELETE(raw_task_active, semaphore_ptr); raw_sched(); return RAW_SUCCESS; }
vod_status_t write_buffer_queue_send(write_buffer_queue_t* queue, off_t max_offset) { buffer_header_t* cur_buffer; vod_status_t rc; while (!is_list_empty(&queue->buffers)) { cur_buffer = (buffer_header_t*)queue->buffers.next; if (cur_buffer->cur_pos <= cur_buffer->start_pos) { break; } if (cur_buffer->end_offset > max_offset) { break; } remove_entry_list(&cur_buffer->link); if (cur_buffer == queue->cur_write_buffer) { queue->cur_write_buffer = NULL; } rc = queue->write_callback(queue->write_context, cur_buffer->start_pos, cur_buffer->cur_pos - cur_buffer->start_pos); if (rc != VOD_OK) { vod_log_debug1(VOD_LOG_DEBUG_LEVEL, queue->request_context->log, 0, "write_buffer_queue_send: write_callback failed %i", rc); return rc; } if (!queue->reuse_buffers) { cur_buffer->start_pos = NULL; } cur_buffer->cur_pos = cur_buffer->start_pos; insert_tail_list(&queue->buffers, &cur_buffer->link); } return VOD_OK; }
RAW_OS_ERROR raw_mutex_delete(RAW_MUTEX *mutex_ptr) { LIST *block_list_head; RAW_SR_ALLOC(); #if (RAW_MUTEX_FUNCTION_CHECK > 0) if (mutex_ptr == 0) { return RAW_NULL_OBJECT; } #endif RAW_CRITICAL_ENTER(); if (mutex_ptr->common_block_obj.object_type != RAW_MUTEX_OBJ_TYPE) { RAW_CRITICAL_EXIT(); return RAW_ERROR_OBJECT_TYPE; } block_list_head = &mutex_ptr->common_block_obj.block_list; mutex_ptr->common_block_obj.object_type = RAW_OBJ_TYPE_NONE; if (mutex_ptr->mtxtsk) { release_mutex(mutex_ptr->mtxtsk, mutex_ptr); } /*All task blocked on this mutex is waken up*/ while (!is_list_empty(block_list_head)) { delete_pend_obj(raw_list_entry(block_list_head->next, RAW_TASK_OBJ, task_list)); } RAW_CRITICAL_EXIT(); TRACE_MUTEX_DELETE(raw_task_active, mutex_ptr); raw_sched(); return RAW_SUCCESS; }
void raw_task_free_mutex(RAW_TASK_OBJ *tcb) { RAW_MUTEX *mtxcb, *next_mtxcb; RAW_TASK_OBJ *next_tcb; LIST *block_list_head; next_mtxcb = tcb->mtxlist; while ((mtxcb = next_mtxcb) != 0) { next_mtxcb = mtxcb->mtxlist; block_list_head = &mtxcb->common_block_obj.block_list; if (!is_list_empty(block_list_head)) { next_tcb = raw_list_entry(block_list_head->next, RAW_TASK_OBJ, task_list); /* Wake wait task */ raw_wake_object(next_tcb); /* Change mutex get task */ mtxcb->mtxtsk = next_tcb; mtxcb->mtxlist = next_tcb->mtxlist; next_tcb->mtxlist = mtxcb; if (mtxcb->policy == RAW_MUTEX_CEILING_POLICY) { if (next_tcb->priority > mtxcb->ceiling_prio) { /* Raise the priority for the task that got lock to the highest priority limit */ change_internal_task_priority(next_tcb, mtxcb->ceiling_prio); } } } else { /* No wait task */ mtxcb->mtxtsk = 0; } } }
/* Must use critical section to protect alloc_ioreq and free_ioreq, due to the irq level possibilities of the callers. This is to guarantee the atomic context of the service. */ struct io_req *alloc_ioreq(struct io_queue *pio_q) { _irqL irqL; _list *phead = &pio_q->free_ioreqs; struct io_req *preq = NULL; _func_enter_; _enter_critical(&pio_q->lock, &irqL); if (is_list_empty(phead) == _FALSE) { preq = LIST_CONTAINOR(get_next(phead), struct io_req, list); list_delete(&preq->list); //_memset((u8 *)preq, 0, sizeof(struct io_req));//!!! _init_listhead(&preq->list); _init_sema(&preq->sema, 0); }
/* 0 struct list_head free_txirp_mgt; 1 struct list_head free_txirp_small; 2 struct list_head free_txirp_medium; 3 struct list_head free_txirp_large; */ struct txirp *alloc_txirp(_adapter *padapter) { _irqL flags; struct txirp *irp = NULL; struct mib_info *pmibinfo = &(padapter->_sys_mib); _list *head = &(pmibinfo->free_txirp_mgt); _enter_critical(&(pmibinfo->free_txirp_mgt_lock), &flags); if(is_list_empty(head)==_TRUE) goto ret; irp = LIST_CONTAINOR(head->next, struct txirp, list); list_delete(head->next); memset( (u8*)irp->txbuf_phyaddr, 0, TXMGTBUF_SZ); irp->tx_len = 0; ret: _exit_critical(&(pmibinfo->free_txirp_mgt_lock), &flags); return irp; }
/* * Schedules a timer into the active_timer list. Usually the timer is * requisitioned from the passive_timer list to avoid making extra calls * to malloc, but will allocate memory for a new counter if there are no * inactive timers available */ struct Timer * timer_schedule(void (*timeout) (struct Timer * t, Any_Type arg), Any_Type subject, Time delay) { struct Timer *t; if (!is_list_empty(passive_timers)) { Any_Type a = list_pop(passive_timers); t = (struct Timer *) a.vp; } else if ((t = malloc(sizeof(struct Timer))) == NULL) return NULL; memset(t, 0, sizeof(struct Timer)); t->timeout_callback = timeout; t->has_expired = false; t->timer_subject = subject; t->time_started = timer_now(); t->timeout_delay = delay; if (delay > 0) { Any_Type temp; temp.vp = (void *)t; list_push(active_timers, temp); } else { Any_Type temp; temp.vp = (void *)t; list_push(persistent_timers, temp); } if (DBG > 2) fprintf(stderr, "timer_schedule: t=%p, delay=%gs, subject=%lx\n", t, delay, subject.l); return t; }
struct evt_obj* dequeue_evt(_queue *queue) { _irqL irqL; struct evt_obj *pevtobj; _func_enter_; _enter_critical_ex(&queue->lock, &irqL); if (is_list_empty(&(queue->queue))) pevtobj = NULL; else { pevtobj = LIST_CONTAINOR(get_next(&(queue->queue)), struct evt_obj, list); list_delete(&pevtobj->list); } _exit_critical_ex(&queue->lock, &irqL); _func_exit_; return pevtobj; }
void free_arch(ARCH arch) { /* free text, data, bss sections */ for (int i = 0; i < 4 ; i++) { free((arch->sections[i]).name); free((arch->sections[i]).data); } /* free symbol table */ free(arch->symbols); /* free breakpoints list */ if (!is_list_empty(arch->breakpoints)) free_list(arch->breakpoints); free(arch->symbols_names); /* free instructions array*/ free_desc_array(); /* last but not least */ free(arch); }