void app_main() { #if sem_test sem_init(&sem, (U8 *)"sem1", 1); #endif #if mutex_test mutex_init(&mutex, (U8 *)"mutex1"); #endif #if msg_queue_test msg_queue_create(&my_queue, 100, (U8 *)"my_queue"); msg_queue_create(&my_queue1, 100, (U8 *)"my_queue1"); msg_queue_create(&my_queue2, 100, (U8 *)"my_queue2"); msg1.buff = (U8 *)"1aaa"; msg2.buff = (U8 *)"2bbb"; msg3.buff = (U8 *)"3ccc"; msg4.buff = (U8 *)"4aaa"; msg5.buff = (U8 *)"5bbb"; msg6.buff = (U8 *)"6ccc"; msg7.buff = (U8 *)"7aaa"; msg8.buff = (U8 *)"8bbb"; msg9.buff = (U8 *)"9ccc"; #endif task_create(&tcb1, (U8 *)"task1", task1, NULL, stack1, STACK_SIZE, 3, 1); task_create(&tcb2, (U8 *)"task2", task2, NULL, stack2, STACK_SIZE, 4, 1); //task_create(&tcb3, (U8 *)"task3", task3, NULL, stack3, STACK_SIZE, 3, 1); //task_create(&tcb4, (U8 *)"task4", task4, NULL, stack4, STACK_SIZE, 1, 1); }
static void tccgui_init() { script_key_mq = (struct msg_queue *) msg_queue_create("script_key", 10); find_scripts(); run_startup_script(); menu_add("Scripts", tccgui_menu, MIN(script_cnt, COUNT(tccgui_menu))); }
/** Create and initialise a +Client+ structure to represent a single client. * * \param client_sock the socket associated to the client transmission * (from libocomm). The client_sock should be attached to an active * client that has been accepted by the server socket. * * \param page_size the page size for the underlying memory store for * buffering received measurements. * \param file_name save measurements to a file with this name. * \param server_port the port of the downstream OML server * \param server_address the address of the downstream OML Server * * \return a new Client structure */ Client* client_new (Socket* client_sock, int page_size, char* file_name, int server_port, char* server_address) { Client* self = (Client *)oml_malloc(sizeof(Client)); memset(self, 0, sizeof(Client)); self->state = C_HEADER; self->downstream_port = server_port; self->downstream_addr = oml_strndup (server_address, strlen (server_address)); self->mbuf = mbuf_create (); self->headers = NULL; self->msg_start = dummy_read_msg_start; self->messages = msg_queue_create (); self->cbuf = cbuf_create (page_size); self->file = fopen(file_name, "wa"); self->file_name = oml_strndup (file_name, strlen (file_name)); self->recv_socket = client_sock; /* FIXME: Return value checking */ pthread_mutex_init (&self->mutex, NULL); pthread_cond_init (&self->condvar, NULL); return self; }
int main(void) { pthread_t t_put[5] = {0}; pthread_t t_fetch; msg_queue_t* q; void* t_ret; int i; signal(SIGTERM, on_sigterm); signal(SIGINT, on_sigterm); srand(time(NULL)); if(!(q = msg_queue_create(2))) { printf("msg_queue_errno() = %s\n", msg_queue_errno2str(msg_queue_errno())); return(1); } for(i = 0; i < ARRAY_COUNT(t_put); ++ i) { if(pthread_create(&t_put[i], NULL, put_thread, q)) { terminate = 1; break; } } if(!pthread_create(&t_fetch, NULL, fetch_thread, q)) { sleep(15); terminate = 1; pthread_join(t_fetch, &t_ret); } terminate = 1; for(i = 0; t_put[i] && i < ARRAY_COUNT(t_put); ++ i) { pthread_join(t_put[i], &t_ret); } msg_queue_destroy(q); return(0); }