Example #1
0
void switchTask(Regs *regs)
{
	ASM("sti");
	if (currentThread == NULL)
	{
		apic->timerInitCount = quantumTicks;
		return;
	};
	if (spinlockTry(&schedLock))
	{
		//kprintf_debug("WARNING: SCHED LOCKED\n");
		apic->timerInitCount = quantumTicks;
		return;
	};

	__sync_fetch_and_add(&switchTaskCounter, 1);

	// remember the context of this thread.
	fpuSave(&currentThread->fpuRegs);
	memcpy(&currentThread->regs, regs, sizeof(Regs));

	// get the next thread
	do
	{
		currentThread = currentThread->next;
	} while (!canSched(currentThread));

	// if there are signals waiting, and not currently being handled, then handle them.
	if (((currentThread->flags & THREAD_SIGNALLED) == 0) && (currentThread->sigcnt != 0))
	{
		// if the syscall is interruptable, do the switch-back.
		if (currentThread->flags & THREAD_INT_SYSCALL)
		{
			//kprintf_debug("signal in queue, THREAD_INT_SYSCALL ok\n");
			memcpy(&currentThread->regs, &currentThread->intSyscallRegs, sizeof(Regs));
			*((int64_t*)&currentThread->regs.rax) = -1;
			currentThread->therrno = EINTR;
		};
		
		// i've found that catching signals in kernel mode is a bad idea
		if ((currentThread->regs.cs & 3) == 3)
		{
			dispatchSignal(currentThread);
		};
	};

	spinlockRelease(&schedLock);
	jumpToTask();
};
Example #2
0
static void kernelThreadExit()
{
	// just to be safe
	if (currentThread == &firstThread)
	{
		panic("kernel startup thread tried to exit (this is a bug)");
	};

	Thread *nextThread = currentThread->next;

	// we need to do all of this with interrupts disabled. we remove ourselves from the runqueue,
	// but do not free the stack nor the thread description; this will be done by ReleaseKernelThread()
	ASM("cli");
	currentThread->prev->next = currentThread->next;
	currentThread->next->prev = currentThread->prev;
	currentThread->flags |= THREAD_TERMINATED;

	// switch tasks
	currentThread = nextThread;
	jumpToTask();
};
Example #3
0
TodoDialog::TodoDialog(MainWindow *mainWindow, QString taskUid,
                       QWidget *parent) :
        MasterDialog(parent),
        ui(new Ui::TodoDialog) {
    _mainWindow = mainWindow;
    ui->setupUi(this);
    setupUi();

    // init the description edit search frame
    ui->descriptionEdit->initSearchFrame(ui->descriptionEditSearchFrame);

    QString selectedText =
            _mainWindow->activeNoteTextEdit()->textCursor().selectedText();

    // insert the selected note text in the new item edit
    if (!selectedText.isEmpty()) {
        ui->newItemEdit->setText(selectedText);
    }

    // jump to a task
    if (!taskUid.isEmpty()) {
        jumpToTask(taskUid);
    }
}