本文整理汇总了C++中queue_init函数的典型用法代码示例。如果您正苦于以下问题:C++ queue_init函数的具体用法?C++ queue_init怎么用?C++ queue_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了queue_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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;
}
示例2: main
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;
}
示例3: main
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;
}
示例4: Convert_NFA_To_DFA
/*
* 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);
}
示例5: main
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;
}
示例6: main
/* 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;
}
示例7: prio_sched_init
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;
}
示例8: main
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);
}
示例9: int
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);
}
示例10: rate_limit_start
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);
}
示例11: fs_init
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;
}
示例12: wait_queue_unlinkall_nofree
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);
}
示例13: IOLog1
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;
}
示例14: REG_INSERT
/**
* @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;
}
示例15: logger_create
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;
}