void vc_hostfs_init(void) { // This hostfs module is not thread safe - it allocaes a block // of memory and uses it without any kind of locking. // // It offers no advantage of stdio, and so most clients should // not use it. Arguably FILESYS should use it in order to get // the FIFO support. const char *thread_name = vcos_thread_get_name(vcos_thread_current()); if (strcmp(thread_name, "FILESYS") != 0 && strcmp(thread_name, "HFilesys") != 0) { fprintf(stderr,"%s: vc_hostfs is deprecated. Please use stdio\n", vcos_thread_get_name(vcos_thread_current())); } vcos_log_register("hostfs", &hostfs_log_cat); DEBUG_MINOR("init"); // Allocate memory for the file info table p_file_info_table = (file_info_t *)calloc( FILE_INFO_TABLE_CHUNK_LEN, sizeof( file_info_t ) ); assert( p_file_info_table != NULL ); if (p_file_info_table) { file_info_table_len = FILE_INFO_TABLE_CHUNK_LEN; } }
void _vcos_task_timer_set(void (*pfn)(void*), void *cxt, VCOS_UNSIGNED ms) { VCOS_THREAD_T *thread = vcos_thread_current(); VCOS_STATUS_T status; status = vcos_timer_create(&thread->task_timer, "vcos_task_timer", pfn, cxt); vcos_assert(status == VCOS_SUCCESS); vcos_timer_set(&thread->task_timer, ms); }
void _vcos_task_timer_set(void (*pfn)(void*), void *cxt, VCOS_UNSIGNED ms) { VCOS_THREAD_T *self = vcos_thread_current(); vcos_assert(self); vcos_assert(self->_timer.pfn == NULL); self->_timer.pfn = pfn; self->_timer.cxt = cxt; vcos_timer_set(&self->_timer.timer, ms); }
void _vcos_task_timer_cancel(void) { VCOS_THREAD_T *self = vcos_thread_current(); if (self->_timer.timer.linux_timer.function) { vcos_timer_cancel(&self->_timer.timer); vcos_timer_delete(&self->_timer.timer); } }
void vcos_thread_exit(void *arg) { VCOS_THREAD_T *thread = vcos_thread_current(); vcos_assert(thread); vcos_assert(thread->magic == VCOS_THREAD_MAGIC); thread->exit_data = arg; }
void _vcos_task_timer_set(void (*pfn)(void *), void *cxt, VCOS_UNSIGNED ms) { VCOS_THREAD_T *self = vcos_thread_current(); vcos_assert(self); vcos_assert(self->_timer.pfn == NULL); vcos_timer_create( &self->_timer.timer, "TaskTimer", pfn, cxt ); vcos_timer_set(&self->_timer.timer, ms); }
void _vcos_task_timer_cancel(void) { VCOS_THREAD_T *thread = vcos_thread_current(); if (thread->task_timer.pfn) { thread->task_timer.pfn = NULL; vcos_timer_delete(&thread->task_timer); } }
void _vcos_task_timer_cancel(void) { VCOS_THREAD_T *self = vcos_thread_current(); if (self->_timer.pfn) { vcos_timer_cancel(&self->_timer.timer); self->_timer.pfn = NULL; } }
void _vcos_task_timer_cancel(void) { VCOS_THREAD_T *thread = vcos_thread_current(); if (thread == NULL || !thread->task_timer_created) return; vcos_timer_cancel(&thread->task_timer); thread->orig_task_timer_expiration_routine = NULL; }
void vcos_generic_reentrant_mutex_unlock(VCOS_REENTRANT_MUTEX_T *m) { vcos_assert(m->count != 0); vcos_assert(m->owner == vcos_thread_current()); m->count--; if (m->count == 0) { m->owner = 0; vcos_mutex_unlock(&m->mutex); } }
void vcos_thread_exit(void *arg) { VCOS_THREAD_T *thread = vcos_thread_current(); if ( thread && thread->dummy ) { vcos_free ( (void*) thread ); thread = NULL; } pthread_exit(arg); }
void vcos_thread_exit(void *arg) { VCOS_THREAD_T *thread = vcos_thread_current(); if ( thread && thread->dummy ) { vcos_free ( (void*) thread ); thread = NULL; } // Do nothing UNREFERENCED_PARAMETER(arg); }
void vcos_generic_reentrant_mutex_lock(VCOS_REENTRANT_MUTEX_T *m) { VCOS_THREAD_T *thread = vcos_thread_current(); vcos_assert(m); vcos_assert(thread != 0); if (m->owner != thread) { vcos_mutex_lock(&m->mutex); m->owner = thread; vcos_assert(m->count == 0); } m->count++; }
extern void vcos_thread_deregister_at_exit(void (*pfn)(void*), void *cxt) { int i; VCOS_THREAD_T *self = vcos_thread_current(); vcos_assert(self); vcos_assert(!self->joined); for (i=0; i<VCOS_MAX_EXIT_HANDLERS; i++) { if ((self->at_exit[i].pfn == pfn) && (self->at_exit[i].cxt == cxt)) { self->at_exit[i].pfn = NULL; return; } } vcos_assert(0); /* pfn/cxt not found */ }
// Wait on the mutex semaphore if we don't already own it. void _mwmutex_lock(_lock_t sem) { #if _REENTRANT if (sem != 0) { void *self = vcos_thread_current(); if (sem->th_id == self) sem->count++; else { rtos_latch_get( &sem->latch ); sem->th_id = self; sem->count = 1; } } #endif }
static _VCOS_INLINE void vcos_msg_send_helper(VCOS_MSGQUEUE_T *src, VCOS_MSGQUEUE_T *dest, uint32_t code, VCOS_MSG_T *msg) { vcos_assert(msg); vcos_assert(dest); msg->code = code; msg->dst = dest; msg->src = src; msg->next = NULL; msg->src_thread = vcos_thread_current(); msgq_append(dest, msg); vcos_semaphore_post(&dest->sem); }
bool khrn_worker_init(void) { #ifndef KHRN_WORKER_USE_LLAT VCOS_THREAD_ATTR_T attr; #endif vcos_assert(!inited); khrn_worker_enter_pos = 0; khrn_worker_exit_pos_0 = 0; khrn_worker_exit_pos_1 = 0; khrn_worker_msg.post = msgs; khrn_worker_msg.done_it = msgs; khrn_worker_msg.cleanup = msgs; #ifdef KHRN_WORKER_USE_LLAT llat_i = khrn_llat_register(khrn_worker_llat_callback); vcos_assert(llat_i != -1); #else if (vcos_event_create(&event, "khrn_worker_event") != VCOS_SUCCESS) { return false; } exit_thread = false; vcos_thread_attr_init(&attr); vcos_thread_attr_setpriority(&attr, THREAD_PRIORITY); #if !defined(V3D_LEAN) switch (vcos_thread_get_affinity(vcos_thread_current())) { case VCOS_AFFINITY_CPU0: vcos_thread_attr_setaffinity(&attr, VCOS_AFFINITY_CPU1); break; case VCOS_AFFINITY_CPU1: vcos_thread_attr_setaffinity(&attr, VCOS_AFFINITY_CPU0); break; } vcos_thread_attr_setstacksize(&attr, THREAD_STACK_SIZE); #endif /* V3D_LEAN */ if (vcos_thread_create(&thread, "khrn_worker_thread", &attr, khrn_worker_main, NULL) != VCOS_SUCCESS) { vcos_event_delete(&event); return false; } #endif inited = true; return true; }
extern VCOS_STATUS_T vcos_thread_at_exit(void (*pfn)(void*), void *cxt) { int i; VCOS_THREAD_T *self = vcos_thread_current(); if (!self) { vcos_assert(0); return VCOS_EINVAL; } for (i=0; i<VCOS_MAX_EXIT_HANDLERS; i++) { if (self->at_exit[i].pfn == NULL) { self->at_exit[i].pfn = pfn; self->at_exit[i].cxt = cxt; return VCOS_SUCCESS; } } return VCOS_ENOSPC; }
/** Exit the thread. Resources must still be cleaned up via a call to thread_join(). */ void vcos_thread_exit(void *data) { /* Get the current task pointer, and cast to the joinable thread * structure - this works with Nucleus and ThreadX style threads * which is what this is designed for, but may not work with * other thread types. */ VCOS_THREAD_T *thread = vcos_thread_current(); vcos_assert(thread); vcos_assert(thread->magic == VCOS_THREAD_MAGIC); thread->exit_data = data; /* Wake up our parent */ vcos_semaphore_post(&thread->wait); vcos_llthread_exit(); }
void _vcos_task_timer_set(void (*pfn)(void*), void *cxt, VCOS_UNSIGNED ms) { VCOS_THREAD_T *thread = vcos_thread_current(); if (thread == NULL) return; vcos_assert(thread->orig_task_timer_expiration_routine == NULL); if (!thread->task_timer_created) { VCOS_STATUS_T st = vcos_timer_create(&thread->task_timer, NULL, _task_timer_expiration_routine, thread); (void)st; vcos_assert(st == VCOS_SUCCESS); thread->task_timer_created = 1; } thread->orig_task_timer_expiration_routine = pfn; thread->orig_task_timer_context = cxt; vcos_timer_set(&thread->task_timer, ms); }
extern VCOS_STATUS_T vcos_generic_event_flags_get(VCOS_EVENT_FLAGS_T *flags, VCOS_UNSIGNED bitmask, VCOS_OPTION op, VCOS_UNSIGNED suspend, VCOS_UNSIGNED *retrieved_bits) { VCOS_EVENT_WAITER_T waitreq; VCOS_STATUS_T rc = VCOS_EAGAIN; int satisfied = 0; vcos_assert(flags); /* default retrieved bits to 0 */ *retrieved_bits = 0; vcos_mutex_lock(&flags->lock); switch (op & VCOS_EVENT_FLAG_OP_MASK) { case VCOS_AND: if ((flags->events & bitmask) == bitmask) { *retrieved_bits = flags->events; rc = VCOS_SUCCESS; satisfied = 1; if (op & VCOS_CONSUME) flags->events &= ~bitmask; } break; case VCOS_OR: if (flags->events & bitmask) { *retrieved_bits = flags->events; rc = VCOS_SUCCESS; satisfied = 1; if (op & VCOS_CONSUME) flags->events &= ~bitmask; } break; default: vcos_assert(0); rc = VCOS_EINVAL; break; } if (!satisfied && suspend) { /* Have to go to sleep. * * Append to tail so we get FIFO ordering. */ waitreq.requested_events = bitmask; waitreq.op = op; waitreq.return_status = VCOS_EAGAIN; waitreq.flags = flags; waitreq.actual_events = 0; waitreq.thread = vcos_thread_current(); waitreq.next = 0; vcos_assert(waitreq.thread != (VCOS_THREAD_T*)-1); VCOS_QUEUE_APPEND_TAIL(&flags->waiters, &waitreq); if (suspend != (VCOS_UNSIGNED)-1) _vcos_task_timer_set(event_flags_timer_expired, &waitreq, suspend); vcos_mutex_unlock(&flags->lock); /* go to sleep and wait to be signalled or timeout */ _vcos_thread_sem_wait(); *retrieved_bits = waitreq.actual_events; rc = waitreq.return_status; /* cancel the timer - do not do this while holding the mutex as it * might be waiting for the timeout function to complete, which will * try to take the mutex. */ if (suspend != (VCOS_UNSIGNED)-1) _vcos_task_timer_cancel(); } else { vcos_mutex_unlock(&flags->lock); } return rc; }
static void pool_object_logging( const char *fname, VC_POOL_OBJECT_T *object ) { logging_message( LOGGING_VMCS,"%s: %p: task %s: refcount=%d", fname, object, vcos_thread_get_name( vcos_thread_current() ), object->refcount ); }