int main (int argc, char const *argv[]) { UNUSED_ARG(argc); UNUSED_ARG(argv); //Create queue lpqueue * q = queue_init(10); assert(q != NULL); //Add 10 elements (fill the queue) bool success; unsigned int i; printf("\nEnqueue... "); for(i = 0; i < 10; i++) { printf("%u, ", i); success = queue_append(q, strings[i], strlen(strings[i]), true); assert(success == true); } //Should be full success = queue_append(q, strings[1], strlen(strings[1]), true); assert(success == false); //Pop 10 elements void * data; size_t size; printf("\nDequeue... "); for(i = 0; i < 10; i++) { printf("%u, ", i); success = queue_pop(q, &data, &size); assert(success == true); //Check that they are ok assert(size = strlen(strings[i])); assert(memcmp(data, strings[i], size) == 0); free(data); } //Should now be empty success = queue_pop(q, &data, &size); assert(success == VALUES_QUEUE_EMPTY); printf("\nTEST SUCCESSFUL!\n"); return 0; }
int main() { int ret; common_data_t common_data; pthread_t recv_tid; pthread_t write_tid; queue_init(&common_data); ret = init_audio_device(&common_data); if(ret == -1){ dbg("init audio device error.\n"); exit(1); } ret = setup_socket(&common_data); if(ret == -1){ dbg("setup socket error.\n"); return 0; } /* create two threads: socket recv thread and pcm write thread */ ret = pthread_create(&recv_tid, NULL, recv_pcmdata, (void *)&common_data); if (0 != ret){ dbg("can't create recv_pcmdata thread\n"); } ret = pthread_create(&write_tid, NULL, write_pcmdata, (void *)&common_data); if (0 != ret){ dbg("can't create write_thread\n"); } pthread_join(recv_tid, NULL); // pthread_join(write_tid, NULL); close(common_data.client_socket); close(common_data.server_socket); //free(g_buf); snd_pcm_drain(common_data.handle); snd_pcm_close(common_data.handle); return 0; }
int main(void) { uint8_t msg; queue_init(); queue_add(1); queue_add(2); queue_add(3); queue_add(4); queue_add(5); queue_add(6); queue_add(7); msg = queue_get(); printf("Get %d\n", msg); msg = queue_get(); printf("Get %d\n", msg); msg = queue_get(); printf("Get %d\n", msg); msg = queue_get(); printf("Get %d\n", msg); msg = queue_get(); printf("Get %d\n", msg); msg = queue_get(); printf("Get %d\n", msg); msg = queue_get(); printf("Get %d\n", msg); printf("Hello World!\n"); return 0; }
/* * Build Deterministic Finite Automata from NFA */ static void Convert_NFA_To_DFA (ACSM_STRUCT * acsm) { int r, s; int i; QUEUE q, *queue = &q; /* Init a Queue */ queue_init (queue); /* Add the state 0 transitions 1st */ for (i = 0; i < ALPHABET_SIZE; i++) { s = acsm->acsmStateTable[0].NextState[i]; if (s) { queue_add (queue, s); } } /* Start building the next layer of transitions */ while (queue_count (queue) > 0) { r = queue_remove (queue); /* State is a branch state */ for (i = 0; i < ALPHABET_SIZE; i++) { if ((s = acsm->acsmStateTable[r].NextState[i]) != ACSM_FAIL_STATE) { queue_add (queue, s); } else { acsm->acsmStateTable[r].NextState[i] = acsm->acsmStateTable[acsm->acsmStateTable[r].FailState]. NextState[i]; } } } /* Clean up the queue */ queue_free (queue); }
int main(void) { // Разрешить светодиод arduino pro mini. DDRB |= _BV(DDB5); timer_init(); uart_async_init(); i2c_init(); queue_init(); init_int0(); // Разрешить прерывания. sei(); uart_readln(&commands_reciver); uart_writeln("start"); // Бесконечный цикл с энергосбережением. for(;;) { switch(queue_getTask()) { case DO_REQUEST_RTC_DATA_START : //Установть позицию на регистр 0x0 ds3231_buf[0] = 0; i2c_send(0xD0, ds3231_buf, 1, &callBackForRequestRtcData); break; case DO_REQUEST_RTC_DATA_END : //Читаем 7 байт i2c_recive(0xD0 + 1, ds3231_buf, 7, &callBackForRequestRtcData); break; case DO_TIMER1_OVF : i2c_init(); //queue_putTask(DO_REQUEST_RTC_DATA_START); timer1_doing = 0; break; case COMMAND_SEND_I2C : i2c_send(commands_reciver_param1[0], // Адресс. commands_reciver_param2, // Буфер. commands_reciver_param3[0], // Количество. &callBackForSendI2CData); break; case COMMAND_RECIVE_I2C : i2c_recive(commands_reciver_param1[0], // Адресс. ds3231_buf, // Буфер. commands_reciver_param3[0], // Количество. &callBackForReciveI2CData); break; default : sleep_mode(); } } return 0; }
/* The main function creates the LCD task, registers the edge counter polling interrupt, * and starts the OS. */ int main(void) { int status; // Initialize components. lcd_init(); queue_init(); // Create the LCD task. OSTaskCreateExt(lcd_task, NULL, (void *)&lcd_task_stk[TASK_STACKSIZE - 1], LCD_TASK_PRIORITY, LCD_TASK_PRIORITY, lcd_task_stk, TASK_STACKSIZE, NULL, 0); // Create the LCD task. OSTaskCreateExt(ir_task, NULL, (void *)&ir_task_stk[TASK_STACKSIZE - 1], IR_TASK_PRIORITY, IR_TASK_PRIORITY, ir_task_stk, TASK_STACKSIZE, NULL, 0); // Register the IR pushbutton interrupt. status = alt_ic_isr_register(IR_PUSHBUTTON_IRQ_INTERRUPT_CONTROLLER_ID, IR_PUSHBUTTON_IRQ, isr_on_ir_pushbutton, NULL, NULL); // Start. if (status == OK) { OSStart(); } return 0; }
sched_t* prio_sched_init() { sched_t* toReturn = (sched_t*)malloc(sizeof(sched_t)); int i; assert(toReturn != NULL); toReturn->sched = malloc(sizeof(prio_sched_t)); for (i = 0; i < LOWEST_PRIO; ++i) { SCHED_QUEUE(toReturn)[i] = queue_init(); } toReturn->add_thread = prio_sched_add_thread; toReturn->next_thread = prio_sched_next_thread; toReturn->for_all_threads = prio_sched_for_all_threads; toReturn->destroy = prio_sched_destroy; return toReturn; }
int main (int argc, char** argv) { static const char* usage = "usage: aRead numBlocks"; int numBlocks = 0; queue_init (&prq); if (argc == 2) numBlocks = strtol (argv [1], NULL, 10); if (argc != 2 || (numBlocks == 0 && errno == EINVAL)) { printf ("%s\n", usage); return EXIT_FAILURE; } uthread_init (1); disk_start (interruptServiceRoutine); run (numBlocks); printf ("%d\n", sum); }
struct v4l2_m2m_ctx *v4l2_m2m_ctx_init(struct v4l2_m2m_dev *m2m_dev, void *drv_priv, int (*queue_init)(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)) { struct v4l2_m2m_ctx *m2m_ctx; struct v4l2_m2m_queue_ctx *out_q_ctx, *cap_q_ctx; int ret; m2m_ctx = kzalloc(sizeof *m2m_ctx, GFP_KERNEL); if (!m2m_ctx) return ERR_PTR(-ENOMEM); m2m_ctx->priv = drv_priv; m2m_ctx->m2m_dev = m2m_dev; init_waitqueue_head(&m2m_ctx->finished); out_q_ctx = &m2m_ctx->out_q_ctx; cap_q_ctx = &m2m_ctx->cap_q_ctx; INIT_LIST_HEAD(&out_q_ctx->rdy_queue); INIT_LIST_HEAD(&cap_q_ctx->rdy_queue); spin_lock_init(&out_q_ctx->rdy_spinlock); spin_lock_init(&cap_q_ctx->rdy_spinlock); INIT_LIST_HEAD(&m2m_ctx->queue); ret = queue_init(drv_priv, &out_q_ctx->q, &cap_q_ctx->q); if (ret) goto err; /* * If both queues use same mutex assign it as the common buffer * queues lock to the m2m context. This lock is used in the * v4l2_m2m_ioctl_* helpers. */ if (out_q_ctx->q.lock == cap_q_ctx->q.lock) m2m_ctx->q_lock = out_q_ctx->q.lock; return m2m_ctx; err: kfree(m2m_ctx); return ERR_PTR(ret); }
void rate_limit_start(struct secchan *secchan, const struct settings *s, struct switch_status *ss, struct rconn *remote) { struct rate_limiter *rl; size_t i; rl = xcalloc(1, sizeof *rl); rl->s = s; rl->remote_rconn = remote; for (i = 0; i < ARRAY_SIZE(rl->queues); i++) { queue_init(&rl->queues[i]); } rl->last_fill = time_msec(); rl->tokens = s->rate_limit * 100; switch_status_register_category(ss, "rate-limit", rate_limit_status_cb, rl); add_hook(secchan, &rate_limit_hook_class, rl); }
ret_code_t fs_init(void) { uint16_t lowest_index = 0; uint16_t lowest_order = 0xFFFF; uint32_t * current_end = (uint32_t*)FS_PAGE_END_ADDR; uint32_t num_left = FS_SECTION_VARS_COUNT; queue_init(); /** Assign pages to registered users, beginning with the ones with the lowest * order, which will be assigned pages with the lowest memory address. */ do { fs_config_t * p_config; for (uint16_t i = 0; i < FS_SECTION_VARS_COUNT; i++) { p_config = FS_SECTION_VARS_GET(i); // Skip the ones which have the end-address already set. if (p_config->p_end_addr != NULL) continue; if (p_config->page_order < lowest_order) { lowest_order = p_config->page_order; lowest_index = i; } } p_config = FS_SECTION_VARS_GET(lowest_index); p_config->p_end_addr = current_end; p_config->p_start_addr = p_config->p_end_addr - (p_config->num_pages * FS_PAGE_SIZE_WORDS); current_end = p_config->p_start_addr; lowest_order = 0xFFFF; } while ( --num_left > 0 ); m_flags |= FS_FLAG_INIT; return NRF_SUCCESS; }
kern_return_t wait_queue_unlinkall_nofree( wait_queue_t wq) { wait_queue_element_t wq_element; wait_queue_element_t wq_next_element; wait_queue_set_t wq_set; wait_queue_link_t wql; queue_head_t links_queue_head; queue_t links = &links_queue_head; queue_t q; spl_t s; if (!wait_queue_is_queue(wq)) { return KERN_INVALID_ARGUMENT; } queue_init(links); s = splsched(); wait_queue_lock(wq); q = &wq->wq_queue; wq_element = (wait_queue_element_t) queue_first(q); while (!queue_end(q, (queue_entry_t)wq_element)) { WAIT_QUEUE_ELEMENT_CHECK(wq, wq_element); wq_next_element = (wait_queue_element_t) queue_next((queue_t) wq_element); if (wq_element->wqe_type == WAIT_QUEUE_LINK) { wql = (wait_queue_link_t)wq_element; wq_set = wql->wql_setqueue; wqs_lock(wq_set); wait_queue_unlink_locked(wq, wq_set, wql); wqs_unlock(wq_set); } wq_element = wq_next_element; } wait_queue_unlock(wq); splx(s); return(KERN_SUCCESS); }
bool AppleRAIDMirrorSet::init() { IOLog1("AppleRAIDMirrorSet::init() called\n"); if (super::init() == false) return false; arRebuildThreadCall = 0; arSetCompleteThreadCall = 0; arExpectingLiveAdd = 0; arMaxReadRequestFactor = 32; // with the default 32KB blocksize -> 1 MB queue_init(&arFailedRequestQueue); setProperty(kAppleRAIDLevelNameKey, kAppleRAIDLevelNameMirror); arAllocateRequestMethod = OSMemberFunctionCast(IOCommandGate::Action, this, &AppleRAIDSet::allocateRAIDRequest); return true; }
/** * @brief Initializes a thread structure. * @note This is an internal functions, do not use it in application code. * * @param[in] tp pointer to the thread * @param[in] prio the priority level for the new thread * @return The same thread pointer passed as parameter. * * @notapi */ thread_t *_thread_init(thread_t *tp, tprio_t prio) { tp->p_prio = prio; tp->p_state = CH_STATE_WTSTART; tp->p_flags = CH_FLAG_MODE_STATIC; #if CH_CFG_TIME_QUANTUM > 0 tp->p_preempt = CH_CFG_TIME_QUANTUM; #endif #if CH_CFG_USE_MUTEXES tp->p_realprio = prio; tp->p_mtxlist = NULL; #endif #if CH_CFG_USE_EVENTS tp->p_epending = 0; #endif #if CH_DBG_THREADS_PROFILING tp->p_time = 0; #endif #if CH_CFG_USE_DYNAMIC tp->p_refs = 1; #endif #if CH_CFG_USE_REGISTRY tp->p_name = NULL; REG_INSERT(tp); #endif #if CH_CFG_USE_WAITEXIT list_init(&tp->p_waiting); #endif #if CH_CFG_USE_MESSAGES queue_init(&tp->p_msgqueue); #endif #if CH_DBG_ENABLE_STACK_CHECK tp->p_stklimit = (stkalign_t *)(tp + 1); #endif #if CH_DBG_STATISTICS || defined(__DOXYGEN__) chTMObjectInit(&tp->p_stats); chTMStartMeasurementX(&tp->p_stats); #endif #if defined(CH_CFG_THREAD_INIT_HOOK) CH_CFG_THREAD_INIT_HOOK(tp); #endif return tp; }
struct logger* logger_create(int type, char* dstip, int dstport, char* filepath) { struct logger* l = kzalloc(sizeof(struct logger), GFP_ATOMIC); CHECK_IF(l == NULL, return NULL, "l is null"); queue_init(&l->mq, -1, _clean_log, QUEUE_FLAG_POP_BLOCK); l->type = type; l->lv = LOG_DEFAULT_LV; if (type & LOG_UDP) { CHECK_IF(dstip == NULL, goto _ERROR, "LOG_UDP dstip is null"); CHECK_IF(dstport <= 0, goto _ERROR, "LOG_UDP dstport = %d invalid", dstport); udp_init(&l->udp, NULL, UDP_PORT_ANY); snprintf(l->remote.ipv4, INET_ADDRSTRLEN, "%s", dstip); l->remote.port = dstport; }
int main(int argc,const char* const* argv){ int c; const char* message = NULL; while ( (c = getopt(argc,(char*const*)argv, "p:")) != -1) { switch(c) { /* -p $MSGID : preprocess message $MSGID */ caseof('p',message = optarg) } } if(message) { queue_init(); queue_process(message); return 0; } clock_init(argv[0]); clock_loop(); return 1; }
void SparkProtocol::init(const char *id, const SparkKeys &keys, const SparkCallbacks &callbacks, const SparkDescriptor &descriptor) { memcpy(server_public_key, keys.server_public, MAX_SERVER_PUBLIC_KEY_LENGTH); memcpy(core_private_key, keys.core_private, MAX_DEVICE_PRIVATE_KEY_LENGTH); memcpy(device_id, id, 12); // when using this lib in C, constructor is never called queue_init(); this->callbacks = callbacks; this->descriptor = descriptor; memset(event_handlers, 0, sizeof(event_handlers)); initialized = true; }
int main(void) { int size = 4; int item_size = sizeof(int); printk("Starting queue tests\n"); printk("- init queue with size of %d and item_size of %d\n", size, item_size); queue_init(&queue, size, item_size); printk("- adding thread A (%x)\n", &thread_a); add_thread(&thread_a, HIGHEST_PRIORITY); printk("- adding thread B(%x)\n", &thread_b); add_thread(&thread_b, HIGHEST_PRIORITY - 1); return 0; }
/* main init */ void pmu_init(void) { mutex_init(&pmu_adc_mutex); queue_init(&pmu_queue, false); create_thread(pmu_thread, pmu_thread_stack, sizeof(pmu_thread_stack), 0, "PMU" IF_PRIO(, PRIORITY_SYSTEM) IF_COP(, CPU)); /* configure PMU interrutps */ for (int i = 0; i < 6; i++) ints_msk[i] = 0xff; #if CONFIG_CHARGING ints_msk[0] &= ~PCF5063X_INT1_ADPINS & /* FireWire */ ~PCF5063X_INT1_ADPREM; #endif ints_msk[1] &= ~PCF5063X_INT2_EXTON2R & /* USB */ ~PCF5063X_INT2_EXTON2F; #ifdef IPOD_ACCESSORY_PROTOCOL ints_msk[1] &= ~PCF5063X_INT2_EXTON3R & /* Accessory */ ~PCF5063X_INT2_EXTON3F; #endif ints_msk[5] &= ~PCF50635_INT6_GPIO2; /* Holdswitch */ pmu_write_multiple(PCF5063X_REG_INT1M, 5, ints_msk); pmu_write(PCF50635_REG_INT6M, ints_msk[5]); /* clear all */ unsigned char ints[5]; pmu_read_multiple(PCF5063X_REG_INT1, 5, ints); pmu_read(PCF50635_REG_INT6); /* get initial values */ #if CONFIG_CHARGING pmu_read_inputs_mbcs(); #endif pmu_read_inputs_ooc(); pmu_read_inputs_gpio(); eint_register(&pmu_eint); }
/** * Removes all rules which are not descendants of simulated DAG rooted at targets. * * @param rules Queue of rules which is read and modified. * @param targets List of targets which act as roots. * @return Void. */ static void filterOnTargets(queue_t **rules, char **targets){ queue_t *validRules = malloc(sizeof(queue_t)); queue_init(validRules); int idx; //initialize validRules with targets for(idx=0; idx < queue_size(*rules);idx++){ rule_t *curRule = queue_at(*rules, idx); int tarIdx; for(tarIdx=0; targets[tarIdx] != NULL; tarIdx++){ if(strcmp(curRule->target, targets[tarIdx]) == 0){ queue_enqueue(validRules, curRule); queue_remove_at(*rules, idx); idx--; break; } } } //repeated linear search for new valid targets int prevSize = 0; while(prevSize != queue_size(validRules)){ prevSize = queue_size(validRules); for(idx=0; idx < queue_size(*rules); idx++){ rule_t *curRule = queue_at(*rules, idx); if(findMatch(curRule, validRules)){ queue_enqueue(validRules, curRule); queue_remove_at(*rules, idx); idx--; } } } //cleanup old rules queue_iterate(*rules, rule_free_adapter, 0); queue_destroy(*rules); free(*rules); //assign new queue *rules = validRules; }
bool bfs_data_structure_init(set_t** visited_ptr, queue_t** queue_ptr, unsigned int id) { bool status = true; struct bfs_node_struct *bfs_node_ptr = NULL; *queue_ptr = NULL; *visited_ptr = NULL; /* Initialize the visited set */ if((*visited_ptr = set_init()) == NULL) status = false; /* Add id in the visited set */ if(status) status = set_add(*visited_ptr, id); /* Initialize the queue */ if(status && (*queue_ptr = queue_init()) == NULL) status = false; /* Allocate memory for the queue's first entry */ if(status && (bfs_node_ptr = malloc(sizeof(struct bfs_node_struct))) != NULL) { bfs_node_ptr->id = id; bfs_node_ptr->distance = 0; if(!(status = queue_enqueue(*queue_ptr, bfs_node_ptr))) free(bfs_node_ptr); } else status = false; /* On error, free everything */ if(!status) bfs_data_structure_destroy(visited_ptr, queue_ptr); return status; }
thread_pool* init_thread_pool(int threads_num) { thread_pool* pool = malloc(sizeof(thread_pool)); pool->threads_num = threads_num; pool->cancelled = false; pool->mutex = malloc(sizeof(pthread_mutex_t)); pool->mutex_free = malloc(sizeof(pthread_mutex_t)); pool->cond = malloc(sizeof(pthread_cond_t)); pthread_mutex_init(pool->mutex, NULL); pthread_mutex_init(pool->mutex_free, NULL); pthread_cond_init(pool->cond, NULL); pool->tasks_queue = queue_init(); pool->threads = malloc(threads_num * sizeof(pthread_t)); pthread_t* thread; for(int i = 0; i < threads_num; i++) { thread = &pool->threads[i]; pthread_create(thread, NULL, thread_exec, pool); } return pool; }
lrucache_init(LRUCACHE* lrucache, int size) { int err; lrucache->size = size; lrucache->map = malloc(sizeof(MAP)); err = map_init(lrucache->map); if (err) { return -1; } lrucache->queue = malloc(sizeof(QUEUE)); err = queue_init(lrucache->queue); if (err) { return -2; } return 0; }
void pvm_restart_tty( pvm_object_t o ) { struct data_area_4_tty *tty = pvm_object_da( o, tty ); printf( "restart TTY %p\n", tty ); tty->w.title = tty->title; // need? must be correct in snap // BUG! How do we fill owner? We must have object ref here tty->w.inKernelEventProcess = 0; tty->w.owner = -1; queue_init(&(tty->w.events)); tty->w.events_count = 0; drv_video_window_enter_allwq( &tty->w ); //event_q_put_win( 0, 0, UI_EVENT_WIN_REPAINT, &tty->w ); //event_q_put_win( 0, 0, UI_EVENT_WIN_REDECORATE, &tty->w ); }
int main(void) { queue Q; int i = 0; queue_init(&Q, SIZE); for (i = 0; i < SIZE-2; i++) { queue_enter(&Q, i); } for (i = 0; i < SIZE; i++) { printf("%d\n", queue_delete(&Q)); } queue_destroy(&Q); return 0; }
static int obsoleted_by_pseudos_only(Transaction *trans, Id p) { Pool *pool = trans->pool; Queue q; Id op; int i; op = transaction_obs_pkg(trans, p); if (op && !is_pseudo_package(pool, pool->solvables + op)) return 0; queue_init(&q); transaction_all_obs_pkgs(trans, p, &q); for (i = 0; i < q.count; i++) if (!is_pseudo_package(pool, pool->solvables + q.elements[i])) break; i = !q.count || i < q.count ? 0 : 1; queue_free(&q); return i; }
bool IOCommandPool:: initWithWorkLoop(IOWorkLoop *inWorkLoop) { assert(inWorkLoop); if (!super::init()) return false; queue_init(&fQueueHead); fSerializer = IOCommandGate::commandGate(this); assert(fSerializer); if (!fSerializer) return false; if (kIOReturnSuccess != inWorkLoop->addEventSource(fSerializer)) return false; return true; }
int main(void) { SystemCoreClockUpdate(); Board_Init(); Board_LED_Set(0, false); // SW4 setup Chip_GPIO_SetDir(LPC_GPIO, 1, 31, false); sw4 = debounce_add(DEBOUNCE_TIME / DEBOUNCE_CYCLE, is_sw4_pushed, NULL); queue_init(&queue, 1, EventQueue, AlarmTimeoutPush, AlarmTimeoutPop, MutexQueue); StartOS(AppMode1); while (1) { } return 0; }
int main() { Queue queue; queue_init(&queue, free); int *data; int data1; data1 = 4; int data2; data2 = 9; queue_enqueue(&queue, &data1); queue_enqueue(&queue, &data2); printf("%d\n", queue_size(&queue)); while (queue_size(&queue) > 0) { queue_dequeue(&queue, (void *) &data); printf("queue_dequeue returned %d\n", *data); } return 0; }
/* * Routine: wait_queue_set_init * Purpose: * Initialize a previously allocated wait queue set. * Returns: * KERN_SUCCESS - The wait_queue_set_t was initialized * KERN_INVALID_ARGUMENT - The policy parameter was invalid */ kern_return_t wait_queue_set_init( wait_queue_set_t wqset, int policy) { kern_return_t ret; ret = wait_queue_init(&wqset->wqs_wait_queue, policy); if (ret != KERN_SUCCESS) return ret; wqset->wqs_wait_queue.wq_type = _WAIT_QUEUE_SET_inited; if (policy & SYNC_POLICY_PREPOST) wqset->wqs_wait_queue.wq_isprepost = TRUE; else wqset->wqs_wait_queue.wq_isprepost = FALSE; queue_init(&wqset->wqs_setlinks); wqset->wqs_refcount = 0; return KERN_SUCCESS; }