Ejemplo n.º 1
0
void taskCallBackShutDown()
{
    if (babyTaskHandle != -1)
    {
        taskStop(babyTaskHandle);
    }

    listDeleteAll(&callbacks.babies);
}
Ejemplo n.º 2
0
Archivo: test.c Proyecto: eswartz/emul
int run_test_process(ContextAttachCallBack * done, void * data) {
#if defined(WIN32)
    char fnm[FILE_PATH_SIZE];
    char cmd[FILE_PATH_SIZE];
    int res = 0;
    STARTUPINFO si;
    PROCESS_INFORMATION prs;
    ContextAttachArgs * args;

    memset(&si, 0, sizeof(si));
    memset(&prs, 0, sizeof(prs));
    memset(fnm, 0, sizeof(fnm));
    if (GetModuleFileName(NULL, fnm, sizeof(fnm)) == 0) {
        set_win32_errno(GetLastError());
        return -1;
    }
    si.cb = sizeof(si);
    strcpy(cmd, "agent.exe -t");
    if (CreateProcess(fnm, cmd, NULL, NULL,
            FALSE, CREATE_SUSPENDED | CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW,
            NULL, NULL, &si, &prs) == 0) {
        set_win32_errno(GetLastError());
        return -1;
    }
    args = (ContextAttachArgs *)loc_alloc(sizeof(ContextAttachArgs));
    args->done = done;
    args->data = data;
    args->thread = prs.hThread;
    args->process = prs.hProcess;
    res = context_attach(prs.dwProcessId, done_context_attach, args, 0);
    if (res != 0) loc_free(args);
    return res;
#elif defined(_WRS_KERNEL)
    int tid = taskCreate("tTcf", 100, 0, 0x4000, (FUNCPTR)test_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    if (tid == 0) return -1;
    taskStop(tid);
    taskActivate(tid);
    assert(taskIsStopped(tid));
    return context_attach(tid, done, data, 0);
#else
    /* Create child process to debug */
    int pid = fork();
    if (pid < 0) return -1;
    if (pid == 0) {
        int fd;
        if (context_attach_self() < 0) exit(1);
        fd = sysconf(_SC_OPEN_MAX);
        while (fd-- > 2) close(fd);
        if (tkill(getpid(), SIGSTOP) < 0) exit(1);
        test_proc();
        exit(0);
    }
    return context_attach(pid, done, data, CONTEXT_ATTACH_SELF);
#endif
}
Ejemplo n.º 3
0
/*-----------------------------------------------------------------------------
    Name        : taskStartName
    Description : Start a specific task
    Inputs      : function - entry point of task
                  name - a string describing the task for debugging
                  period - period between consecutive calls
                  stacksize - size of task's local stack
                  flags - control execution of task
    Outputs     : taskdata structure allocated and initialized
    Return      : handle to task for later manipulation of task
    Note        : if a taskdata structure or stack RAM cannot be allocated, the
                    function will generate a fatal error.
                  name must be caller-allocated and outlive the task.
                  This is usually invoked with the taskStart macro.
                  The task is executed once immediately and must yield
                  rather than exit at this first call.
----------------------------------------------------------------------------*/
taskhandle taskStartName(taskfunction function, char *name,
                         real32 period, udword flags)
{
    static taskhandle handle = ERROR;
    taskdata *newTask;
    
    taskInitCheck();
    dbgAssertOrIgnore(function != NULL);
    dbgAssertOrIgnore(period > 0.0f);

    newTask = memAlloc(sizeof(taskdata), "taskData", NonVolatile);
    handle = taskPointerAlloc();
    taskData[handle] = newTask;

#if TASK_VERBOSE_LEVEL >= 2
    dbgMessagef("%s: starting task at 0x%x at %d Hz, flags 0x%x using handle %d at 0x%x",
                __FUNCTION__, function, 1.0f/period, flags, handle, taskData[handle]);
#endif

    //make task in use and running
    newTask->flags = flags | TF_Allocated;
    newTask->function = function;
    newTask->context = NULL;
    newTask->name = name;
    newTask->ticks = 0;         //no residual ticks
    dbgAssertOrIgnore(period * taskFrequency < (real32)SDWORD_Max);
    newTask->ticksPerCall = (udword)(period * taskFrequency);

    function(&newTask->context);

    if (newTask->context == NULL)
    {
        // Exited already?
#if TASK_ERROR_CHECKING
        dbgFatalf(DBG_Loc, "taskStart: stillborn task %s", name);
#endif
        taskStop(handle);
        return ERROR;
    }

    return handle;
}
Ejemplo n.º 4
0
sdword taskExecuteAllPending(sdword ticks)
{
#if TASK_VERBOSE_LEVEL >= 2
    if (ticks > 0)
    {
        dbgMessagef("%s: executing tasks for %d ticks", __FUNCTION__, ticks);
    }
#endif

    /* Don't do a taskInitCheck because this sometimes gets called on
       exiting, after all the tasks are shut down. */
    if (taskModuleInit == FALSE)
    {
        return(OKAY);
    }
    //taskInitCheck();

    if (demDemoRecording)
    {
        demNumberTicksSave(ticks);
    }
    else if (demDemoPlaying)
    {
        ticks = demNumberTicksLoad(ticks);
    }

    taskTimeDelta = ticks / taskFrequency;
    taskTimeElapsed += taskTimeDelta;
    tTicks = ticks;             //save the ticks parameter

    // Verify we're not in any task currently.
    dbgAssertOrIgnore(taskCurrentTask == -1);

    for (taskCurrentTask = 0; taskCurrentTask < taskMaxTask; taskCurrentTask++)
    {
        if (taskData[taskCurrentTask] == NULL
            || bitTest(taskData[taskCurrentTask]->flags, TF_Paused))
            continue;

        if (TitanActive)
            titanPumpEngine();

        //calculate number of calls
        if (bitTest(taskData[taskCurrentTask]->flags, TF_OncePerFrame))
        {
/* Don't do this if check, because if you do it is possible that
   hundreds of other tasks will get executed and this task will starve
   when the game AI gets heavy.  Luke, later check if there's a better
   way to do this. */
/*
            if (taskData[taskCurrentTask]->ticks == 0)  //see if time to execute
            {
*/
            taskNumberCalls = 1; //flag to call once
            taskData[taskCurrentTask]->ticks =
                taskData[taskCurrentTask]->ticksPerCall;
/*
            }
*/
            taskData[taskCurrentTask]->ticks--;
        }
        else
        {                       //else it's a real-time task
            //add leftover ticks from last frame
            tLocalTicks = tTicks + taskData[taskCurrentTask]->ticks;
            //save leftover ticks for next frame
            taskData[taskCurrentTask]->ticks =
                tLocalTicks % taskData[taskCurrentTask]->ticksPerCall;
            taskNumberCalls =
                tLocalTicks / taskData[taskCurrentTask]->ticksPerCall;
#if TASK_MAX_TICKS
            taskNumberCalls = min(taskNumberCalls, TSK_MaxTicks);
#endif //TASK_MAX_TICKS
            }
#if TASK_VERBOSE_LEVEL >= 3
        if (taskNumberCalls)
        {
            dbgMessagef(
                "%s: task %d (%s) to run %d times, "
                "%d ticks elapsed / %d per call = %d",
                __FUNCTION__,
                taskCurrentTask, taskData[taskCurrentTask]->name,
                taskNumberCalls,
                tLocalTicks, taskData[taskCurrentTask]->ticksPerCall,
                tLocalTicks / taskData[taskCurrentTask]->ticksPerCall);
        }
#endif
        taskProcessIndex++;
        for (; taskNumberCalls > 0; taskNumberCalls--)
        {
            taskData[taskCurrentTask]->function(
                &taskData[taskCurrentTask]->context);
            if (taskData[taskCurrentTask]->context == NULL) {
                // Task has exited.
                taskStop(taskCurrentTask);
                break;
            }
        }
    }
    taskCurrentTask = -1;       //not currently executing any tasks
    return(OKAY);
}
Ejemplo n.º 5
0
static int start_process(Channel * c, char ** envp, char * dir, char * exe, char ** args, int attach,
                int * pid, int * selfattach, ChildProcess ** prs) {
    int err = 0;
    char * ptr;
    SYM_TYPE type;

    if (symFindByName(sysSymTbl, exe, &ptr, &type) != OK) {
        err = errno;
        if (err == S_symLib_SYMBOL_NOT_FOUND) err = ERR_SYM_NOT_FOUND;
        assert(err != 0);
    }
    else {
        int i;
        int pipes[2][2];
        /* TODO: arguments, environment */
        *pid = taskCreate("tTcf", 100, 0, 0x4000, (FUNCPTR)ptr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        for (i = 0; i < 2; i++) {
            char pnm[32];
            char pnm_m[32];
            char pnm_s[32];
            snprintf(pnm, sizeof(pnm), "/pty/tcf-%0*lx-%d", sizeof(*pid) * 2, *pid, i);
            snprintf(pnm_m, sizeof(pnm_m), "%sM", pnm);
            snprintf(pnm_s, sizeof(pnm_m), "%sS", pnm);
            if (ptyDevCreate(pnm, PIPE_SIZE, PIPE_SIZE) == ERROR) {
                err = errno;
                break;
            }
            pipes[i][0] = open(pnm_m, O_RDWR, 0);
            pipes[i][1] = open(pnm_s, O_RDWR, 0);
            if (pipes[i][0] < 0 || pipes[i][1] < 0) {
                err = errno;
                break;
            }
        }
        if (err) {
            taskDelete(*pid);
            *pid = 0;
        }
        else {
            semTake(prs_list_lock, WAIT_FOREVER);
            ioTaskStdSet(*pid, 0, pipes[0][1]);
            ioTaskStdSet(*pid, 1, pipes[0][1]);
            ioTaskStdSet(*pid, 2, pipes[1][1]);
            *prs = loc_alloc_zero(sizeof(ChildProcess));
            (*prs)->inp = pipes[0][0];
            (*prs)->out = pipes[0][0];
            (*prs)->err = pipes[1][0];
            (*prs)->pid = *pid;
            (*prs)->bcg = c->bcg;
            list_add_first(&(*prs)->link, &prs_list);
            if (attach) {
                taskStop(*pid);
                taskActivate(*pid);
                assert(taskIsStopped(*pid));
            }
            else {
                taskActivate(*pid);
            }
            semGive(prs_list_lock);
        }
    }
    if (!err) return 0;
    errno = err;
    return -1;
}
Ejemplo n.º 6
0
/*-----------------------------------------------------------------------------
    Name        : pingShutdown
    Description : Shut down the ping module
    Inputs      :
    Outputs     :
    Return      :
----------------------------------------------------------------------------*/
void pingShutdown(void)
{
    taskStop(pingTaskHandle);
}
Ejemplo n.º 7
0
	//------------------------------------------------------------------------
	Clock::~Clock(){
		taskStop();
	}