RiCBoolean RiCOSTask_init (RiCOSTask *const me, RiCOSTaskEndCallBack tfunc, void *param, const char *name, const long stackSize);
me
The RiCOSTask object to initialize
tfunc
The callback function that ends the current operating system task
param
The parameters to the callback function
name
stackSize
RiCBoolean RiCOSTask_init(RiCOSTask * const me,
RiCOSTaskEndCallBack tfunc, void * param,
const char * name, const long stackSize)
{
size_t i, len = 0;
char* myName = NULL;
if (me == NULL) {return 0;}
me->endOSTaskInCleanup = TRUE;
me->isWrapperThread = 0;
/* Copy the thread name. */
if (name != NULL) len = strlen(name);
/* check for legal name */
for (i = 0; i < len; i++) {
if ((isalnum((int)name[i]) == 0) &&
(name[i] != '_')) {
len = 0;
break;
}
}
if (len > 0) {
myName = malloc(len + 1);
strcpy(myName, name);
}
RiCOSEventFlag_init(&me->m_SuspEventFlag);
RiCOSEventFlag_reset(&me->m_SuspEventFlag);
/* Create SUSPENDED thread !!!!!! */
me->m_ExecFunc = tfunc;
me->m_ExecParam = param;
me->hThread = 0;
me->hThread = taskSpawn(myName,
/* name of new task (stored at pStackBase) */
(int) PRIORITY_NORMAL, /* priority of new task */
0, /* task option word */
(int)stackSize, /*size (bytes) of stack needed */
(int (*)())preExecFunc, /* thread function */
(int)(void *)me, /* argument to thread function */
0,0,0,0,0,0,0,0,0);
return 1;
}