Example #1
0
static int event_queue_wait(event_queue_t * peq)
{
    int ret = 0;
    cmd_event_t * pe;
    struct timespec tsp;
    long seconds = 50;
    EVENT_LOCK(peq);
    do {
     //   printf("\n1\n");
        if ((pe = min_heap_top(peq->heap)) != NULL)
            break;
     //   printf("\n2\n");
        peq->event_state = EVENT_SLEEP;
    //    printf("\n3\n");
     //   pthread_cond_wait(&peq->cond, &peq->lock);
        maketimeout(&tsp, seconds);
        pthread_cond_timedwait(&peq->cond, &peq->lock, &tsp);
     //   printf("\n4\n");
        if ((pe = min_heap_top(peq->heap)) == NULL) {
            log_error(LOG_DEBUG, "pthread_cond_wait");
            ret = -1;
        }
      //  printf("\n5\n");
        peq->event_state = EVENT_ALIVE;
    } while (0);
    EVENT_UNLOCK(peq);
    return ret;
}
Example #2
0
FBCALL int fb_GfxEvent(EVENT *event)
{
	EVENT *e = NULL;

	FB_GRAPHICS_LOCK( );

	if (!__fb_gfx) {
		FB_GRAPHICS_UNLOCK( );
		return FB_FALSE;
	}

	EVENT_LOCK();
	if (__fb_gfx->event_head != __fb_gfx->event_tail) {
		e = &__fb_gfx->event_queue[__fb_gfx->event_head];
		if (event)
			__fb_gfx->event_head = (__fb_gfx->event_head + 1) & (MAX_EVENTS - 1);
	}
	if (e && event)
		fb_hMemCpy(event, e, sizeof(EVENT));
	EVENT_UNLOCK();

	FB_GRAPHICS_UNLOCK( );

	return e ? FB_TRUE : FB_FALSE;
}
Example #3
0
static inline void del_all_events(int cnt, cmd_event_t * events[], event_queue_t * peq)
{
    EVENT_LOCK(peq);
    while ((cnt)--) {
        cmd_event_del(peq, events[cnt]);
    }
    EVENT_UNLOCK(peq);
}
Example #4
0
static inline cmd_event_t * event_queue_pop(event_queue_t * pq)
{
    cmd_event_t * pe;

    EVENT_LOCK(pq);
    pe = min_heap_pop(pq->heap);
    EVENT_UNLOCK(pq);
    return pe;
}
Example #5
0
/*:::::*/
void fb_hPostEvent(EVENT *e)
{
	EVENT *slot;
	
	EVENT_LOCK();
	slot = &__fb_gfx->event_queue[__fb_gfx->event_tail];
	fb_hMemCpy(slot, e, sizeof(EVENT));
	if (((__fb_gfx->event_tail + 1) & (MAX_EVENTS - 1)) == __fb_gfx->event_head)
		__fb_gfx->event_head = (__fb_gfx->event_head + 1) & (MAX_EVENTS - 1);
	__fb_gfx->event_tail = (__fb_gfx->event_tail + 1) & (MAX_EVENTS - 1);
	EVENT_UNLOCK();
}
Example #6
0
static inline int del_events(int cnt, cmd_event_t * events[], event_queue_t * peq)
{
    int c = 0;
    if (cnt >= MAX_DEL_EVENTS_CNTS) {

        EVENT_LOCK(peq);
        while(c < cnt) {
            cmd_event_del(peq, events[c]);
            c++;
        }
        EVENT_UNLOCK(peq);
    }
    return c;
}
Example #7
0
int event_queue_push(event_level_t          level,
                     struct connectSock *   psock,
                     event_queue_pt         pt,
 //                    uint8_t                cmd,
 //                    uint16_t               opt_code,
                     void *              pdata,
                     int                    siz)
{
    int ret = 0;
    //int max_conn = 0;
    uint32_t weight = 0;
    struct cmd_event * pe;
    event_queue_t * peq;
    uint16_t * p_value;
    timestamp++;
    //printf("\ntimestamp = %u\n", timestamp);
    if (siz > MAX_EBUF_SIZ) {
        log_error(LOG_NOTICE, "MAX_EBUF_SIZ");
        return -1;
    }

    weight = ++weightness;

    if (psock != NULL) {
        weight = psock->addr;
        p_value = &psock->event_cnt;
    } else {
        p_value = &pserial_des->event_cnt;
    }

    peq = pq + get_tindex(weight);          //平衡相应的队列


    EVENT_LOCK(peq);
    debug_event("\nstart push ok line = %d\n", __LINE__);
    do {
        pe = cmd_event_new(peq, siz);


        if (pe == NULL) {
            if (psock == NULL) {
                peq = pq + get_tindex(weight + 1);
                pe = cmd_event_new(peq, siz);
            }
            if (pe == NULL) {
                ret = -1;
                log_error(LOG_NOTICE, "cmd queue full queue.no = %d", peq->queue_no);
                break;
            }
        }



        pe->level = level;
 //      pe->cmd = cmd;
 //       pe->opt_code = opt_code;
        pe->weight_value = ++(*p_value);
        pe->timestamp = timestamp;
        pe->cb = pt;
        pe->psock = psock;
        memcpy(pe->buffer, pdata, siz);

        //printf("\npe->level = %d, pe->timestamp = %u\n",level, timestamp);
        if (min_heap_insert(peq->heap, pe) == NULL) {
            log_error(LOG_ERROR, "min_heap_inisert !!!!");
            cmd_event_del(peq, pe);
        }


    } while (0);
//     printf("\nccc\n");
    event_queue_wakeup(peq);
    debug_event("\nend push ok line = %d\n", __LINE__);
    EVENT_UNLOCK(peq);

    return ret;
}