static char* remove_multiple_items(void) { linked_list_append(root, create_object(1)); linked_list_append(root, create_object(2)); linked_list_append(root, create_object(3)); linked_list_remove(root, 2); linked_list_remove(root, 1); mu_assert(1 == get_id(linked_list_get(root, 0)), "Removing multiple items failed."); mu_assert(1 == linked_list_count(root), "Removing multiple items failed."); return 0; }
void engine_update_box (Player* player, Engine* engine) { vertex* v = player->v_buf->v; if (v->tl > -1) { linked_list_remove(engine->partitions[v->tl], v); v->tl = -1; } if (v->tr > -1) { linked_list_remove(engine->partitions[v->tr], v); v->tr = -1; } if (v->bl > -1) { linked_list_remove(engine->partitions[v->bl], v); v->bl = -1; } if (v->br > -1) { linked_list_remove(engine->partitions[v->br], v); v->br = -1; } int w = ceil(((double) engine->max_w) / BOX_SIZE); int x1 = *player->x / BOX_SIZE; int y1 = *player->y / BOX_SIZE; int x2 = (*player->x + v->bitmap->w) / BOX_SIZE; int y2 = (*player->y + v->bitmap->h) / BOX_SIZE; int idx = y1 * w + x1; if (idx < engine->partition_len) { engine->partitions[idx] = linked_list_add(engine->partitions[idx], v); v->tl = idx; } idx = y1 * w + x2; if (x2 != x1 && idx < engine->partition_len) { engine->partitions[idx] = linked_list_add(engine->partitions[idx], v); v->tr = idx; } idx = y2 * w + x1; if (y2 != y1 && idx < engine->partition_len) { engine->partitions[idx] = linked_list_add(engine->partitions[idx], v); v->bl = idx; } idx = y2 * w + x2; if (x2 != x1 && y2 != y1 && idx < engine->partition_len) { engine->partitions[idx] = linked_list_add(engine->partitions[idx], v); v->br = idx; } }
static void evg_tex_engine_fetch(struct evg_compute_unit_t *compute_unit) { struct linked_list_t *pending_queue = compute_unit->tex_engine.pending_queue; struct linked_list_t *finished_queue = compute_unit->tex_engine.finished_queue; struct evg_wavefront_t *wavefront; struct evg_uop_t *cf_uop, *uop; struct evg_work_item_uop_t *work_item_uop; struct evg_inst_t *inst; int inst_num; struct evg_work_item_t *work_item; int work_item_id; char str[MAX_LONG_STRING_SIZE]; char str_trimmed[MAX_LONG_STRING_SIZE]; /* Get wavefront to fetch from */ linked_list_head(pending_queue); cf_uop = linked_list_get(pending_queue); if (!cf_uop) return; wavefront = cf_uop->wavefront; assert(wavefront->clause_kind == EVG_CLAUSE_TEX); /* If fetch queue is full, cannot fetch until space is made */ if (compute_unit->tex_engine.fetch_queue_length >= evg_gpu_tex_engine_fetch_queue_size) return; /* Emulate instruction and create uop */ inst_num = (wavefront->clause_buf - wavefront->clause_buf_start) / 16; evg_wavefront_execute(wavefront); inst = &wavefront->tex_inst; uop = evg_uop_create(); uop->wavefront = wavefront; uop->work_group = wavefront->work_group; uop->cf_uop = cf_uop; uop->compute_unit = compute_unit; uop->id_in_compute_unit = compute_unit->gpu_uop_id_counter++; uop->last = wavefront->clause_kind != EVG_CLAUSE_TEX; uop->global_mem_read = wavefront->global_mem_read; uop->global_mem_write = wavefront->global_mem_write; uop->vliw_slots = 1; /* If TEX clause finished, extract CF uop from 'pending_queue' and * insert it into 'finished_queue'. */ if (uop->last) { linked_list_remove(pending_queue); linked_list_add(finished_queue, cf_uop); } /* If instruction is a global memory read (should be), record addresses */ if (uop->global_mem_read) { assert((inst->info->flags & EVG_INST_FLAG_MEM_READ)); EVG_FOREACH_WORK_ITEM_IN_WAVEFRONT(wavefront, work_item_id) { work_item = evg_gpu->ndrange->work_items[work_item_id]; work_item_uop = &uop->work_item_uop[work_item->id_in_wavefront]; work_item_uop->global_mem_access_addr = work_item->global_mem_access_addr; work_item_uop->global_mem_access_size = work_item->global_mem_access_size; }
static void action_delete_title_update(ui_view* view, void* data, float* progress, char* text) { delete_title_data* deleteData = (delete_title_data*) data; title_info* info = (title_info*) deleteData->selected->data; Result res = 0; if(R_SUCCEEDED(res = AM_DeleteTitle(info->mediaType, info->titleId)) && deleteData->ticket) { res = AM_DeleteTicket(info->titleId); } ui_pop(); info_destroy(view); if(R_FAILED(res)) { error_display_res(info, ui_draw_title_info, res, "Failed to delete title."); } else { linked_list_remove(deleteData->items, deleteData->selected); task_free_title(deleteData->selected); prompt_display("Success", "Title deleted.", COLOR_TEXT, false, NULL, NULL, NULL); } free(data); }
void timer_process(void) { PCB *each_pcb; int size, i, on; MSG_BUF *each_msg, *received_msg; while(1) { received_msg = receive_message(&size); on = atomic_on(); if(received_msg->mtype == MSG_TIMER_NOTIFICATION) { for (i = 0; i < gp_pending_message_queue.size; i++) { each_msg = list_entry(linked_list_get(&gp_pending_message_queue, i), MSG_BUF, m_lnode); each_msg->delay--; if (each_msg->delay <= 0) { each_pcb = get_pcb_by_pid(each_msg->m_recv_pid); linked_list_remove(&gp_pending_message_queue, i); add_to_message_queue(each_pcb, each_msg); i--; if (each_pcb->m_state == BLK && each_pcb->m_blk_reason == BLK_REASON_WAITING_FOR_MSG) { k_unblock_process(each_pcb->m_pid); } } } } atomic_off(on); } }
static struct gpu_wavefront_t *gpu_schedule_round_robin(struct gpu_compute_unit_t *compute_unit) { struct gpu_wavefront_t *wavefront, *temp_wavefront; struct linked_list_t *wavefront_pool = compute_unit->wavefront_pool; /* Select current position in pool as initial candidate wavefront */ if (!linked_list_get(wavefront_pool)) linked_list_head(wavefront_pool); wavefront = linked_list_get(wavefront_pool); temp_wavefront = wavefront; /* Look for a valid candidate */ for (;;) { /* Wavefront must be running, * and the corresponding slot in fetch buffer must be free. */ assert(wavefront->id_in_compute_unit < gpu->wavefronts_per_compute_unit); if (DOUBLE_LINKED_LIST_MEMBER(wavefront->work_group, running, wavefront) && !compute_unit->cf_engine.fetch_buffer[wavefront->id_in_compute_unit]) break; /* Current candidate is not valid - go to next. * If we went through the whole pool, no fetch. */ linked_list_next_circular(wavefront_pool); wavefront = linked_list_get(wavefront_pool); if (wavefront == temp_wavefront) return NULL; } /* Wavefront found, remove from pool and return. */ assert(wavefront->clause_kind == GPU_CLAUSE_CF); linked_list_remove(wavefront_pool); return wavefront; }
/** * Remove timer from run loop */ static int embedded_remove_timer(timer_source_t *ts){ #ifdef TIMER_SUPPORT return linked_list_remove(&timers, (linked_item_t *) ts); #else return 0; #endif }
int CS_putSegment(struct content_obj * prefix_obj, struct linked_list * content_chunks) { if (!prefix_obj || !content_chunks) return -1; struct CS_segment * segment = malloc(sizeof(struct CS_segment)); /* this is a content matching a prefix */ char * key = malloc(strlen(prefix_obj->name->full_name)); strcpy(key, prefix_obj->name->full_name); segment->index_chunk = prefix_obj; segment->num_chunks = content_chunks->len; segment->chunks = malloc(sizeof(struct content_obj * ) * segment->num_chunks); segment->valid = bit_create(segment->num_chunks); pthread_mutex_init(&segment->lock, NULL); int i = 0; while (content_chunks->len) { bit_set(segment->valid, i); segment->chunks[i++] = linked_list_remove(content_chunks, 0); } pthread_mutex_lock(&_cs.lock); hash_put(_cs.table, key, (void * ) segment); pthread_mutex_unlock(&_cs.lock); return 0; }
// finalize closed channel - l2cap_handle_disconnect_request & DISCONNECTION_RESPONSE void l2cap_finialize_channel_close(l2cap_channel_t *channel){ channel->state = L2CAP_STATE_CLOSED; l2cap_emit_channel_closed(channel); // discard channel linked_list_remove(&l2cap_channels, (linked_item_t *) channel); btstack_memory_l2cap_channel_free(channel); }
static void * tpool_worker(void * arg) { thread_pool_t * pool = (thread_pool_t * ) arg; pthread_mutex_lock(&pool->pj_mutex); while (!pool->shutdown) { while (pool->pending_jobs->len == 0) { pthread_cond_wait(&pool->pj_cond, &pool->pj_mutex); if (pool->shutdown) goto SHUTDOWN; } /* we have the mutex & len > 0 */ tpjob_t * job = linked_list_remove(pool->pending_jobs, 0); if (!job) continue; pthread_mutex_unlock(&pool->pj_mutex); void * ret_val = (job->job)(job->arg); if (job->use_arg_free) job->arg_free(job->arg); if (job->add_rv) { pthread_mutex_lock(job->cj_mutex); linked_list_append(job->completed_jobs, ret_val); pthread_cond_signal(job->cj_cond); pthread_mutex_unlock(job->cj_mutex); } free(job); pthread_mutex_lock(&pool->pj_mutex); } SHUTDOWN: pthread_mutex_unlock(&pool->pj_mutex); pthread_exit(NULL); }
static int get_link_key(bd_addr_t bd_addr, link_key_t link_key, link_key_type_t * link_key_type) { #if 1 char bd_addr_ini_string[BD_ADDR_LEN * 2 + 1]; memory_to_ini_string(bd_addr, BD_ADDR_LEN, bd_addr_ini_string); char link_key_ini_string[3 /* store link_key_type */ + LINK_KEY_LEN * 2 + 1]; if (!ev3rt_get_bluetooth_link_key(bd_addr_ini_string, link_key_ini_string)) return 0; link_key_ini_string[2] = '\0'; uint8_t link_key_type_val; ini_string_to_memory(link_key_ini_string, &link_key_type_val); *link_key_type = link_key_type_val; ini_string_to_memory(&link_key_ini_string[3], link_key); return 1; #else db_mem_device_link_key_t * item = (db_mem_device_link_key_t *) get_item(db_mem_link_keys, bd_addr); if (!item) return 0; memcpy(link_key, item->link_key, LINK_KEY_LEN); if (link_key_type) { *link_key_type = item->link_key_type; } linked_list_remove(&db_mem_link_keys, (linked_item_t *) item); linked_list_add(&db_mem_link_keys, (linked_item_t *) item); return 1; #endif }
static void delete_link_key(bd_addr_t *bd_addr){ db_mem_device_t * item = get_item(db_mem_link_keys, bd_addr); if (!item) return; linked_list_remove(&db_mem_link_keys, (linked_item_t *) item); btstack_memory_db_mem_device_link_key_free(item); }
void linked_list_clear(LinkedRoot* root) { if (NULL == root) { return; } while (root->head != NULL) { linked_list_remove(root, 0); } }
static void delete_name(bd_addr_t bd_addr){ db_mem_device_t * item = get_item(db_mem_names, bd_addr); if (!item) return; linked_list_remove(&db_mem_names, (linked_item_t *) item); btstack_memory_db_mem_device_name_free((db_mem_device_name_t*)item); }
/** * Remove timer from run loop */ int embedded_remove_timer(timer_source_t *ts){ #ifdef HAVE_TICK // log_info("Removed timer %x at %u\n", (int) ts, (unsigned int) ts->timeout.tv_sec); return linked_list_remove(&timers, (linked_item_t *) ts); #else return 0; #endif }
void bitmaps_cleanup(void) { while (linked_list_count(bitmaps) > 0) { AppBitmap* bmp = linked_list_get(bitmaps, 0); gbitmap_destroy(bmp->bitmap); free(bmp); linked_list_remove(bitmaps, 0); } }
int return_valid_ticket(linked_list_t *invalid_tickets, int ticket_tail) { while (++ticket_tail) { if (linked_list_count(invalid_tickets, ticket_tail)) linked_list_remove(invalid_tickets, ticket_tail); else break; } return ticket_tail; }
// unregister service record internally // // makes sure one client cannot remove service records of other clients // void sdp_unregister_service_internal(void *connection, uint32_t service_record_handle) { service_record_item_t * record_item = sdp_get_record_for_handle(service_record_handle); if (record_item && record_item->connection == connection) { linked_list_remove(&sdp_service_records, (linked_item_t *) record_item); #ifndef EMBEDDED free(record_item); #endif } }
void evg_faults_done(void) { while (linked_list_count(evg_fault_list)) { linked_list_head(evg_fault_list); free(linked_list_get(evg_fault_list)); linked_list_remove(evg_fault_list); } linked_list_free(evg_fault_list); }
void timers_clear(void) { if (! timers) { return; } while (linked_list_count(timers) > 0) { Timer* timer = (Timer*) linked_list_get(timers, 0); linked_list_remove(timers, 0); free(timer); } }
void socket_connection_free_connection(connection_t *conn){ // remove from run_loop run_loop_remove_data_source(&conn->ds); // and from connection list linked_list_remove(&connections, &conn->item); // destroy free(conn); }
void l2cap_unregister_service_internal(void *connection, uint16_t psm){ l2cap_service_t *service = l2cap_get_service(psm); if (!service) return; linked_list_remove(&l2cap_services, (linked_item_t *) service); btstack_memory_l2cap_service_free(service); // disable page scan when no services registered if (!linked_list_empty(&l2cap_services)) return; hci_connectable_control(0); }
void events_app_message_unsubscribe(EventHandle handle) { int16_t index = linked_list_find(s_handler_list, handle); if (index == -1) { return; } free(linked_list_get(s_handler_list, index)); linked_list_remove(s_handler_list, index); if (linked_list_count(s_handler_list) == 0) { app_message_deregister_callbacks(); } }
bool timers_remove(uint8_t position) { Timer* timer = timers_get(position); if (NULL == timer) { return false; } timer_pause(timer); linked_list_remove(timers, position); free(timer); timers_mark_updated(); return true; }
void si_uop_list_free(struct linked_list_t *gpu_uop_list) { struct si_uop_t *uop; while (linked_list_count(gpu_uop_list)) { linked_list_head(gpu_uop_list); uop = linked_list_get(gpu_uop_list); si_uop_free(uop); linked_list_remove(gpu_uop_list); } }
void test_linked_list_add_and_remove () { linked_list *list = create_linked_list (); TEST_ASSERT_NOT_NULL (list); // try to append an item and get it back later char *str1 = "hello"; linked_list_append (list, str1); TEST_ASSERT_EQUAL_INT (list->item_count, 1); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 0), str1); // try to append multiple items and get one back later char *strs1[] = {"world", "!"}; linked_list_append_all (list, (void **) strs1, 2); TEST_ASSERT_EQUAL_INT (list->item_count, 3); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 0), str1); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 1), strs1[0]); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 2), strs1[1]); // try to add an item at a specific position char *str2 = " "; linked_list_add (list, 1, str2); TEST_ASSERT_EQUAL_INT (list->item_count, 4); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 0), str1); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 1), str2); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 2), strs1[0]); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 3), strs1[1]); // try to add multiple items at a specific position char *strs2[] = {"WORLD", "?", "\n", "HELLO "}; linked_list_add_all (list, 2, (void **) strs2, 4); TEST_ASSERT_EQUAL_INT (list->item_count, 8); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 0), str1); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 1), str2); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 2), strs2[0]); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 3), strs2[1]); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 4), strs2[2]); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 5), strs2[3]); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 6), strs1[0]); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 7), strs1[1]); // try to remove an item linked_list_remove (list, 6); TEST_ASSERT_EQUAL_INT (list->item_count, 7); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 0), str1); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 1), str2); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 2), strs2[0]); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 3), strs2[1]); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 4), strs2[2]); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 5), strs2[3]); TEST_ASSERT_EQUAL_STR (linked_list_get (list, 6), strs1[1]); delete_linked_list (list); }
void events_battery_state_service_unsubscribe(EventHandle handle) { int16_t index = linked_list_find(s_handler_list, handle); if (index == -1) { return; } free(linked_list_get(s_handler_list, index)); linked_list_remove(s_handler_list, index); if (linked_list_count(s_handler_list) == 0) { battery_state_service_unsubscribe(); } }
int tpool_get_job(thread_pool_t * pool, void ** ret) { pthread_mutex_lock(&pool->cj_mutex); while (pool->completed_jobs->len == 0) { pthread_cond_wait(&pool->cj_cond, &pool->cj_mutex); } *ret = linked_list_remove(pool->completed_jobs, 0); pthread_mutex_unlock(&pool->cj_mutex); return 0; }
int tpool_cjl_get_job(completed_jobs_t * cjl, void ** ret) { pthread_mutex_lock(&cjl->mutex); while (cjl->completed->len == 0) { pthread_cond_wait(&cjl->cond, &cjl->mutex); } *ret = linked_list_remove(cjl->completed, 0); pthread_mutex_unlock(&cjl->mutex); return 0; }
static int get_name(bd_addr_t bd_addr, device_name_t *device_name) { db_mem_device_name_t * item = (db_mem_device_name_t *) get_item(db_mem_names, bd_addr); if (!item) return 0; strncpy((char*)device_name, item->device_name, MAX_NAME_LEN); linked_list_remove(&db_mem_names, (linked_item_t *) item); linked_list_add(&db_mem_names, (linked_item_t *) item); return 1; }