Int32 fxnTest1(UInt32 size, UInt32 *data) { FxnArgs *args = (FxnArgs *)((UInt32)data + sizeof(map_info_type)); t1.buffer1 = t2.buffer1 = (int*)(args->a) ; t1.buffer2 = t2.buffer2 = (int*)(args->b) ; t1.buffer3 = t2.buffer3 = (int*)(args->c) ; t1.start_indx = t2.start_indx = args->start_indx; t1.end_indx = t2.end_indx = args->end_indx; int unit_work = (t2.end_indx - t1.start_indx)/2 ; t1.end_indx = t1.start_indx + unit_work ; t2.start_indx = t2.start_indx + unit_work ; task0 = Task_create((Task_FuncPtr)common_wrapper, &taskParams0, &eb0); if (task0 == NULL) { System_abort("Task create failed"); } task1 = Task_create((Task_FuncPtr)common_wrapper, &taskParams1, &eb1); if (task1 == NULL) { // System_abort("Task create failed"); } UInt events ; events = Event_pend(edgeDetectEvent, Event_Id_00 + Event_Id_01, Event_Id_NONE, BIOS_WAIT_FOREVER) ; Task_delete(&task0) ; Task_delete(&task1) ; Uint32 reta = 1 ; return reta ; }
/*! * ======== OffloadM3_exit ======== * * Finalize the OffloadM3 module, currently supported only on SysM3 */ Void OffloadM3_exit() { if (MultiProc_self() != sysm3ProcId) return; Task_delete(&module.tasks[OFFLOAD_CREATE_IDX]); Task_delete(&module.tasks[OFFLOAD_DELETE_IDX]); Semaphore_delete(&module.semaphores[OFFLOAD_CREATE_IDX]); Semaphore_delete(&module.semaphores[OFFLOAD_DELETE_IDX]); Semaphore_delete(&module.mutex); }
int8_t BtStack_stop(void) { Task_delete(&rxTask); hasStart = FALSE; return 0; }
TIMM_OSAL_ERRORTYPE TIMM_OSAL_DeleteTask (TIMM_OSAL_PTR pTask) { TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_NONE; TIMM_OSAL_TASK *pHandle = (TIMM_OSAL_TASK *)pTask; TIMM_OSAL_U32 uSleepTime = TASK_MIN_WAIT_TIME; if (TIMM_OSAL_NULL == pHandle) { bReturnStatus = TIMM_OSAL_ERR_PARAMETER; goto EXIT; } if (pHandle->isCreated != TIMM_OSAL_TRUE) { bReturnStatus = TIMM_OSAL_ERR_UNKNOWN; goto EXIT; } /*Check the status of the Task*/ while ( Task_Mode_TERMINATED != Task_getMode ( pHandle->task) ) { TIMM_OSAL_SleepTask ( uSleepTime ); uSleepTime <<= 1; if ( uSleepTime >= TASK_MAX_WAIT_TIME) { bReturnStatus = TIMM_OSAL_ERR_UNKNOWN; goto EXIT; } } Task_delete ( &(pHandle->task) ); TIMM_OSAL_Free (pHandle->stackPtr); TIMM_OSAL_Free (pHandle); EXIT: return bReturnStatus; }
static Void OffloadM3_deleteTask(UArg sem, UArg arg1) { Semaphore_Handle semHandle = (Semaphore_Handle)sem; Int i; while (1) { Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); Mutex_enter(); if (module.created) { /* * Since this task is higher priority than any of the subtasks, * they won't be in running state, so we can call Task_delete on * them */ for (i = OFFLOAD_AC_IDX; i < OFFLOAD_MAX_IDX; i++) { Task_delete(&module.tasks[i]); Semaphore_delete(&module.semaphores[i]); module.tasks[i] = NULL; module.semaphores[i] = NULL; } module.created = FALSE; } Mutex_leave(); } }
Int32 Utils_tskDelete(Utils_TskHndl * pHndl) { UInt32 sleepTime = 8; /* in OS ticks */ Utils_tskSendCmd(pHndl, UTILS_TSK_CMD_EXIT); /* wait for command to be received and task to be exited */ Task_sleep(1); while (Task_Mode_TERMINATED != Task_getMode(pHndl->tsk)) { Task_sleep(sleepTime); sleepTime >>= 1; if (sleepTime == 0) { char name[64]; strcpy(name, "INVALID_TSK"); Utils_prfGetTaskName(pHndl->tsk, name); Vps_printf("Task Delete Error!!!!!!, task %s not deleted\n", name); UTILS_assert(0); } } Utils_prfLoadUnRegister(pHndl->tsk); Task_delete(&pHndl->tsk); Utils_mbxDelete(&pHndl->mbx); return FVID2_SOK; }
/* * ======== pthread_cancel ======== * The specification of this API is that it be used as a means for one thread * to termintate the execution of another thread. There is no mention of * returning an error if the argument, pthread, is the same thread as the * calling thread. */ int pthread_cancel(pthread_t pthread) { pthread_Obj *thread = (pthread_Obj *)pthread; UInt key; /* * Cancel the thread. Only asynchronous cancellation is supported, * since functions that would normally be cancellation points (eg, * printf()), are not cancellation points for BIOS. */ key = Task_disable(); /* Indicate that cancellation is requested. */ thread->cancelPending = 1; if (thread->cancelState == PTHREAD_CANCEL_ENABLE) { /* Set this task's priority to -1 to stop it from running. */ Task_setPri(thread->task, -1); Task_restore(key); /* Pop and execute the cleanup handlers */ while (thread->cleanupList != NULL) { _pthread_cleanup_pop(thread->cleanupList, 1); } /* Cleanup any pthread specific data */ _pthread_removeThreadKeys(pthread); if (thread->detached) { /* Free memory */ #if ti_sysbios_posix_Settings_supportsMutexPriority__D Queue_destruct(&(thread->mutexList)); #endif Semaphore_destruct(&(thread->joinSem)); Task_delete(&(thread->task)); Memory_free(Task_Object_heap(), thread, sizeof(pthread_Obj)); } else { /* pthread_join() will clean up. */ thread->ret = PTHREAD_CANCELED; Semaphore_post(Semaphore_handle(&(thread->joinSem))); } } else { Task_restore(key); } return (0); }
/* * ======== Task_deleteTerminatedTasksFunc ======== */ Void Task_deleteTerminatedTasksFunc() { UInt key; Task_Handle tsk; key = Hwi_disable(); if (!Queue_empty(Task_Module_State_terminatedQ())) { tsk = Queue_head(Task_Module_State_terminatedQ()); Hwi_restore(key); Task_delete(&tsk); } else { Hwi_restore(key); } }
/* * ======== IpcPower_exit ======== */ Void IpcPower_exit() { --curInit; if (curInit == 0) { /* Unblock PM suspend task */ Semaphore_post(IpcPower_semSuspend); /* Wait for task completion */ Semaphore_pend(IpcPower_semExit, BIOS_WAIT_FOREVER); /* Delete the suspend task and semaphore */ Task_delete(&IpcPower_tskSuspend); Semaphore_delete(&IpcPower_semSuspend); Semaphore_delete(&IpcPower_semExit); } }
/* * ======== pthread_join ======== * Wait for thread to terminate. * * If multiple threads simultaneously try to join with the same * thread, the results are undefined. We will return an error. * * If the thread calling pthread_join() is canceled, then the target * thread will remain joinable (i.e., it will not be detached). */ int pthread_join(pthread_t pthread, void **thread_return) { pthread_Obj *thread = (pthread_Obj *)pthread; UInt key; key = Task_disable(); if ((thread->joinThread != NULL) || (thread->detached != 0)) { /* * Error - Another thread has already called pthread_join() * for this thread, or the thread is in the detached state. */ Task_restore(key); return (EINVAL); } if (pthread == pthread_self()) { Task_restore(key); return (EDEADLK); } /* * Allow pthread_join() to be called from a BIOS Task. If we * set joinThread to pthread_self(), we could get NULL if the * Task arg1 is 0. All we need is a non-NULL value for joinThread. */ thread->joinThread = Task_self(); Task_restore(key); Semaphore_pend(Semaphore_handle(&(thread->joinSem)), BIOS_WAIT_FOREVER); if (thread_return) { *thread_return = thread->ret; } #if ti_sysbios_posix_Settings_supportsMutexPriority__D Queue_destruct(&(thread->mutexList)); #endif Semaphore_destruct(&(thread->joinSem)); Task_delete(&(thread->task)); Memory_free(Task_Object_heap(), thread, sizeof(pthread_Obj)); return (0); }
/* * ======== Task_deleteTerminatedTasksFunc ======== */ Void Task_deleteTerminatedTasksFunc() { UInt hwiKey, taskKey; Task_Handle tsk; taskKey = Task_disable(); hwiKey = Hwi_disable(); if (!Queue_empty(Task_Module_State_terminatedQ())) { tsk = Queue_head(Task_Module_State_terminatedQ()); Hwi_restore(hwiKey); tsk->readyQ = NULL; Task_delete(&tsk); } else { Hwi_restore(hwiKey); } Task_restore(taskKey); }
/* * ======== ThreadSupport_Instance_finalize ======== */ Void ThreadSupport_Instance_finalize(ThreadSupport_Handle obj, Int status) { ti_sysbios_knl_Semaphore_Handle bios6sem; bios6sem = ThreadSupport_Instance_State_join_sem(obj); /* status is equal to the return code from Instance_init */ switch (status) { case 0: Task_delete(&(obj->task)); /* OK to fall through */ case ThreadSupport_TASK_FAILURE: Semaphore_destruct(Semaphore_struct(bios6sem)); /* OK to fall through */ case ThreadSupport_PRI_FAILURE: default: break; } }
void osDeleteTask(OsTask *task) { //Delete the specified task Task_delete(&task); }
/** * \brief delete a thread * * deletes the specified application thread. Since the specified thread must be in a * terminated or completed state, this service cannot be called from a thread attempting to delete itself. * It is the application’s responsibility to manage the memory area associated * with the thread’s stack, which is available after this service completes. * In addition, the application must prevent use of a deleted thread * * \param[in] p_handle Handle to a thread control block * * \return e_SUCCESS on success, e_FAILURE on error * * \sa OS_thread_create, OS_thread_terminate, OS_thread_sleep * \note * * \warning */ e_ret_status OS_thread_delete(handle p_handle) { Task_delete((Task_Handle *)p_handle); return e_SUCCESS; /* Semaphore_post doesn't return the status */ }
/*----------------------------------------------------------------------------- * ccode - Called from a kernel wrapper * * Start another task running and then ping / pong back and forth between * this function task and the other function task using a semaphore. *----------------------------------------------------------------------------*/ void ccode(uint32_t *completion_code) { counter = 0; /*------------------------------------------------------------------------- * Create a task to run the compute routine *------------------------------------------------------------------------*/ Task_Params taskParams; Task_Params_init(&taskParams); taskParams.instance->name = "compute"; /*------------------------------------------------------------------------- * The task is provided with a new stack that we simply malloc from the heap. * OpenCL kernels and functions called from kernels are provided with a * limited heap. If the stack space required for the task is greater than * the malloc can provide, then a buffer passed to the kernel can provide * the underlying memory for the stack. *------------------------------------------------------------------------*/ taskParams.stackSize = T1_STKSZ; taskParams.stack = malloc(T1_STKSZ); if (!taskParams.stack) { *completion_code = APP_FAIL_STACK; return; } /*------------------------------------------------------------------------- * Since the new task priority will be higher than this function which runs * at a priority level between 5 and 10, the task start immediately after * creation function blocks with the semaphore pend. *------------------------------------------------------------------------*/ taskParams.priority = 11; /*------------------------------------------------------------------------- * Create a semaphore that we will post and the compute function will * pend on. The address of the semaphore will be passed to the task function. *------------------------------------------------------------------------*/ Semaphore_Handle sem = Semaphore_create(0, NULL, NULL); if (!sem) { *completion_code = APP_FAIL_SEMAPHORE; return; } taskParams.arg0 = (UArg)&sem; Task_Handle task = Task_create(compute, &taskParams, NULL); if (!task) { *completion_code = APP_FAIL_TASK; return; } /*------------------------------------------------------------------------- * for multiple iterations, ping/pong between tasks *------------------------------------------------------------------------*/ int i; uint32_t c1 = __clock(); for (i = 0; i < 1000; ++i) { counter++; Semaphore_post(sem); } uint32_t c2 = __clock() - c1; printf("%u task switches in %u cycles ==> %u cycles per switch\n", counter, c2, c2/counter); /*------------------------------------------------------------------------- * Cleanup the SysBios resources *------------------------------------------------------------------------*/ Task_delete (&task); Semaphore_delete (&sem); *completion_code = APP_OK; }