コード例 #1
0
ファイル: submit.c プロジェクト: flux-framework/flux-core
int main (int argc, char *argv[])
{
    struct queue *queue;

    plan (NO_PLAN);

    if (!(queue = queue_create (true)))
        BAIL_OUT ("queue_create() failed");

    single_job_check (queue);
    multi_job_check (queue);

    queue_destroy (queue);
    done_testing ();
}
コード例 #2
0
ファイル: queue.c プロジェクト: j1111011/bdsl
int queue_push(pqueuenode header,pqueueelem elem){
	pqueuenode node = queue_create();
	if(header->_tailer == NULL){
		header->_tailer = node;
		header->_fronter = node;
		node->elem = *elem;
	}
	else {
		header->_tailer->_next = node;
		header->_tailer = node;
		node->elem = *elem;
	}
	header->size++;
	return 0;
}
コード例 #3
0
ファイル: queue.c プロジェクト: suzp1984/donkey
static void multi_thread_test(void)
{
	pthread_t consumer_t;
	pthread_t producer_t;

	Queue* queue = queue_create(NULL, NULL);

	pthread_create(&producer_t, NULL, producer_run, (void*)queue);
	pthread_create(&consumer_t, NULL, consumer_run, (void*)queue);

	pthread_join(consumer_t, NULL);
	pthread_join(producer_t, NULL);

	consumer_run((void*)queue);
}
コード例 #4
0
ファイル: lua-chan.c プロジェクト: lqefn/lua-chan
static int chan_new(lua_State* L)
{
    const char* name = _lua_arg_string(L, 1, NULL, _usage_new);
    int limit = _lua_arg_integer(L, 2, 1, 0, _usage_new);
    struct queue_t* q = queue_create(name, limit);
    if (!queues_add(q))
    {
        queue_destroy(q);
        lua_pushnil(L);
        lua_pushstring(L, "chan name duplicated");
        return 2;
    }
    chan_pushqueue(L, q);
    return 1;
}
コード例 #5
0
ファイル: task.c プロジェクト: PeterJohansson/speedy
/*!
 * Creates a task which encapsulates a service.
 * The reason for this is to make it possible to observe services and to track
 * dependencies. A task can be both an observer and a subject since it uses
 * C inheritance from the \c struct \c subject_t.
 *
 * \param service - A service that is going to be encapsulated into a task.
 *
 * \return A task which encapsulates a service.
 */
task_t * task_create(struct service_t *service, struct task_handler_t *handler)
{
    if (service->name != NULL) {
        task_t * this_ptr = (task_t*) malloc(sizeof(task_t));

        if (this_ptr != NULL) {
            this_ptr->task_id = hash_generate(service->name);
            this_ptr->dependency_queue = NULL;
            this_ptr->service = service;
            this_ptr->task_handler = handler;
            this_ptr->counter = 0;
            subject_init((subject_t*) this_ptr);
            observer_set_notify((observer_t*) this_ptr, task_notify);

            /* Check if there is a provides string, if there isn't any provides
             * string, use the task name instead for the generated id. */
            if (service->provides != NULL) {
                this_ptr->provides_id = hash_generate(service->provides);
            } else {
                this_ptr->provides_id = this_ptr->task_id;
            }

            if (service->dependency != NULL) {
                char **dependency_arg = (char**) service->dependency;
                task_dependency_t *dependency;

                this_ptr->dependency_queue = queue_create();

                while (*dependency_arg != NULL) {

                    printf("%s dep: %s\n",service->name, *dependency_arg);
                    dependency = (task_dependency_t*) malloc(sizeof(
                                  task_dependency_t));

                    dependency->name = *dependency_arg;
                    dependency->id = hash_generate(dependency->name);
                    dependency->task = NULL;

                    queue_push(this_ptr->dependency_queue, dependency);

                    dependency_arg++;
                }
            }
        }
        return this_ptr;
    }
    return NULL;
}
コード例 #6
0
ファイル: test.c プロジェクト: fonglee/just_for_fun
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;
}
コード例 #7
0
ファイル: queue_array.c プロジェクト: zmr961006/DSAA
int main(){
    queue *Q;
    Q = queue_create();
    int i ;
    for(i = 0;i < 5;i++){
        queue_in(Q,i);
    }
 
    for(i = 0;i < 5;i++){
        int test;
        test = queue_out(Q);
        printf("%d ",test);
        printf("\n");
    }

}
コード例 #8
0
ファイル: main.c プロジェクト: hbfhaapy/study
static void 
queue_test_enqueue(element_t e, 
  int (*cmp)(element_t, element_t, int), int elem_sz)
{
  queue_t q = queue_create(0);
  element_t elem;

  queue_enqueue(q, e);
  elem = queue_dequeue(q);

  assert(cmp(e, elem, elem_sz));

  queue_delete(&q);

  fprintf(stdout, "Testing queue enqueue and dequeue success ...\n");
}
コード例 #9
0
ファイル: inotify.c プロジェクト: Nymphetaminer/dsl-n55u
int inotifyStart()
{
    if (inotify_fd > 0)
    {
        queue_t q;
        q = queue_create (128);

        process_inotify_events (q, inotify_fd);
        //}
        printf ("\nTerminating\n");
        //close_inotify_fd (inotify_fd);
        queue_destroy (q);

    }
    return 0;
}
コード例 #10
0
ファイル: pool.c プロジェクト: robbassi/memory-pool
struct pool *allocate_pool(size_t size)
{
	debug("ALLOCATE-POOL", "allocating pool for size %d, pre-allocating %d slots (%d bytes)",
			size, prealloclen,  prealloclen * (size + headerlen));

	struct pool *p = (struct pool *) malloc(sizeof(struct pool));
	p->freed = queue_create();
	p->size = size;
	p->slots = prealloclen;
	p->cursor = 0;

	// pre-allocate some slots
	p->data = malloc((size + headerlen) * prealloclen);

	return p;
}
コード例 #11
0
ファイル: queue.c プロジェクト: jash16/algo
int main() {
    queue *q = queue_create(8, NULL);
    assert(q != NULL);
    int a = 10;
    int b = 20;
    enqueue(q, &a);
    enqueue(q, &b);

    printf("size=%d\n", queue_size(q));
    assert(queue_full(q) != true);
    printf("%d\n", *(int *)dequeue(q));
    printf("%d\n", *(int *)dequeue(q));
    assert(queue_empty(q) != false);
 
    queue_release(q);
}
コード例 #12
0
ファイル: ethread_pool.c プロジェクト: eyehere/libeasy
thread_pool_t *thread_pool_create(int size, thread_func_t func, void *data)
{
    int i = 0;
    thread_pool_t *thread_pool = NULL;

    if(size <= 0){
        return NULL;
    }
   
    thread_pool = (thread_pool_t *)MALLOC_WRAPPER(sizeof(thread_pool_t));
    if(NULL == thread_pool){
        printf("MALLOC_WRAPPER for thread pool failed.\n");
        return NULL;
    }

    thread_pool->threads = (thread_context_t *)MALLOC_WRAPPER(sizeof(thread_context_t) * size); 
    if(NULL == thread_pool->threads){
        printf("MALLOC_WRAPPER for thread_pool->threads failed.\n");
        thread_pool_destroy(&thread_pool);
        return NULL;
    }
    bzero(thread_pool->threads, sizeof(thread_context_t) * size);
    thread_pool->thread_num = size;

    thread_pool->queue = queue_create(1024);
    if(NULL == thread_pool->queue){
        printf("queue_create for thread_pool->queue failed.\n");
        thread_pool_destroy(&thread_pool);
        return NULL;
    }

    thread_pool->data = data;

    for(i = 0; i < size; i++){
        thread_pool->threads[i].id = i;
        thread_pool->threads[i].thread_pool = thread_pool;
        thread_pool->threads[i].work_continue = 1;
        if(0 != pthread_create(&thread_pool->threads[i].thread, 
                               NULL, func, &thread_pool->threads[i])){
            printf("create thread[%d] for thread pool failed.\n", i);
            thread_pool_destroy(&thread_pool);
            return NULL;
        }
    }
    
    return thread_pool;
}
コード例 #13
0
ファイル: queuetest.c プロジェクト: kcorman/cse451
int append_apply_test(){
  queue* q = queue_create();

  int x = 0;
  int y = 1;
  int z = 2;
  queue_append(q, &x);
  queue_append(q, &y);
  queue_append(q, &z);
  queue_append(q, &x);
  printf("Queue size is %zu\n", queue_size(q));
  
  int index = 0;
  queue_apply(q, show_one, &index);
  queue_destroy(q,false);
  return 0;
}
コード例 #14
0
int create_semaphore(int value)
{
    int sem_index = get_available_semaphore_slot();
    if (sem_index == -1) {
        printf("Error: maximum number of semaphores already in use.\n");
        return -1;
    }
    /* Create a new semaphore. */
    num_sem++;
    sem_t *sem = malloc(sizeof(sem_t));
    sem->init = value;
    sem->count = value;
    sem->wait_queue = queue_create();
    /* Insert the semaphore in the first empty slot in the table. */
    sem_table[sem_index] = sem;
    return sem_index;
}
コード例 #15
0
ファイル: myfs.c プロジェクト: shadowpt/sampleProject2
int my_init_lib()
{
	char CLIENT_SOCK[] = "/tmp/clientXXXXXX";
	if(mkstemp(CLIENT_SOCK) < 0) {
		printf("[my_init_lib] Unable to create client socket.\n");
		return -1;
	}
	
	if(snfs_init(CLIENT_SOCK, SERVER_SOCK) < 0) {
		printf("[my_init_lib] Unable to initialize SNFS API.\n");
		return -1;
	}
	Open_files_list = queue_create();
	Lib_initted = 1;
	
	return 0;
}
コード例 #16
0
ファイル: queuetest.c プロジェクト: kcorman/cse451
int remove_value_test(){
  queue *q = queue_create();
  int x = 0, y = 1, z = 2;
  queue_append(q, &x);
  queue_append(q, &y);
  queue_append(q, &z);
  assert(queue_size(q) == 3);
  int *ret_val;
  queue_remove(q, (queue_element **)&ret_val); 
  assert(*ret_val == x);
  queue_remove(q, (queue_element **)&ret_val); 
  assert(*ret_val == y);
  queue_remove(q, (queue_element **)&ret_val); 
  assert(*ret_val == z);
  queue_destroy(q,false);
  return 0;
}
コード例 #17
0
ファイル: thread_pool.c プロジェクト: PeterJohansson/speedy
thread_pool_t *thread_pool_create(unsigned int threads,
                                  int (*task_exec)(void *task))
{
    thread_pool_t *this_ptr = (thread_pool_t*) malloc(sizeof(thread_pool_t));
    int i;

    if ((this_ptr != NULL) && (task_exec != NULL)) {
        this_ptr->task_exec = task_exec;
        this_ptr->threads = (pthread_t*) malloc(sizeof(pthread_t) * threads - 1);
        this_ptr->condititon = (pthread_cond_t*) malloc(sizeof(pthread_cond_t));
        this_ptr->mutex = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t));
        this_ptr->queue = queue_create();

        if ((this_ptr->queue != NULL) && (this_ptr->threads != NULL) &&
            (this_ptr->condititon != NULL) && (this_ptr->mutex != NULL)) {

            this_ptr->continue_thread_pool = true;
            if (threads > 0) {
                this_ptr->thread_size = threads - 1;
            } else {
                this_ptr->thread_size = 0;
            }

            this_ptr->passive_threads = 0;
            this_ptr->tasks = 0;

            pthread_cond_init(this_ptr->condititon, NULL);
            pthread_mutex_init(this_ptr->mutex, NULL);

            for (i = 0; i < this_ptr->thread_size; i++) {
                pthread_create(&this_ptr->threads[i], NULL,
                               thread_pool_run_thread, this_ptr);
            }

        } else {
            free(this_ptr->threads);
            free(this_ptr->condititon);
            free(this_ptr->mutex);
            queue_destroy(this_ptr->queue);
            free(this_ptr);
            this_ptr = NULL;
        }
    }
    return this_ptr;
}
コード例 #18
0
ファイル: hla_double_cache.c プロジェクト: Lichtavat/TCAX
TCAS_Error_Code libtcas_double_cache_init(const char *filename, tcas_u32 fpsNumerator, tcas_u32 fpsDenominator, tcas_u16 width, tcas_u16 height, int maxFrameCount, int maxFrameChunkCount, int fileCacheSize, TCAS_pDoubleCache pDoubleCache) {
    TCAS_Error_Code error;
    error = libtcas_frame_chunks_cache_init(filename, fpsNumerator, fpsDenominator, width, height, maxFrameChunkCount, fileCacheSize, &pDoubleCache->dcpArgs.fcc);
    if (tcas_error_success != error)
        return error;
    pDoubleCache->dcpArgs.width = width;
    pDoubleCache->dcpArgs.height = height;
    pDoubleCache->minFrame = (tcas_u32)((tcas_u64)pDoubleCache->dcpArgs.fcc.fccpArgs.header.minTime * fpsNumerator / (fpsDenominator * 1000)) + 1;
    pDoubleCache->maxFrame = (tcas_u32)((tcas_u64)pDoubleCache->dcpArgs.fcc.fccpArgs.header.maxTime * fpsNumerator / (fpsDenominator * 1000)) + 1;
    pDoubleCache->maxFrameCount = maxFrameCount;
    queue_create(&pDoubleCache->qFrames, sizeof(TCAS_QueuedFrame), pDoubleCache->maxFrameCount, NULL, NULL);    /* stores pointers to frame buffers */
    pDoubleCache->semQueue = CreateSemaphore(NULL, 0, pDoubleCache->maxFrameCount, NULL);
    pDoubleCache->semFrames = CreateSemaphore(NULL, 0, pDoubleCache->maxFrameCount, NULL);
    InitializeCriticalSection(&pDoubleCache->lock);
    pDoubleCache->active = 1;
    pDoubleCache->tdWorker = CreateThread(NULL, 0, _libtcas_create_frame_with_chunks_cached_worker_proc, pDoubleCache, 0, &pDoubleCache->threadID);
    return tcas_error_success;
}
コード例 #19
0
ファイル: list.c プロジェクト: grondo/flux-core
/* 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;
}
コード例 #20
0
ファイル: main.c プロジェクト: BelaBelphegor/Crawler-JS
int		main(void)
{
	t_logger	*logger;
	t_queue		*queue;
	int			a;
	int			*b;

	a = 5;
	queue = queue_create();
	if (queue_enqueue(queue, &a) < 0)
		return (-1);	
	b = (int *)queue_dequeue(queue);
	queue_destroy(queue);
	logger = logger_create();
	logger_write("Ceci est une gestion d\'erreur.\n");
	logger_destroy();
	return (0);
}
コード例 #21
0
ファイル: queue-00.c プロジェクト: alperakcan/algorithms
int main (int argc, char *argv[])
{
	int i;
	struct queue *queue;
	queue = queue_create();
	if (queue == NULL) {
		return -1;
	}
	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "-") == 0) {
			printf("%s ", (char *) queue_dequeue(queue));
		} else {
			queue_enqueue(queue, argv[i]);
		}
	}
	queue_destroy(queue);
	return 0;
}
コード例 #22
0
void crearNivel(t_list* lNiveles, tNivel* pNivelNuevo, int socket, char *nombreNivel, tInfoNivel *pInfoNivel) {
	pNivelNuevo->nombre = malloc(strlen(nombreNivel) + 1);
	strcpy(pNivelNuevo->nombre, nombreNivel);
	pNivelNuevo->cListos 	 = queue_create();
	pNivelNuevo->lBloqueados = list_create();
	pNivelNuevo->socket 	 = socket;
	pNivelNuevo->quantum 	 = pInfoNivel->quantum;
	pNivelNuevo->algoritmo 	 = pInfoNivel->algoritmo;
	pNivelNuevo->delay 		 = pInfoNivel->delay;
	pNivelNuevo->maxSock 	 = socket;
	pNivelNuevo->rdDefault	 = 999;
	pthread_cond_init(&(pNivelNuevo->hayPersonajes), NULL);
	FD_ZERO(&(pNivelNuevo->masterfds));

	pthread_mutex_lock(&mtxlNiveles);
	list_add(lNiveles, pNivelNuevo);
	pthread_mutex_unlock(&mtxlNiveles);
}
コード例 #23
0
ファイル: gprs.c プロジェクト: fuosck/gprs-of-sim928a
void gprs_init(void)
{
    sim928a_gprs_init();
    gprs_uart_init();
    queue_create(&gprs_queue);         // 初始化,构造空队
    
#if GPRS_TEST
    gprs_config_t gprs_test_config;
    
#define BUILD_IP_ADDRESS(b3, b2, b1, b0) ((uint32_t)(b3) << 24) | \
     ((uint32_t)(b2) << 16) | ((uint32_t)(b1) << 8) | ((uint32_t)(b0))        
        
    gprs_test_config.ip_addr = BUILD_IP_ADDRESS(58, 214, 236, 152);
    gprs_test_config.port = 8066;
    gprs_test_config.type_cb = gprs_test_send_cb;
    gprs_test_config.data_cb = gprs_test_receive_cb;    
    gprs_config(&gprs_test_config);
    
    uint8_t DATA[4] = {"1234"};
    gprs_set_mode(CONTINE_MODE);
    gprs_send(DATA, 0x04, 1, 0);
    gprs_send(DATA, 0x04, 2, 0);
    gprs_send(DATA, 0x04, 3, 0);
    gprs_send(DATA, 0x04, 4, 0);
    gprs_send(DATA, 0x04, 4, 1000);
    gprs_send(DATA, 0x04, 4, 1000);
    gprs_send(DATA, 0x04, 4, 1000);
#endif
    
    gprs_flush_receive_buf();
    
    wsnos_init_printf(NULL, NULL);
    
    // 创建任务
    osel_task_tcb *gprs_task_handle = osel_task_create(&gprs_task, 
                                                       GPRS_TASK_PRIO);
    // 消息绑定
    osel_subscribe(gprs_task_handle, GPRS_SEND_EVENT);
    osel_subscribe(gprs_task_handle, GPRS_POLL_EVENT);
    osel_subscribe(gprs_task_handle, GPRS_SEND_CMD_EVENT);
    osel_subscribe(gprs_task_handle, GPRS_RESPONSE_EVENT);
    
    osel_post(GPRS_POLL_EVENT, NULL, OSEL_EVENT_PRIO_LOW);
}
コード例 #24
0
ファイル: events.c プロジェクト: jimmy-zhao-tainio/project.m
NetPollEvents *net_poll_events_create (void)
{
        NetPollEvents *events;
        struct epoll_event event = { 0 };
        
        if (!(events = memory_create (sizeof (NetPollEvents)))) {
                error_code (FunctionCall, 1);
                return NULL;
        }
        events->file = -1;
        events->internal_event = -1;
        events->event_index = 0;
        events->event_count = 0;
        events->queue_got_events = false;
        if (!queue_create (&events->queue, 
                           1024,
                           sizeof (NetPollEvent),
                           QUEUE_SIZE_DYNAMIC)) {
                memory_destroy (events);
                error_code (FunctionCall, 2);
                return NULL;
        }
        if ((events->file = epoll_create1 (0)) == -1) {
                net_poll_events_destroy (events);
                error_code (SystemCall, 1);
                return NULL;
        }
        if ((events->internal_event = eventfd (0, EFD_NONBLOCK)) == -1) {
                error_code (SystemCall, 2);
                net_poll_events_destroy (events);
                return NULL;
        }
        event.data.ptr = &events->internal_event;
        event.events = EPOLLIN | EPOLLET;
        if (epoll_ctl (events->file, 
                       EPOLL_CTL_ADD, 
                       events->internal_event, 
                       &event) == -1) {
                net_poll_events_destroy (events);
                error_code (SystemCall, 3);
                return NULL;
        }
        return events;
}
コード例 #25
0
ファイル: utils.c プロジェクト: shenyanjun/libevlite
struct msgqueue * msgqueue_create( uint32_t size )
{
    struct msgqueue * self = NULL;

    self = (struct msgqueue *)malloc( sizeof(struct msgqueue) );
    if ( self )
    {
        self->popfd = -1;
        self->pushfd = -1;
        pthread_spin_init( &self->lock, 0 );
    
        self->queue = queue_create( size );
        if ( self->queue == NULL )
        {
            msgqueue_destroy( self );
            self = NULL;
        }
        else
        {
            int32_t rc = -1;
            int32_t fds[2] = { -1, -1 };

            rc = socketpair( AF_UNIX, SOCK_STREAM, 0, fds );
            if ( rc == -1 )
            {
                msgqueue_destroy( self );
                self = NULL;
            }
            else
            {
                self->popfd = fds[0];
                self->pushfd = fds[1];
				
#ifdef O_NOATIME
				// linux在读pipe的时候会更新访问时间, touch_atime(), 这个的开销也不小
				fcntl( self->popfd, F_SETFL, O_NOATIME );
#endif
            }
        }
    }

    return self;
}
コード例 #26
0
ファイル: commands.c プロジェクト: hyper/rqd
static void cmdBroadcast(void *base)
{
	node_t *node = (node_t *) base;
	queue_t *q = NULL;
	message_t *msg;
	
 	assert(node);
	assert(node->handle >= 0);
	assert(node->sysdata);
	logger(node->sysdata->logging, 3,
		"node:%d BROADCAST (flags:%x, mask:%x)",
		node->handle, node->data.flags, node->data.mask);

	// do we have a queue name, or a qid?
	if (BIT_TEST(node->data.mask, DATA_MASK_QUEUE) || BIT_TEST(node->data.mask, DATA_MASK_QUEUEID)) {

		if (BIT_TEST(node->data.mask, DATA_MASK_QUEUE)) {
			q = queue_get_name(node->sysdata->queues, expbuf_string(&node->data.queue));
		}
		else if (BIT_TEST(node->data.mask, DATA_MASK_QUEUEID)) {
			q = queue_get_id(node->sysdata->queues, node->data.qid);
		}

		if (q == NULL) {
			q = queue_create(node->sysdata, expbuf_string(&node->data.queue));
		}

		// by this point, we should have 'q'.
		assert(q);
		
		// create message object.
		msg = next_message(node);
		assert(msg);

		// now that we have a message structure completely filled out with the
		// data from the node, then we need to do something with it.
		assert(0);
	}
	else {
		// we didn't have a queue name, or a queue id.   We need to handle this gracefully.
		assert(0);
	}
}
コード例 #27
0
ファイル: fs_queue.c プロジェクト: Zeke-OS/zeke
struct fs_queue * fs_queue_create(size_t nr_blocks, size_t block_size)
{
    struct buf * bp;
    struct fs_queue * fsq;

    bp = geteblk(sizeof(struct fs_queue)
                 + nr_blocks * (sizeof(struct fs_queue_packet) + block_size));
    if (!bp)
        return NULL;

    fsq = (struct fs_queue *)(bp->b_data);

    fsq->qcb = queue_create(fsq->packet, block_size, nr_blocks);
    mtx_init(&fsq->wr_lock, MTX_TYPE_TICKET, MTX_OPT_DEFAULT);
    mtx_init(&fsq->rd_lock, MTX_TYPE_TICKET, MTX_OPT_DEFAULT);
    fsq->bp = bp;

    return fsq;
}
コード例 #28
0
liberadosNoSerializadoStruct *desserializador_liberados(void *data,int16_t length)
{
		liberadosNoSerializadoStruct *self = malloc(sizeof(liberadosNoSerializadoStruct));
        recursoStruct *elem;
        int32_t i, offset = 0, tmp_size = 0;
        self->cola=queue_create();

        int32_t tamanioCola=length;

        for (i = 0; i < tamanioCola; i++)
        {
        		offset += tmp_size;
                elem = malloc(sizeof(recursoStruct));
                memcpy(elem,data + offset, sizeof(recursoStruct));
                queue_push(self->cola,elem);
                tmp_size=sizeof(recursoStruct);
        }
        return self;
}
コード例 #29
0
ファイル: ipc_helper.c プロジェクト: Blurjp/Swimart_ORB
T_QUEUE ipc_setup(void)
{
	/* Framework initializations */
	T_QUEUE queue = queue_create(32, NULL);
	assert(queue);

	/* Initialize IPC: channels have been chosen arbitrarily */
	ipc_init(0, 5, 1, 6, CPU_ID_ARC);
	ipc_async_init(queue);

	set_cpu_id(CPU_ID_QUARK);
	set_cpu_message_sender(CPU_ID_ARC, ipc_async_send_message);
	set_cpu_free_handler(CPU_ID_ARC, ipc_async_free_message);
#ifdef CONFIG_IPC_UART
	set_cpu_message_sender(CPU_ID_BLE, send_message_ipc_uart);
	set_cpu_free_handler(CPU_ID_BLE, free_message_ipc_uart);
#endif
	return queue;
}
コード例 #30
0
ファイル: timer.c プロジェクト: ljvblfz/clearrtos
error_t module_timer (system_state_t _state)
{
    usize_t idx;
    error_t ecode;
    static task_handle_t handle;

    if (STATE_UP == _state) {
        STACK_DECLARE (stack, CONFIG_TIMER_TASK_STACK_SIZE);
        QUEUE_BUFFER_DECLARE (buffer, sizeof (timer_handle_t),
                              CONFIG_TIMER_QUEUE_SIZE);

        ecode = queue_create ("Timer", &g_timer_queue, buffer,
                              sizeof (timer_handle_t), CONFIG_TIMER_QUEUE_SIZE);
        if (0 != ecode) {
            return ecode;
        }
        ecode = task_create (&handle, "Timer", CONFIG_TIMER_TASK_PRIORITY,
                             stack, sizeof (stack));
        if (0 != ecode) {
            return ecode;
        }
        ecode = task_start (handle, task_timer, g_timer_queue);
        if (0 != ecode) {
            return ecode;
        }
    }
    else if (STATE_DOWN == _state) {
        if (0 != task_delete (handle)) {
            console_print ("Error: cannot delete task \"Timer\"");
        }
        if (0 != queue_delete (g_timer_queue)) {
            console_print ("Error: cannot delete queue \"Timer\"");
        }
    }
    else if (STATE_DESTROYING == _state) {
        for (idx = 0; idx <= BUCKET_LAST_INDEX; ++ idx) {
            (void) dll_traverse (&g_buckets [idx].dll_, timer_check_for_each, 0);
        }
        (void) dll_traverse (&g_inactive_timer, timer_check_for_each, 0);
    }
    return 0;
}