static int demux_thread(void *data)
{
    webm_context *ctx = (webm_context *)data;
    nestegg_packet *pkt;
    int r;
    while ((r = nestegg_read_packet(ctx->nestegg_ctx, &pkt)) > 0)
    {
        unsigned int track;
        nestegg_packet_track(pkt, &track);

        if (track == ctx->audio_track)
        {
            if (queue_insert(ctx->audio_ctx.packet_queue, pkt) < 0)
            {
                nestegg_free_packet(pkt);
                break;
            }
        }
        else if (track == ctx->video_track)
        {
            if (queue_insert(ctx->video_ctx.packet_queue, pkt) < 0)
            {
                nestegg_free_packet(pkt);
                break;
            }
        }

        if (quit_video) break;
    }
    queue_insert(ctx->video_ctx.packet_queue, NULL);
    if (ctx->audio_track >= 0) queue_insert(ctx->audio_ctx.packet_queue, NULL);
    return 0;
}
Example #2
0
int main()
{
	int x = 0; char *a ;
	struct arrayqueue *queue;
	printf("\ntesting queue_create...");
	queue = queue_create();
	if(queue == NULL)
	{
		printf("\n queue not created...\n");
		goto fail;
	}
	else
		printf("[ok]\n");
	
	printf("testing queue_insert...");
	x = queue_insert(queue, 'a');
	if(x == 1)
	{
		x = queue_insert(queue, 'b');
		x = queue_insert(queue, 'c');
		x = queue_insert(queue, 'd');
		printf("[ok]\n");
	}
	else
		goto fail;

	printf("testing queue_remove...");
	x = queue_remove(queue, a);
	if( *a != 'a')
		goto fail;
	else
		printf("[ok]\n");

	x = queue_remove(queue, a);
	x = queue_remove(queue, a);
	x = queue_remove(queue, a);	

	printf("testing queue_empty...");
	x = queue_empty(queue);
	if( x == 1)
		printf("[ok]\n");
	else
		goto fail;

	return 0;
fail:
	printf("[failed]\n");
	return -1;
}
Example #3
0
int main(int argc, char const *argv[])
{
	void * queue;
	queue = queue_create();
	
	teacher_t t[50];

	for (int i = 0 ; i < 50; i++)
	{
		t[i].age = i;
		queue_insert(queue, &t[i]);
	}
	
	teacher_t * p;
	int k = queue_length(queue);
	for (int i = 0; i < k-1; i++)
	{
		p = (teacher_t *)queue_delete(queue);
		fprintf(stdout, "%d ", p->age);
	} 

	fprintf(stdout, "\n");

	p = (teacher_t *)queue_head(queue);
	fprintf(stdout, "%d ", p->age);
	fprintf(stdout, "\n");
	queue_delete(queue);

	for (int i = 0 ; i < 50; i++)
	{
		t[i].age = i + 100;
		queue_insert(queue, &t[i]);
	}
	if (!queue_empty(queue))
		fprintf(stdout, "queue is not empty\n");
	k = queue_length(queue);
	for (int i = 0; i < k; i++)
	{
		p = (teacher_t *)queue_delete(queue);
		fprintf(stdout, "%d ", p->age);
	} 
	fprintf(stdout, "\n");
	if (queue_empty(queue))
		fprintf(stdout, "queue not empty\n");

	queue_destroy(queue);
	return 0;
}
Example #4
0
int myrg_rlast(MYRG_INFO *info, uchar *buf, int inx)
{
  MYRG_TABLE *table;
  MI_INFO *mi;
  int err;

  if (_myrg_init_queue(info,inx, HA_READ_KEY_OR_PREV))
    return my_errno;

  for (table=info->open_tables ; table < info->end_table ; table++)
  {
    if ((err=mi_rlast(table->table,NULL,inx)))
    {
      if (err == HA_ERR_END_OF_FILE)
	continue;
      return err;
    }
    /* adding to queue */
    queue_insert(&(info->by_key),(uchar *)table);
  }
  /* We have done a read in all tables */
  info->last_used_table=table;

  if (!info->by_key.elements)
    return HA_ERR_END_OF_FILE;

  mi=(info->current_table=(MYRG_TABLE *)queue_top(&(info->by_key)))->table;
  return _myrg_mi_read_record(mi,buf);
}
Example #5
0
/* Initiate teardown.  Clear any alloc/free requests, and clear
 * the alloc->ready flag to stop prep/check from allocating.
 */
static void interface_teardown (struct alloc_ctx *ctx, char *s, int errnum)
{
    if (ctx->ready) {
        struct job *job;

        flux_log (ctx->h, LOG_DEBUG, "alloc: stop due to %s: %s",
                  s, flux_strerror (errnum));

        job = queue_first (ctx->queue);
        while (job) {
            /* jobs with alloc pending need to go back in the queue
             * so they will automatically send alloc again.
             */
            if (job->alloc_pending) {
                assert (job->aux_queue_handle == NULL);
                if (queue_insert (ctx->inqueue, job,
                                                &job->aux_queue_handle) < 0)
                    flux_log_error (ctx->h, "%s: queue_insert", __FUNCTION__);
                job->alloc_pending = 0;
                job->alloc_queued = 1;
            }
            /* jobs with free pending (much smaller window for this to be true)
             * need to be picked up again after 'hello'.
             */
            job->free_pending = 0;
            job = queue_next (ctx->queue);
        }
        ctx->ready = false;
        ctx->active_alloc_count = 0;
    }
}
static void ipphone_display_status(LinphoneCore *lc, const char *something){
	fsm_evnt_t new_event = -1;
	
	if(!strcmp(something, "User is temporarily unavailable."))
		something = "STATUS: UNAVAILABLE ";
	else
	if(!strcmp(something, "User cannot be found at given address."))
		something = "STATUS: UNREACHABLE ";
	else
	if(!strcmp(something, "Call declined."))
		something = "STATUS: DECLINED    ";
	else
	if(!strcmp(something, "Service Unavailable"))
		something = "STATUS: UNAVAILABLE ";
	else
	if(!strcmp(something, "Address Incomplete"))
		something = "STATUS: UNREACHABLE ";
	else
	if(!strcmp(something, "Could not reach destination."))
		something = "STATUS: UNAVAILABLE ";
  else
	{
    printf("something_status:%s\n",something);
		return;
	}

  lcd_write_justified(LCD_WRITE_LEFT_JUSTIFIED, 1, something);
  queue_insert((main_queue_t *)lc->data, FSM_EVNT_LINPHONE_CALL_FAIL);
}
Example #7
0
char* lrucache_get(LRUCACHE* lrucache, char* key)
{
    queue_remove(lrucache->queue, key);
    queue_insert(lrucache->queue, key);
    
    return map_get(lrucache->map, key);
}
Example #8
0
int myrg_rkey(MYRG_INFO *info,uchar *buf,int inx, const uchar *key,
            key_part_map keypart_map, enum ha_rkey_function search_flag)
{
  uchar *key_buff;
  uint pack_key_length;
  uint16 last_used_keyseg;
  MYRG_TABLE *table;
  MI_INFO *mi;
  int err;
  DBUG_ENTER("myrg_rkey");
  LINT_INIT(key_buff);
  LINT_INIT(pack_key_length);
  LINT_INIT(last_used_keyseg);

  if (_myrg_init_queue(info,inx,search_flag))
    DBUG_RETURN(my_errno);

  for (table=info->open_tables ; table != info->end_table ; table++)
  {
    mi=table->table;

    if (table == info->open_tables)
    {
      err=mi_rkey(mi, 0, inx, key, keypart_map, search_flag);
      /* Get the saved packed key and packed key length. */
      key_buff=(uchar*) mi->lastkey+mi->s->base.max_key_length;
      pack_key_length=mi->pack_key_length;
      last_used_keyseg= mi->last_used_keyseg;
    }
    else
    {
      mi->once_flags|= USE_PACKED_KEYS;
      mi->last_used_keyseg= last_used_keyseg;
      err=mi_rkey(mi, 0, inx, key_buff, pack_key_length, search_flag);
    }
    info->last_used_table=table+1;

    if (err)
    {
      if (err == HA_ERR_KEY_NOT_FOUND)
	continue;
      DBUG_PRINT("exit", ("err: %d", err));
      DBUG_RETURN(err);
    }
    /* adding to queue */
    queue_insert(&(info->by_key),(uchar *)table);

  }

  DBUG_PRINT("info", ("tables with matches: %u", info->by_key.elements));
  if (!info->by_key.elements)
    DBUG_RETURN(HA_ERR_KEY_NOT_FOUND);

  mi=(info->current_table=(MYRG_TABLE *)queue_top(&(info->by_key)))->table;
  mi->once_flags|= RRND_PRESERVE_LASTINX;
  DBUG_PRINT("info", ("using table no: %d",
                      (int) (info->current_table - info->open_tables + 1)));
  DBUG_DUMP("result key", (uchar*) mi->lastkey, mi->lastkey_length);
  DBUG_RETURN(_myrg_mi_read_record(mi,buf));
}
Example #9
0
void P(struct semaphore* sig){

	if (!sig->INT)
		cli();

	sig->value--;
	if (sig->value < 0){
		queue_delete(current_pcb);
		if (sig->value == -1){
			current_pcb->pre_pcb = current_pcb;
			current_pcb->next_pcb = current_pcb;
			sig->waitlist = current_pcb;
		}
		else
			queue_insert(sig->waitlist, current_pcb);	/*wait*/
		proc_run--;
		if (sig->INT)
			pick_proc();
		else 
			yield();
	}

	if (!sig->INT)
		sti();
}
Example #10
0
void add_thread(struct node *node, struct node *add_item)
{
	
	queue_insert(node->queue, queue_first(add_item->queue));
	node->num_threads++;
	free(add_item);
}
Example #11
0
/**
 * @brief   Puts the invoking thread into the queue's threads queue.
 *
 * @param[out] qp       pointer to an @p GenericQueue structure
 * @param[in] time      the number of ticks before the operation timeouts,
 *                      the following special values are allowed:
 *                      - @a TIME_IMMEDIATE immediate timeout.
 *                      - @a TIME_INFINITE no timeout.
 *                      .
 * @return              A message specifying how the invoking thread has been
 *                      released from threads queue.
 * @retval Q_OK         is the normal exit, thread signaled.
 * @retval Q_RESET      if the queue has been reset.
 * @retval Q_TIMEOUT    if the queue operation timed out.
 */
static msg_t qwait(GenericQueue *qp, systime_t time) {

    if (TIME_IMMEDIATE == time)
        return Q_TIMEOUT;
    currp->p_u.wtobjp = qp;
    queue_insert(currp, &qp->q_waiting);
    return chSchGoSleepTimeoutS(THD_STATE_WTQUEUE, time);
}
Example #12
0
/**
 * @brief   Enqueues the caller thread on a threads queue object.
 * @details The caller thread is enqueued and put to sleep until it is
 *          dequeued or the specified timeouts expires.
 *
 * @param[in] tqp       pointer to the threads queue object
 * @param[in] timeout   the timeout in system ticks, the special values are
 *                      handled as follow:
 *                      - @a TIME_INFINITE the thread enters an infinite sleep
 *                        state.
 *                      - @a TIME_IMMEDIATE the thread is not enqueued and
 *                        the function returns @p MSG_TIMEOUT as if a timeout
 *                        occurred.
 *                      .
 * @return              The message from @p osalQueueWakeupOneI() or
 *                      @p osalQueueWakeupAllI() functions.
 * @retval MSG_TIMEOUT  if the thread has not been dequeued within the
 *                      specified timeout or if the function has been
 *                      invoked with @p TIME_IMMEDIATE as timeout
 *                      specification.
 *
 * @sclass
 */
msg_t chThdEnqueueTimeoutS(threads_queue_t *tqp, systime_t timeout) {

  if (TIME_IMMEDIATE == timeout)
    return MSG_TIMEOUT;

  queue_insert(currp, tqp);
  return chSchGoSleepTimeoutS(CH_STATE_QUEUED, timeout);
}
Example #13
0
void queue_move(thread_queue *dst, thread_queue *src, thread *th)
{
	if(th)
	{
		queue_remove(src, th);
		queue_insert(dst, th);
	}
}
Example #14
0
//costruisce una "Queue" a partire da un array. Usa il metodo insert
list* queue_build(void* new_object_array [], int object_number){
	list *new_list;
	new_list = build_list(new_object_array[0]);
	for (int i = 1; i<object_number; i++) {
		queue_insert(new_list, new_object_array[i]);	
	}
	
	return new_list;
}
Example #15
0
thread *queue_next(thread_queue *q)
{
	thread *next = q->first;
	if(next)
	{
		q->first = next->next;
		queue_insert(q, next);
	}
	return next;
}
Example #16
0
/* This function rotates the FIFO in the priority queue RDYQUE 'rq' for 
   the supplied 'priority'.  This involves removing the element from the
   head of the queue and then reinserting it at the tail/end of the queue.
*/
void
ready_queue_rotate(RDYQUE *rq,INT priority)
	{
	QUEUE	*entry, *queue;

	if ( !queue_empty_p(queue=&(rq->tskque[priority])) )
		{
		entry = queue_delete_next(queue);
		queue_insert(entry, queue);
		}
	}
Example #17
0
int alloc_enqueue_alloc_request (struct alloc_ctx *ctx, struct job *job)
{
    assert (job->state == FLUX_JOB_SCHED);
    if (!job->alloc_queued && !job->alloc_pending) {
        assert (job->aux_queue_handle == NULL);
        if (queue_insert (ctx->inqueue, job, &job->aux_queue_handle) < 0)
            return -1;
        job->alloc_queued = 1;
    }
    return 0;
}
Example #18
0
/*
**++
**  ROUTINE:	netlib___free_dnsreq
**
**  FUNCTIONAL DESCRIPTION:
**
**  	Frees a block of memory.
**
**  RETURNS:	void
**
**  PROTOTYPE:
**
**  	netlib___free_dnsreq(struct CMD *c)
**
**  IMPLICIT INPUTS:	None.
**
**  IMPLICIT OUTPUTS:	None.
**
**  COMPLETION CODES:	None.
**
**  SIDE EFFECTS:   	None.
**
**--
*/
unsigned int netlib___free_dnsreq (struct DNSREQ *dnsreq) {

    unsigned int aststat;

    BLOCK_ASTS(aststat);
    queue_insert(dnsreq, dnsreqque.tail);
    UNBLOCK_ASTS(aststat);

    return SS$_NORMAL;

} /* netlib___free_dnsreq */
Example #19
0
/*
**++
**  ROUTINE:	netlib___get_nameservers
**
**  FUNCTIONAL DESCRIPTION:
**
**  	Obtains the list of DNS servers configured for this TCP/IP package.
**
**  RETURNS:	int
**
**  PROTOTYPE:
**
**  	NETLIB___GET_NAMESERVERS nsq
**
**  IMPLICIT INPUTS:	None.
**
**  IMPLICIT OUTPUTS:	None.
**
**  COMPLETION CODES:
**
**
**  SIDE EFFECTS:   	None.
**
**--
*/
int netlib___get_nameservers (QUEUE *nsq) {

    struct NAMESERVER *ns;
    struct INADDRDEF a;
    struct CTX *tmpctx;
    struct dsc$descriptor dsc, lognamdsc;
    ITMLST lnmlst[2];
    char name[256], lognam[256], *cp, *anchor;
    unsigned int status, size, maxidx;
    unsigned short namlen;
    int index, i, remain;
    int v5, count;
    static unsigned int one = 1;

    tmpctx = 0;
    count = 0;

    ITMLST_INIT(lnmlst[0], LNM$_STRING, sizeof(name), name, &namlen);
    ITMLST_INIT(lnmlst[1], 0, 0, 0, 0);

    INIT_SDESC(lognamdsc, 0, lognam);

    for (v5 = 1; (count == 0) && (v5 >= 0); v5--) {
    	for (index = 0; index <= 16; index++) {
    	    lognamdsc.dsc$w_length = sprintf(lognam, (v5 == 0 ? "UCX$BIND_SERVER%03d" : "TCPIP$BIND_SERVER%03d"), index);
    	    status = sys$trnlnm(0, &nameserver_tabnam, &lognamdsc, 0, lnmlst);
    	    if (!OK(status) || namlen == 0) continue;
    	    for (anchor = name, remain = namlen; remain > 0;
    	    	    	    	    	remain -= i+1, anchor = cp+1) {
    	    	cp = memchr(anchor, ',', remain);
    	    	if (cp == 0) i = remain;
    	    	else i = cp - anchor;
    	    	INIT_SDESC(dsc, i, anchor);
    	    	if (!OK(netlib_strtoaddr(&dsc, &a))) {
    	    	    if (tmpctx == 0) {
    	    	    	if (!OK(netlib_socket(&tmpctx, 0, 0))) continue;
    	    	    }
    	    	    if (!OK(netlib_name_to_address(&tmpctx, 0, &dsc, &a, &one, 0,
    	    	    	    	0, 0, 0))) continue;
    	    	}
    	    	size = sizeof(struct NAMESERVER);
    	    	status = lib$get_vm(&size, &ns);
    	    	if (!OK(status)) break;
    	    	ns->addr = a;
    	    	queue_insert(ns, nsq->tail);
    	    	count += 1;
    	    }
    	}
    }

    if (tmpctx != 0) netlib_close(&tmpctx);
    return count;

} /* netlib___get_nameservers */
Example #20
0
/*
**++
**  ROUTINE:	netlib___free_ior
**
**  FUNCTIONAL DESCRIPTION:
**
**  	Frees a block of memory.
**
**  RETURNS:	void
**
**  PROTOTYPE:
**
**  	netlib___free_ior(struct CMD *c)
**
**  IMPLICIT INPUTS:	None.
**
**  IMPLICIT OUTPUTS:	None.
**
**  COMPLETION CODES:	None.
**
**  SIDE EFFECTS:   	None.
**
**--
*/
unsigned int netlib___free_ior (struct IOR *ior) {

    unsigned int aststat;

    BLOCK_ASTS(aststat);
    queue_insert(ior, iorque.tail);
    UNBLOCK_ASTS(aststat);

    return SS$_NORMAL;

} /* netlib___free_ior */
Example #21
0
/* reload_map_f callback
 * The job state/flags has been recreated by replaying the job's eventlog.
 * Enqueue the job and kick off actions appropriate for job's current state.
 */
static int restart_map_cb (struct job *job, void *arg)
{
    struct restart_ctx *ctx = arg;

    if (queue_insert (ctx->queue, job, &job->queue_handle) < 0)
        return -1;
    if (event_job_action (ctx->event_ctx, job) < 0) {
        flux_log_error (ctx->h, "%s: event_job_action id=%llu",
                        __FUNCTION__, (unsigned long long)job->id);
    }
    return 0;
}
Example #22
0
static huff_node_t * build_huff_tree(unsigned long int *frequency)
{
	int i;
	queue_t *queue = create_queue(sizeof(huff_node_t));
	for(i = 0; i < CHARS_NUM; i++)
	{
		if (frequency[i] > 0)
			queue_insert(queue, frequency[i], create_huff_node((char)(i - CHARS_NUM/2), frequency[i], NULL, NULL));
	}

	huff_node_t *left = NULL, *right = NULL;
	do
	{
		left = (huff_node_t*)queue_pop(queue);
		right = (huff_node_t*)queue_pop(queue);
		if (!right || !left) break;
		queue_insert(queue, left->frequency + right->frequency,
			create_huff_node((char)0, left->frequency + right->frequency, left, right));
	} while (left && right);

	return left;
}
Example #23
0
int queue_insert_safe(register QUEUE *queue, uchar *element)
{

  if (queue->elements == queue->max_elements)
  {
    if (!queue->auto_extent)
      return 2;
    else if (resize_queue(queue, queue->max_elements + queue->auto_extent))
      return 1;
  }
  
  queue_insert(queue, element);
  return 0;
}
Example #24
0
int main()
{
    instacktop = -1;
    outstacktop = -1;

    for(int i = 0; i<STACKSIZE; i++)
    {
        queue_insert(i);
    }

    printf("\n");

    queue_delete();

    return 0;
}
Example #25
0
struct node *create_node(struct rbt *tree, int vruntime, struct _sthread *thread){
	
	struct node *node = malloc(sizeof(struct node));

	node->color = RED;
	node->vruntime = vruntime;
	node->queue = create_queue();
	queue_insert(node->queue, thread);
	node->num_threads = 1;
	node->parent = tree->nil;	
	node->left = tree->nil;
	node->right = tree->nil;

	return node;

}
Example #26
0
/* filter thread */
void *filter(void *vargs)
{
    FilterArgs *args = (FilterArgs *) vargs;

    /* remove an item from the queue and print it out */
    int number = queue_remove(args);
    printf("%d\n", number);

    /* create a new thread for further filtering */

    /* create the output buffer, and the parameters to be passed to the filter
     * thread */
    int output[BUFSIZE];
    int occupied = 0,
        nextin   = 0,
        nextout  = 0;
    pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
    pthread_cond_t space = PTHREAD_COND_INITIALIZER;
    pthread_cond_t items = PTHREAD_COND_INITIALIZER;

    FilterArgs *output_args = getArgs(output, &occupied, &nextin, &nextout,
                                      &lock, &items, &space);

    /* create the first filter thread */
    pthread_t id;
    pthread_attr_t attrs;
    pthread_attr_init(&attrs);
    pthread_attr_setscope(&attrs, PTHREAD_SCOPE_SYSTEM);
    if (pthread_create(&id, &attrs, filter, output_args)) {
        printf("Error: Thread creation failed.");
        exit(1);
    }

    while (1) {
        int new_num = queue_remove(args);

        if ((new_num % number) == 0) {
            continue;
        }

        queue_insert(new_num, output_args);
        //printf("Receiving: %d\n", new_num);
    }

    return NULL;
}
Example #27
0
int lrucache_set(LRUCACHE* lrucache, char* key, char* value)
{
    char* k;
    
    while (map_length(lrucache->map) >= lrucache->size) {
        k = queue_peek(lrucache->queue);
        if (k == NULL) {
            break;
        } else {
            map_remove(lrucache->map, k);
        }
    }
    
    queue_insert(lrucache->queue, key);
    
    return map_set(lrucache->map, key, value);
}
Example #28
0
/* ping 帧永远插到最前面*/
void Http2Base::PushFrame(Http2_header *header){
    uint32_t id = HTTP2_ID(header->id);
    LOGD(DHTTP2, "push a frame [%d]:%d, size:%d, flags: %d\n", id, header->type, get24(header->length), header->flags);
    std::list<write_block>::insert_iterator i;
    if((http2_flag & HTTP2_FLAG_INITED) == 0){
        i = queue_end();
        goto ret;
    }
    switch(header->type){
    case PING_TYPE:
        for(i = queue_head(); i!= queue_end() ; i++){
            if(i->offset){
                continue;
            }
            const Http2_header* check = (const Http2_header*)i->buff;
            if(check->type != PING_TYPE){
                break;
            }
        }
        break;
    case HEADERS_TYPE:{
        auto j = queue_end();
        do{
            i = j--;
            if(j == queue_head() || j->offset){
                break;
            }

            const Http2_header* check = (const Http2_header*)j->buff;
            if(check->type != DATA_TYPE)
                break;
            uint32_t jid = HTTP2_ID(check->id);
            if(jid == 0 || jid == id)
                break;
        }while(true);
        break;
    }
    default:
        i = queue_end();
        break;
    }
ret:
    size_t length = sizeof(Http2_header) + get24(header->length);
    assert(i == queue_end() || i == queue_head() || i->offset == 0);
    queue_insert(i, write_block{header, length, 0});
}
static void ipphone_display_something(LinphoneCore *lc, const char *something){
	if(!strcmp(something, "User is busy."))
		something = "STATUS: BUSY        ";
	else
	if(!strcmp(something, "User does not want to be disturbed."))
		something = "STATUS: DECLINED    ";
	else
	if(!strcmp(something, "Could not reach destination."))
		something = "STATUS: UNREACHABLE ";
  else
  {
    printf("something_display:%s\n",something);
    return;
  }

	lcd_write_justified(LCD_WRITE_LEFT_JUSTIFIED, 1, something);
	queue_insert((main_queue_t *)lc->data, FSM_EVNT_LINPHONE_CALL_FAIL);
}
Example #30
0
/* Create queue of size jobs
 *   id: [0:size-1]
 */
struct queue *make_test_queue (int size)
{
    struct queue *q;
    flux_jobid_t id;

    q = queue_create ();
    if (!q)
        BAIL_OUT ("could not create queue");

    for (id = 0; id < size; id++) {
        struct job *j;
        if (!(j = job_create (id, 0, 0, 0, 0)))
            BAIL_OUT ("job_create failed");
        if (queue_insert (q, j) < 0)
            BAIL_OUT ("queue_insert failed");
    }
    return q;
}