//----------------------------------------------------------------------------------------------------// // Definitions //----------------------------------------------------------------------------------------------------// void pthread_init (void) { int i; bss_mem_init (); default_attr.schedparam.sched_priority = PRIO_LOWEST; // Defaults to the lowest priority. default_attr.contentionscope = PTHREAD_SCOPE_SYSTEM; // Only system scope supported. default_attr.detachstate = PTHREAD_CREATE_DETACHED; // Detach on thread exit default_attr.stackaddr = NULL; default_attr.stacksize = 0; for (i=0; i<MAX_PTHREADS; i++) { thread_info_list[i].is_allocated = 0; thread_info_list[i].state = PTHREAD_STATE_DETACHED; thread_info_list[i].join_thread = NULL; thread_info_list[i].tid = (pthread_t)i; // Can statically allocate thread ids. thread_info_list[i].mem_id = -1; // BSS memory unallocated. thread_info_list[i].thread_attr = default_attr; thread_info_list[i].parent = NULL; alloc_q (&thread_info_list[i].joinq,1,PTHREAD_JOIN_Q,sizeof(char),0); thread_info_list[i].joinq.items = &(thread_info_list[i].joinq_mem); } #ifdef CONFIG_PTHREAD_MUTEX pthread_mutex_heap_init(); #endif }
void readyq_init() { unsigned int i = 0 ; for (;i < N_PRIO; i++ ) { alloc_q (&ready_q[i], MAX_READYQ, READY_Q, sizeof(char), i); } }
//----------------------------------------------------------------------------------------------------// // Definitions //----------------------------------------------------------------------------------------------------// void pthread_mutex_heap_init() { unsigned int i = 0 ; for (; i < MAX_PTHREAD_MUTEX; i++ ) { pthread_mutex_heap[i].is_allocated = 0; alloc_q (&(pthread_mutex_heap[i].mutex_wait_q), MAX_PTHREAD_MUTEX_WAITQ, PTHREAD_MUTEX_Q, sizeof(char), i) ; } default_mutex_attr.type = PTHREAD_MUTEX_DEFAULT; }
//----------------------------------------------------------------------------------------------------// // @func - msgq_init //! @desc //! The message Queue structures are initialized. //! - Based on the system configuration the message queues are created and //! defaults assigned to them. //! @return //! - Nothing //! @note //! - None //----------------------------------------------------------------------------------------------------// void msgq_init(void) { unsigned int i = 0 ; for( ; i < NUM_MSGQS; i++ ){ msgq_heap[i].msgid = -1; msgq_heap[i].msgq_len = MSGQ_CAPACITY; msgq_heap[i].stats.msg_qbytes = MSGQ_MAX_BYTES; msgq_heap[i].stats.msg_lspid = -1; msgq_heap[i].stats.msg_lrpid = -1; // Allocate space in the queue to contain msgq_len number of pointers alloc_q (&msgq_heap[i].msg_q, MSGQ_CAPACITY, MSG_Q, sizeof(msg_t),i); } }
//----------------------------------------------------------------------------------------------------// // Definitions //----------------------------------------------------------------------------------------------------// void sem_heap_init (void) { unsigned int i = 0 ; for (; i < MAX_SEM; i++ ) { sem_heap[i].sem_id = -1 ; sem_heap[i].owner = -1; sem_heap[i].unlink = 0; alloc_q (&sem_heap[i].sem_wait_q, MAX_SEM_WAITQ, SEM_Q, sizeof(char), i) ; #ifdef CONFIG_NAMED_SEMA sem_map[i].sem = (sem_t)0; bzero ((void*)sem_map[i].name, SEM_NAME_MAX); #endif } }
void invalidate_thread_info (pthread_info_t *thread) { thread->is_allocated = 0; thread->join_thread = NULL; thread->start_func = NULL; thread->param = NULL; thread->retval = NULL; thread->parent = NULL; thread->state = PTHREAD_STATE_DETACHED; alloc_q (&(thread->joinq),1,PTHREAD_JOIN_Q,sizeof(char),0); // Realloc Q afresh qinit (&(thread->joinq)); thread->joinq.items = &(thread->joinq_mem); if( thread->mem_id != -1 ) { free_bss_mem (thread->mem_id) ; thread->mem_id = -1; // BSS memory unallocated. } thread->thread_attr = default_attr; }