Example #1
0
BOOL
OSCreateThread(OSThread *thread, ThreadEntryPoint entry, uint32_t argc, void *argv, uint8_t *stack, uint32_t stackSize, uint32_t priority, OSThreadAttributes::Flags attributes)
{
   // Create new fiber
   auto fiber = gProcessor.createFiber();

   // Setup OSThread
   memset(thread, 0, sizeof(OSThread));
   thread->entryPoint = entry;
   thread->userStackPointer = stack;
   thread->stackStart = gMemory.untranslate(stack);
   thread->stackEnd = thread->stackStart - stackSize;
   thread->basePriority = priority;
   thread->attr = attributes;
   thread->fiber = fiber;
   thread->id = gThreadId++;
   fiber->thread = thread;

   // Write magic stack ending!
   gMemory.write(thread->stackEnd, 0xDEADBABE);

   // Setup thread state
   InitialiseThreadState(thread, entry, argc, argv);

   // Initialise tracer
   traceInit(&fiber->state, 128);

   return TRUE;
}
Example #2
0
BOOL
OSRunThread(OSThread *thread, ThreadEntryPoint entry, uint32_t argc, p32<void> argv)
{
   BOOL result = false;
   OSLockScheduler();

   if (OSIsThreadTerminated(thread)) {
      InitialiseThreadState(thread, entry, argc, argv);
      OSResumeThreadNoLock(thread, 1);
      OSRescheduleNoLock();
   }

   OSUnlockScheduler();
   return result;
}
Example #3
0
BOOL
OSCreateThread(OSThread *thread, ThreadEntryPoint entry, uint32_t argc, void *argv, uint8_t *stack, uint32_t stackSize, int32_t priority, OSThreadAttributes::Flags attributes)
{
   // Setup OSThread
   memset(thread, 0, sizeof(OSThread));
   thread->userStackPointer = stack;
   thread->stackStart = gMemory.untranslate(stack);
   thread->stackEnd = thread->stackStart - stackSize;
   thread->basePriority = priority;
   thread->attr = attributes;
   thread->id = gThreadId++;

   // Write magic stack ending!
   gMemory.write(thread->stackEnd, 0xDEADBABE);

   // Setup thread state
   InitialiseThreadState(thread, entry, argc, argv);

   return TRUE;
}