示例#1
0
void
test_split (void) {
	char str0[] = "\x01";
	char str1[] = "\x01\x01x\x01y\x01z\x01xy\x01yz";
	char str2[] = "buffer one\n\x01\x02\nend buffer\n";
	char str3[] = "buffer two\n\x01\x02\nend buffer\n";

	deque_t *split = (deque_t *)NULL;

	cbuffer_t *buf1 = (cbuffer_t *)NULL;
	cbuffer_t *buf2 = (cbuffer_t *)NULL;
	cbuffer_t *buf3 = (cbuffer_t *)NULL;

	buf1 = cbuf_new ();
	buf2 = cbuf_new ();
	buf3 = cbuf_new ();

	cbuf_import (buf1, str1, strlen (str1));
	cbuf_import (buf2, str2, strlen (str2));
	cbuf_import (buf3, str3, strlen (str3));

	split = cbuf_split (buf1, (void *)str0, 1);
	printf ("test_split(): len = %d\n", deque_length (split));

	deque_push (split, buf2);
	printf ("test_split(): len = %d\n", deque_length (split));

	deque_push (split, buf3);
	printf ("test_split(): len = %d\n", deque_length (split));

	cbuf_delete (buf1);
	deque_delete (split, cbuf_delete_callback);
}
示例#2
0
pth_pool_t *
pth_pool_new (pth_attri_t *attrs, CAF_PT_PROTOTYPE(rtn), int count) {
	pth_pool_t *ptp = (pth_pool_t *)NULL;
	pthread_t *thr = (pthread_t *)NULL;
	int rc = 0;
	int c = 0;
	if (attrs != (pth_attri_t *)NULL) {
		ptp = (pth_pool_t *)xmalloc (CAF_PT_POOL_SZ);
		if (ptp != (pth_pool_t *)NULL && count > 0) {
			ptp->attri = attrs;
			ptp->rtn = rtn;
			ptp->threads = deque_create ();
			for (c = 1; c <= count; c++) {
				thr = (pthread_t *)xmalloc (sizeof(pthread_t));
				if (thr != (pthread_t *)NULL) {
					if ((deque_push (ptp->threads, thr)) != (deque_t *)NULL) {
						rc++;
					}
				}
			}
			ptp->count = rc;
		}
	}
	return ptp;
}
示例#3
0
int
pth_pool_add (pth_pool_t *p, pth_attri_t *attrs, CAF_PT_PROTOTYPE(rtn),
              void *arg) {
	pth_pool_t *pool = (pth_pool_t *)NULL;
	int rt = CAF_ERROR;
	pthread_t *thr;
	if (rtn != NULL
		&& p != (pth_pool_t *)NULL
		&& p->threads != (deque_t *)NULL) {
		thr = (pthread_t *)xmalloc (sizeof (pthread_t));
		if (thr != (pthread_t *)NULL) {
			if (attrs != (pth_attri_t *)NULL) {
				rt = pthread_create (thr, &(attrs->attr), rtn,
									 arg);
			} else {
				rt = pthread_create (thr, &(pool->attri->attr), rtn,
									 arg);
			}
			if (rt == 0) {
				deque_push (pool->threads, thr);
			}
		}
	}
	return rt;
}
示例#4
0
int
caf_dsm_add (caf_dsm_t *m, caf_dsm_state_t *s) {
	if (s != (caf_dsm_state_t *)NULL && m != (caf_dsm_t *)NULL) {
		if ((deque_push (m->m_state, (void *)s)) != (deque_t *)NULL) {
			return CAF_OK;
		}
	}
	return CAF_ERROR;
}
示例#5
0
int thread_pool_add_task(thread_pool_t *self, thread_func_t thread_func, void *arg){
	task_node_t  *task = NULL;
	
	if (self->task_deque->deque_len > MAX_TASK_NUM){
		return -1;
	}
	task = (task_node_t*)malloc(sizeof(task_node_t));
	task->arg = arg;
	task->thread_func = thread_func;
	task->next = NULL;
	/*将任务加入队列*/
	pthread_mutex_lock (&self->task_deque->mutex);
	deque_push(self->task_deque, task);
	/*唤醒一个工作线程*/
	task_sem_signal(self->task_sem);
	pthread_mutex_unlock(&self->task_deque->mutex);
	return 0;
}
示例#6
0
static inline void rt_schedule_async(hclib_task_t *async_task,
        hclib_worker_state *ws) {
#ifdef VERBOSE
    fprintf(stderr, "rt_schedule_async: async_task=%p locale=%p\n", async_task,
            async_task->locale);
#endif

#ifdef HCLIB_STATS
    worker_stats[ws->id].scheduled_tasks++;
#endif

    if (async_task->locale) {
        // If task was explicitly created at a locale, place it there
        if (!deque_push_locale(ws, async_task->locale, async_task)) {
            assert(false);
        }
    } else {
        /*
         * If no explicit locale was provided, place it at a default location.
         * In the old implementation, each worker had the concept of a 'current'
         * locale. For now we just place at locale 0 by default, but having a
         * current locale might be a good thing to implement in the future.
         * TODO.
         */
        const int wid = hclib_get_current_worker();
#ifdef VERBOSE
        fprintf(stderr, "rt_schedule_async: scheduling on worker wid=%d "
                "hc_context=%p hc_context->graph=%p\n", wid, hc_context,
                hc_context->graph);
#endif
        hclib_locale_t *default_locale = hc_context->graph->locales + 0;
        assert(default_locale->reachable);
        if (!deque_push(&(default_locale->deques[wid].deque),
                    async_task)) {
            // Deque is full
            assert(false);
        }
#ifdef VERBOSE
        fprintf(stderr, "rt_schedule_async: finished scheduling on worker "
                "wid=%d\n", wid);
#endif
    }
}
示例#7
0
int deque_push_place(hclib_worker_state *ws, place_t *pl, void *ele) {
    hc_deque_t *deq = get_deque_place(ws, pl);
    return deque_push(&deq->deque, ele);
}