From 9a83ec8001d9e7b44c720f49916047c98fe3345a Mon Sep 17 00:00:00 2001 From: NicJA Date: Wed, 20 May 2015 01:07:11 +0000 Subject: [PATCH] use GET_THIS_TASK internally throughout exec - since it will result in faster/smaller code for most cases. rework some parts of the execsmp locking to use forbid/permit rather than disable/enable. use internal tasklock when modifying certain internal task fields. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@50721 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- rom/exec/allocmem.c | 4 +-- rom/exec/allocsignal.c | 15 +++++++-- rom/exec/alloctaskstorageslot.c | 7 +++-- rom/exec/alloctrap.c | 7 ++--- rom/exec/attemptsemaphore.c | 6 ++-- rom/exec/childorphan.c | 16 +++++----- rom/exec/childstatus.c | 11 +++---- rom/exec/childwait.c | 14 ++++----- rom/exec/debug.c | 2 +- rom/exec/disable.c | 2 ++ rom/exec/enable.c | 4 ++- rom/exec/etask.h | 1 + rom/exec/exec_autoinit.c | 2 +- rom/exec/exec_util.c | 6 ++-- rom/exec/findtask.c | 29 ++++++++++++----- rom/exec/findtaskbypid.c | 26 +++++++++------ rom/exec/forbid.c | 11 +++++-- rom/exec/getparenttaskstorageslot.c | 5 +-- rom/exec/gettaskstorageslot.c | 4 +-- rom/exec/mungwall.c | 4 +-- rom/exec/obtainsemaphore.c | 6 ++-- rom/exec/obtainsemaphorelist.c | 16 +++++----- rom/exec/permit.c | 3 +- rom/exec/procure.c | 6 ++-- rom/exec/putmsg.c | 12 ++++--- rom/exec/releasesemaphore.c | 12 +++---- rom/exec/remove.c | 3 ++ rom/exec/remtask.c | 51 ++++++++++++++---------------- rom/exec/savetaskstorage.c | 4 +-- rom/exec/semaphores.c | 32 +++++++++---------- rom/exec/service.c | 6 ++-- rom/exec/setexcept.c | 23 ++++++++++---- rom/exec/setsignal.c | 18 ++++++++--- rom/exec/settaskstorageslot.c | 4 +-- rom/exec/signal.c | 19 +++++++---- rom/exec/supervisoralert.c | 4 +-- rom/exec/traphandler.c | 12 +++---- rom/exec/wait.c | 63 ++++++++++++++++++++++--------------- 38 files changed, 279 insertions(+), 191 deletions(-) diff --git a/rom/exec/allocmem.c b/rom/exec/allocmem.c index 93590f6c32..8b63ddb143 100644 --- a/rom/exec/allocmem.c +++ b/rom/exec/allocmem.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2012, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ Desc: Allocate some memory @@ -123,7 +123,7 @@ /* Set DOS error if called from a process */ if (res == NULL) { - struct Process *process = (struct Process *)FindTask(NULL); + struct Process *process = (struct Process *)GET_THIS_TASK; if (process->pr_Task.tc_Node.ln_Type == NT_PROCESS) process->pr_Result2 = ERROR_NO_FREE_STORE; } diff --git a/rom/exec/allocsignal.c b/rom/exec/allocsignal.c index 1d622edf40..6fee94d652 100644 --- a/rom/exec/allocsignal.c +++ b/rom/exec/allocsignal.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2011, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ Desc: Allocate a signal @@ -12,6 +12,9 @@ #include #include "exec_util.h" +#if defined(__AROSEXEC_SMP__) +#include "etask.h" +#endif /***************************************************************************** @@ -58,7 +61,7 @@ AROS_LIBFUNC_INIT /* Cast signalNum to BYTE for AOS/68k compatibility. Apps may set up only D0.b */ - return AllocTaskSignal(FindTask(NULL), (BYTE)signalNum, SysBase); + return AllocTaskSignal(GET_THIS_TASK, (BYTE)signalNum, SysBase); AROS_LIBFUNC_EXIT } /* AllocSignal() */ @@ -117,8 +120,16 @@ LONG AllocTaskSignal(struct Task *ThisTask, LONG signalNum, struct ExecBase *Sys ThisTask->tc_SigExcept &= ~mask1; ThisTask->tc_SigWait &= ~mask1; +#if defined(__AROSEXEC_SMP__) + EXEC_SPINLOCK_LOCK(&IntETask(ThisTask->tc_UnionETask.tc_ETask)->iet_TaskLock, SPINLOCK_MODE_WRITE); +#endif Disable(); + ThisTask->tc_SigRecvd &= ~mask1; + +#if defined(__AROSEXEC_SMP__) + EXEC_SPINLOCK_UNLOCK(&IntETask(ThisTask->tc_UnionETask.tc_ETask)->iet_TaskLock); +#endif Enable(); return signalNum; diff --git a/rom/exec/alloctaskstorageslot.c b/rom/exec/alloctaskstorageslot.c index e928c9338c..e4abc103cc 100644 --- a/rom/exec/alloctaskstorageslot.c +++ b/rom/exec/alloctaskstorageslot.c @@ -1,5 +1,5 @@ /* - Copyright © 2011-2012, The AROS Development Team. All rights reserved. + Copyright © 2011-2015, The AROS Development Team. All rights reserved. $Id$ */ @@ -45,9 +45,10 @@ { AROS_LIBFUNC_INIT + struct Task *ThisTask = GET_THIS_TASK; struct TaskStorageFreeSlot *tsfs; LONG slot; - struct IntETask *iet = GetIntETask(FindTask(NULL)); + struct IntETask *iet = GetIntETask(ThisTask); if (!iet) return 0; @@ -60,7 +61,7 @@ slot = tsfs->FreeSlot; - D(bug("[TSS] Task 0x%p (%s): Allocated slot %d\n", FindTask(NULL), FindTask(NULL)->tc_Node.ln_Name, slot)); + D(bug("[TSS] Task 0x%p (%s): Allocated slot %d\n", ThisTask, ThisTask->tc_Node.ln_Name, slot)); if (GetSucc(tsfs) == NULL) { diff --git a/rom/exec/alloctrap.c b/rom/exec/alloctrap.c index 72345c6f31..bd7db87baa 100644 --- a/rom/exec/alloctrap.c +++ b/rom/exec/alloctrap.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2007, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ Desc: Allocate a trap @@ -41,11 +41,10 @@ { AROS_LIBFUNC_INIT - struct Task *ThisTask; + struct Task *ThisTask = GET_THIS_TASK; UWORD mask; UWORD mask1; - - ThisTask = FindTask(NULL); + mask = GetTrapAlloc(ThisTask); /* Will any trap do? */ diff --git a/rom/exec/attemptsemaphore.c b/rom/exec/attemptsemaphore.c index 9a75b1d5b7..86419f4cb6 100644 --- a/rom/exec/attemptsemaphore.c +++ b/rom/exec/attemptsemaphore.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2011, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ Desc: Try to lock a sempahore. @@ -53,9 +53,9 @@ AROS_LIBFUNC_INIT struct TraceLocation tp = CURRENT_LOCATION("AttemptSemaphore"); - struct Task *me = FindTask(NULL); + struct Task *ThisTask = GET_THIS_TASK; - return InternalAttemptSemaphore(sigSem, me, &tp, SysBase); + return InternalAttemptSemaphore(sigSem, ThisTask, &tp, SysBase); AROS_LIBFUNC_EXIT } /* AttemptSemaphore */ diff --git a/rom/exec/childorphan.c b/rom/exec/childorphan.c index b90da61d4f..58a7eeddef 100644 --- a/rom/exec/childorphan.c +++ b/rom/exec/childorphan.c @@ -1,8 +1,8 @@ /* - Copyright © 1995-2007, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ - Desc: Make any children of this task orphans. + Desc: Make any children of ThisTask task orphans. Lang: english */ #include "exec_intern.h" @@ -32,7 +32,7 @@ INPUTS tid -- The ID of the task to orphan, or 0 for all tasks. Note - that this is NOT the pointer to the task. + that ThisTask is NOT the pointer to the task. RESULT Will return 0 on success or CHILD_* on an error. @@ -54,14 +54,14 @@ { AROS_LIBFUNC_INIT - struct Task *this = FindTask(NULL); + struct Task *ThisTask = GET_THIS_TASK; struct ETask *et, *child; - et = GetETask(this); - if(et == NULL) + et = GetETask(ThisTask); + if (et == NULL) return CHILD_NOTNEW; - if(tid == 0L) + if (tid == 0L) { Forbid(); ForeachNode(&et->et_Children, child) @@ -79,7 +79,7 @@ { Forbid(); child = FindChild(tid); - if(child != NULL) + if (child != NULL) { child->et_Parent = NULL; Remove((struct Node *)child); diff --git a/rom/exec/childstatus.c b/rom/exec/childstatus.c index d410e625e4..5bfd1d1248 100644 --- a/rom/exec/childstatus.c +++ b/rom/exec/childstatus.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2007, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ Find out the status of a child task. @@ -24,7 +24,7 @@ determine whether a particular child task is still running or not. INPUTS - tid -- The ID of the task to examine. Note that this is _NOT_ + tid -- The ID of the task to examine. Note that ThisTask is _NOT_ a task pointer. RESULT @@ -47,16 +47,15 @@ { AROS_LIBFUNC_INIT - struct Task *this; + struct Task *ThisTask = GET_THIS_TASK; struct ETask *et; struct ETask *child; ULONG status = CHILD_NOTFOUND; - this = FindTask(NULL); - if ((this->tc_Flags & TF_ETASK) == 0) + if ((ThisTask->tc_Flags & TF_ETASK) == 0) return CHILD_NOTNEW; - et = this->tc_UnionETask.tc_ETask; + et = ThisTask->tc_UnionETask.tc_ETask; /* Sigh... */ Forbid(); diff --git a/rom/exec/childwait.c b/rom/exec/childwait.c index 68c74d980d..081fa05751 100644 --- a/rom/exec/childwait.c +++ b/rom/exec/childwait.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2007, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ ChildWait() - Wait for a task to finish it processing. @@ -21,7 +21,7 @@ /* FUNCTION Wait for either a specific child task, or any child task to finish. - If you specify tid = 0, then this call will return when any child + If you specify tid = 0, then ThisTask call will return when any child task exits, otherwise it will not return until the requested task finishes. @@ -56,7 +56,7 @@ EXAMPLE BUGS - Be careful with the return result of this function. + Be careful with the return result of ThisTask function. SEE ALSO @@ -66,7 +66,7 @@ { AROS_LIBFUNC_INIT - struct Task *this = FindTask(NULL); + struct Task *ThisTask = GET_THIS_TASK; struct ETask *et; struct ETask *child; @@ -76,13 +76,13 @@ Firstly, are we a new-style Task? */ - if ((this->tc_Flags & TF_ETASK) == 0) + if ((ThisTask->tc_Flags & TF_ETASK) == 0) return CHILD_NOTNEW; - et = this->tc_UnionETask.tc_ETask; + et = ThisTask->tc_UnionETask.tc_ETask; /* - Scanning this list is unsafe, I need to Forbid(). Note that the + Scanning ThisTask list is unsafe, I need to Forbid(). Note that the Wait() below will break the Forbid() condition. This is how I need it to be. */ diff --git a/rom/exec/debug.c b/rom/exec/debug.c index b120c43827..90605743e5 100644 --- a/rom/exec/debug.c +++ b/rom/exec/debug.c @@ -284,7 +284,7 @@ static char *NextWord(char *s) #else node = (struct Node *)GET_THIS_TASK; #endif - kprintf("0x%p T %d %s\n",node, node->ln_Pri, node->ln_Name); + kprintf("0x%p T %d %s\n", node, node->ln_Pri, node->ln_Name); #if defined(__AROSEXEC_SMP__) } #endif diff --git a/rom/exec/disable.c b/rom/exec/disable.c index a4acb7ca1f..0d234342b7 100644 --- a/rom/exec/disable.c +++ b/rom/exec/disable.c @@ -78,6 +78,8 @@ AROS_LIBFUNC_INIT + D(bug("[EXEC] Disable()\n")); + if (KernelBase) KrnCli(); diff --git a/rom/exec/enable.c b/rom/exec/enable.c index e7b45ac9a4..3ed25cd1b5 100644 --- a/rom/exec/enable.c +++ b/rom/exec/enable.c @@ -76,11 +76,13 @@ AROS_LIBFUNC_INIT + D(bug("[EXEC] Enable()\n")); + IDNESTCOUNT_DEC; if (KernelBase && (IDNESTCOUNT_GET < 0)) { - D(bug("[Enable] Enabling interrupts\n")); + D(bug("[EXEC] Enable: Enabling interrupts\n")); KrnSti(); if (KrnIsSuper()) diff --git a/rom/exec/etask.h b/rom/exec/etask.h index 555f585e57..f5b0a14482 100644 --- a/rom/exec/etask.h +++ b/rom/exec/etask.h @@ -39,6 +39,7 @@ struct IntETask struct ETask iet_ETask; APTR iet_RT; /* Structure for resource tracking */ #if defined(__AROSEXEC_SMP__) + spinlock_t iet_TaskLock; IPTR iet_CpuNumber; /* core this task is currently running on */ IPTR iet_CpuAffinity; /* bitmap of cores this task can run on */ spinlock_t *iet_SpinLock; /* pointer to spinlock task is spinning on */ diff --git a/rom/exec/exec_autoinit.c b/rom/exec/exec_autoinit.c index 865006f922..aad50e30c7 100644 --- a/rom/exec/exec_autoinit.c +++ b/rom/exec/exec_autoinit.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012, The AROS Development Team + * Copyright (C) 2015, The AROS Development Team * All right reserved. * Author: Jason S. McMullan * diff --git a/rom/exec/exec_util.c b/rom/exec/exec_util.c index 355a4aba3c..a1809f5949 100644 --- a/rom/exec/exec_util.c +++ b/rom/exec/exec_util.c @@ -56,10 +56,11 @@ ******************************************************************************/ { + struct Task *ThisTask = GET_THIS_TASK; struct ETask *et; struct ETask *thisET; - thisET = GetETask(FindTask(NULL)); + thisET = GetETask(ThisTask); if (thisET != NULL) { ForeachNode (&thisET->et_Children, et) @@ -96,10 +97,11 @@ Exec_InitETask(struct Task *task, struct ExecBase *SysBase) task->tc_Flags |= TF_ETASK; #if defined(__AROSEXEC_SMP__) + EXEC_SPINLOCK_INIT(&IntETask(et)->iet_TaskLock); IntETask(et)->iet_CpuAffinity = (1 << 0); #endif - et->et_Parent = FindTask(NULL); + et->et_Parent = GET_THIS_TASK; NEWLIST(&et->et_Children); /* Initialise the message list */ diff --git a/rom/exec/findtask.c b/rom/exec/findtask.c index 650a9955bf..5956f60540 100644 --- a/rom/exec/findtask.c +++ b/rom/exec/findtask.c @@ -59,11 +59,21 @@ if (name == NULL) return GET_THIS_TASK; + /* Always protect task lists */ #if defined(__AROSEXEC_SMP__) - listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskReadySpinLock, SPINLOCK_MODE_READ); -#endif - /* Always protect task lists with a Disable(). */ + listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskRunningSpinLock, SPINLOCK_MODE_READ); + Forbid(); + /* Then into the waiting list. */ + ret = (struct Task *)FindName(&PrivExecBase(SysBase)->TaskRunning, name); + if (ret == NULL) + { + EXEC_SPINLOCK_UNLOCK(listLock); + Permit(); + listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskReadySpinLock, SPINLOCK_MODE_READ); + Forbid(); +#else Disable(); +#endif /* First look into the ready list. */ ret = (struct Task *)FindName(&SysBase->TaskReady, name); @@ -71,9 +81,9 @@ { #if defined(__AROSEXEC_SMP__) EXEC_SPINLOCK_UNLOCK(listLock); - Enable(); + Permit(); listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskWaitSpinLock, SPINLOCK_MODE_READ); - Disable(); + Forbid(); #endif /* Then into the waiting list. */ ret = (struct Task *)FindName(&SysBase->TaskWait, name); @@ -89,9 +99,9 @@ #if defined(__AROSEXEC_SMP__) EXEC_SPINLOCK_UNLOCK(listLock); - Enable(); + Permit(); listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskRunningSpinLock, SPINLOCK_MODE_READ); - Disable(); + Forbid(); ForeachNode(&PrivExecBase(SysBase)->TaskRunning, ret) { s1 = ret->tc_Node.ln_Name; @@ -117,9 +127,12 @@ } #if defined(__AROSEXEC_SMP__) + } EXEC_SPINLOCK_UNLOCK(listLock); -#endif + Permit(); +#else Enable(); +#endif /* Return whatever was found. */ return ret; diff --git a/rom/exec/findtaskbypid.c b/rom/exec/findtaskbypid.c index 74c0d49880..11893d73f2 100644 --- a/rom/exec/findtaskbypid.c +++ b/rom/exec/findtaskbypid.c @@ -56,8 +56,10 @@ /* First up, check running task(s) */ #if defined(__AROSEXEC_SMP__) listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskRunningSpinLock, SPINLOCK_MODE_READ); -#endif + Forbid(); +#else Disable(); +#endif #if defined(__AROSEXEC_SMP__) ForeachNode(&PrivExecBase(SysBase)->TaskRunning, t) { @@ -65,14 +67,14 @@ if (et != NULL && et->et_UniqueID == id) { EXEC_SPINLOCK_UNLOCK(listLock); - Enable(); + Permit(); return t; } } EXEC_SPINLOCK_UNLOCK(listLock); - Enable(); + Permit(); listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskReadySpinLock, SPINLOCK_MODE_READ); - Disable(); + Forbid(); #else if (GET_THIS_TASK != NULL) { @@ -92,16 +94,18 @@ { #if defined(__AROSEXEC_SMP__) EXEC_SPINLOCK_UNLOCK(listLock); -#endif + Permit(); +#else Enable(); +#endif return t; } } #if defined(__AROSEXEC_SMP__) EXEC_SPINLOCK_UNLOCK(listLock); - Enable(); + Permit(); listLock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskWaitSpinLock, SPINLOCK_MODE_READ); - Disable(); + Forbid(); #endif /* Finally, go through the wait list */ ForeachNode(&SysBase->TaskWait, t) @@ -111,16 +115,20 @@ { #if defined(__AROSEXEC_SMP__) EXEC_SPINLOCK_UNLOCK(listLock); -#endif + Permit(); +#else Enable(); +#endif return t; } } #if defined(__AROSEXEC_SMP__) EXEC_SPINLOCK_UNLOCK(listLock); -#endif + Permit(); +#else Enable(); +#endif return NULL; diff --git a/rom/exec/forbid.c b/rom/exec/forbid.c index 2ac5c9c2e9..505ccb7940 100644 --- a/rom/exec/forbid.c +++ b/rom/exec/forbid.c @@ -10,14 +10,17 @@ #include #include #include -#include -/*****************************************************************************/ -#undef Exec +#include "exec_intern.h" + +#undef Exec #ifdef UseExecstubs # define Exec _Exec #endif +/***************************************************************************** + + /* NAME */ #include @@ -73,6 +76,8 @@ AROS_LIBFUNC_INIT + D(bug("[EXEC] Forbid()\n")); + TDNESTCOUNT_INC; AROS_LIBFUNC_EXIT diff --git a/rom/exec/getparenttaskstorageslot.c b/rom/exec/getparenttaskstorageslot.c index 045bdfed6f..3a799b30b7 100644 --- a/rom/exec/getparenttaskstorageslot.c +++ b/rom/exec/getparenttaskstorageslot.c @@ -1,5 +1,5 @@ /* - Copyright © 2014, The AROS Development Team. All rights reserved. + Copyright © 2014-2015, The AROS Development Team. All rights reserved. $Id$ */ @@ -48,7 +48,8 @@ { AROS_LIBFUNC_INIT - struct ETask *et = GetETask(FindTask(NULL)); + struct Task *ThisTask = GET_THIS_TASK; + struct ETask *et = GetETask(ThisTask); IPTR result = (IPTR)NULL; if (!et) diff --git a/rom/exec/gettaskstorageslot.c b/rom/exec/gettaskstorageslot.c index 9795d2c2c1..a9ff6122d5 100644 --- a/rom/exec/gettaskstorageslot.c +++ b/rom/exec/gettaskstorageslot.c @@ -1,5 +1,5 @@ /* - Copyright © 2012-2014, The AROS Development Team. All rights reserved. + Copyright © 2012-2015, The AROS Development Team. All rights reserved. $Id$ */ @@ -48,7 +48,7 @@ { AROS_LIBFUNC_INIT - return TaskGetStorageSlot(FindTask(NULL), id); + return TaskGetStorageSlot(GET_THIS_TASK, id); AROS_LIBFUNC_EXIT } diff --git a/rom/exec/mungwall.c b/rom/exec/mungwall.c index 1ac46b2785..303dc701e5 100644 --- a/rom/exec/mungwall.c +++ b/rom/exec/mungwall.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2011, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ Desc: MungWall memory anti-trashing checker @@ -48,7 +48,7 @@ APTR MungWall_Build(APTR res, APTR pool, IPTR origSize, ULONG requirements, stru header->mwh_allocsize = origSize; header->mwh_pool = pool; header->mwh_AllocFunc = loc->function; - header->mwh_Owner = FindTask(NULL); + header->mwh_Owner = GET_THIS_TASK; header->mwh_Caller = loc->caller; /* Skip to the start of data space */ diff --git a/rom/exec/obtainsemaphore.c b/rom/exec/obtainsemaphore.c index 082c1c35c1..b14e9ae83e 100644 --- a/rom/exec/obtainsemaphore.c +++ b/rom/exec/obtainsemaphore.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2011, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ Desc: Lock a semaphore. @@ -59,9 +59,9 @@ AROS_LIBFUNC_INIT struct TraceLocation tp = CURRENT_LOCATION("ObtainSemaphore"); - struct Task *me = FindTask(NULL); + struct Task *ThisTask = GET_THIS_TASK; - InternalObtainSemaphore(sigSem, me, &tp, SysBase); + InternalObtainSemaphore(sigSem, ThisTask, &tp, SysBase); AROS_LIBFUNC_EXIT } /* ObtainSemaphore */ diff --git a/rom/exec/obtainsemaphorelist.c b/rom/exec/obtainsemaphorelist.c index 13c2218811..7a9fe27618 100644 --- a/rom/exec/obtainsemaphorelist.c +++ b/rom/exec/obtainsemaphorelist.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2001, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ Desc: Lock all semaphores in the list at once. @@ -54,7 +54,7 @@ AROS_LIBFUNC_INIT struct SignalSemaphore *ss; - struct Task * const me = FindTask(NULL); + struct Task * const ThisTask = GET_THIS_TASK; WORD failedObtain = 0; /* @@ -81,15 +81,15 @@ ss->ss_QueueCount++; if(ss->ss_QueueCount != 0) { - /* sem already locked by me? */ - if (ss->ss_Owner != me) + /* sem already locked by ThisTask? */ + if (ss->ss_Owner != ThisTask) { /* * Locked by someone else, post a wait message. We use the field * ss_MultipleLink, which is why this function requires an * external arbitrator. */ - ss->ss_MultipleLink.sr_Waiter = me; + ss->ss_MultipleLink.sr_Waiter = ThisTask; AddTail ( (struct List *)&ss->ss_WaitQueue, @@ -99,7 +99,7 @@ } else { - /* Already locked by me */ + /* Already locked by ThisTask */ ss->ss_NestCount++; } } @@ -107,7 +107,7 @@ { /* We have it... */ ss->ss_NestCount++; - ss->ss_Owner = me; + ss->ss_Owner = ThisTask; } } @@ -117,7 +117,7 @@ while(ss->ss_Link.ln_Succ != NULL) { - if(ss->ss_Owner != me) + if(ss->ss_Owner != ThisTask) { /* * Somebody else has this one. Wait, then check again. diff --git a/rom/exec/permit.c b/rom/exec/permit.c index ea59d9cd04..b5dcd9ab29 100644 --- a/rom/exec/permit.c +++ b/rom/exec/permit.c @@ -21,7 +21,6 @@ # define Exec _Exec #endif - /***************************************************************************** NAME */ @@ -71,6 +70,8 @@ { AROS_LIBFUNC_INIT + D(bug("[EXEC] Permit()\n")); + /* Task switches are allowed again, if a switch is pending, we should allow it. diff --git a/rom/exec/procure.c b/rom/exec/procure.c index 91ead71067..309a7423b0 100644 --- a/rom/exec/procure.c +++ b/rom/exec/procure.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2007, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ Desc: Try to lock a semaphore. @@ -65,7 +65,7 @@ if( (IPTR)(bidMsg->ssm_Message.mn_Node.ln_Name) == SM_SHARED ) bidMsg->ssm_Semaphore = NULL; else - bidMsg->ssm_Semaphore = (struct SignalSemaphore *)FindTask(NULL); + bidMsg->ssm_Semaphore = (struct SignalSemaphore *)GET_THIS_TASK; /* Arbitrate for the semaphore structure - following like ObtainSema() */ Forbid(); @@ -128,7 +128,7 @@ /* All done. */ Permit(); - /* Huh? */ return 0; + AROS_LIBFUNC_EXIT } /* Procure */ diff --git a/rom/exec/putmsg.c b/rom/exec/putmsg.c index 7c08ec994e..50329fd7bd 100644 --- a/rom/exec/putmsg.c +++ b/rom/exec/putmsg.c @@ -61,7 +61,7 @@ ASSERT_VALID_PTR(port); /* Set the node type to NT_MESSAGE == sent message. */ - message->mn_Node.ln_Type=NT_MESSAGE; + message->mn_Node.ln_Type = NT_MESSAGE; InternalPutMsg(port, message, SysBase); @@ -74,7 +74,7 @@ void InternalPutMsg(struct MsgPort *port, struct Message *message, struct ExecBa Therefore the message list of the message port must be protected with Disable() */ Disable(); - AddTail(&port->mp_MsgList,&message->mn_Node); + AddTail(&port->mp_MsgList, &message->mn_Node); Enable(); if (port->mp_SigTask) @@ -85,12 +85,14 @@ void InternalPutMsg(struct MsgPort *port, struct Message *message, struct ExecBa switch(port->mp_Flags & PF_ACTION) { case PA_SIGNAL: + D(bug("[EXEC] PutMsg: PA_SIGNAL, task 0x%p, signal %08x\n", port->mp_SigTask, (1 << port->mp_SigBit))); + /* Send the signal */ - Signal((struct Task *)port->mp_SigTask,1<mp_SigBit); + Signal((struct Task *)port->mp_SigTask, (1 << port->mp_SigBit)); break; case PA_SOFTINT: - D(bug("PutMsg: PA_SOFTINT, port 0x%p, msg 0x%p, int %s\n", port, message, ((struct Interrupt *)port->mp_SoftInt)->is_Node.ln_Name)); + D(bug("[EXEC] PutMsg: PA_SOFTINT, port 0x%p, msg 0x%p, int %s\n", port, message, ((struct Interrupt *)port->mp_SoftInt)->is_Node.ln_Name)); /* Raise a software interrupt */ Cause((struct Interrupt *)port->mp_SoftInt); @@ -101,6 +103,8 @@ void InternalPutMsg(struct MsgPort *port, struct Message *message, struct ExecBa break; case PA_CALL: + D(bug("[EXEC] PutMsg: PA_CALL, task 0x%p, port 0x%p\n", port->mp_SigTask, port)); + /* Call the function in mp_SigTask. */ AROS_UFC2NR(void, port->mp_SigTask, AROS_UFCA(struct MsgPort *, port, D0), diff --git a/rom/exec/releasesemaphore.c b/rom/exec/releasesemaphore.c index 262844aa43..1dbd21ba4e 100644 --- a/rom/exec/releasesemaphore.c +++ b/rom/exec/releasesemaphore.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2013, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ Desc: Release a semaphore. @@ -61,13 +61,13 @@ AROS_LIBFUNC_INIT struct TraceLocation tp = CURRENT_LOCATION("ReleaseSemaphore"); - struct Task *me = FindTask(NULL); + struct Task *ThisTask = GET_THIS_TASK; /* We can be called from within exec's pre-init code. It's okay. */ - if (!me) + if (!ThisTask) return; - if (me->tc_State == TS_REMOVED) + if (ThisTask->tc_State == TS_REMOVED) return; if (!CheckSemaphore(sigSem, &tp, SysBase)) @@ -87,9 +87,9 @@ semaphore, or not. If we are not, make sure that the correct Task is calling ReleaseSemaphore() */ - + #if CHECK_TASK - if (sigSem->ss_Owner != NULL && sigSem->ss_Owner != me) + if (sigSem->ss_Owner != NULL && sigSem->ss_Owner != ThisTask) { /* If it is not, there is a chance that the semaphore diff --git a/rom/exec/remove.c b/rom/exec/remove.c index 4af4616fca..8257b05d90 100644 --- a/rom/exec/remove.c +++ b/rom/exec/remove.c @@ -62,6 +62,9 @@ */ node->ln_Pred->ln_Succ = node->ln_Succ; node->ln_Succ->ln_Pred = node->ln_Pred; + node->ln_Succ = NULL; + node->ln_Pred = NULL; + AROS_LIBFUNC_EXIT } /* Remove */ diff --git a/rom/exec/remtask.c b/rom/exec/remtask.c index e3fa71fbe9..9a240cbe1d 100644 --- a/rom/exec/remtask.c +++ b/rom/exec/remtask.c @@ -61,35 +61,38 @@ struct MemList *mb; struct ETask *et; - BOOL suicide; #if defined(__AROSEXEC_SMP__) spinlock_t *task_listlock = NULL; #endif + struct Task *suicide = GET_THIS_TASK; /* A value of NULL means current task */ - if (task==NULL) - task=GET_THIS_TASK; + if (task == NULL) + task = suicide; DREMTASK("RemTask (0x%p (\"%s\"))", task, task->tc_Node.ln_Name); - /* Don't let any other task interfere with us at the moment - */ #if !defined(__AROSEXEC_SMP__) + /* Don't let any other task interfere with us at the moment */ Forbid(); #endif - suicide = (task == GET_THIS_TASK); - if (suicide) + if (suicide == task) + { DREMTASK("Removing itself"); - - /* Remove() here, before freeing the MemEntry list. Because - the MemEntry list might contain the task struct itself! */ - - if (!suicide) + } + else { + /* + * Remove() here, before freeing the MemEntry list. Because + * the MemEntry list might contain the task struct itself! + */ #if defined(__AROSEXEC_SMP__) switch (task->tc_State) { + case TS_SPIN: + task_listlock =&PrivExecBase(SysBase)->TaskSpinningLock; + break; case TS_RUN: task_listlock =&PrivExecBase(SysBase)->TaskRunningSpinLock; break; @@ -101,7 +104,7 @@ break; } EXEC_SPINLOCK_LOCK(task_listlock, SPINLOCK_MODE_WRITE); - Disable(); + Forbid(); #endif Remove(&task->tc_Node); #if defined(__AROSEXEC_SMP__) @@ -125,8 +128,8 @@ DREMTASK("Cleaning up ETask et=%p", et); CleanupETask(task); - /* Freeing myself? */ - if (suicide) + /* Freeing itself? */ + if (suicide == task) { /* * Send task to task cleaner to clean up memory. This avoids ripping @@ -138,23 +141,22 @@ InternalPutMsg(((struct IntExecBase *)SysBase)->ServicePort, (struct Message *)task, SysBase); -#if !defined(__AROSEXEC_SMP__) /* Changing the task lists always needs a Disable(). */ Disable(); -#endif /* - Since I don't know how many levels of Forbid() - are already pending I set a default value. + * We don't know how many levels of Forbid() + * are already pending, so use a default value. */ TDNESTCOUNT_SET(-1); - /* And force a task switch. Note: Dispatch, not Switch, - because the state of ThisTask must not be saved + /* + * Force rescheduling. + * Note #1: We dont want to preseve the task context so use Dispatch, not Switch. + * Note #2: We will never return from the dispatch to "ThisTask" */ KrnDispatch(); - /* Does not return. */ } else { @@ -169,12 +171,7 @@ } /* All done. */ -#if defined(__AROSEXEC_SMP__) - if (task_listlock) - Enable(); -#else Permit(); -#endif DREMTASK("Success"); diff --git a/rom/exec/savetaskstorage.c b/rom/exec/savetaskstorage.c index 74c56298da..80c3e8e755 100644 --- a/rom/exec/savetaskstorage.c +++ b/rom/exec/savetaskstorage.c @@ -1,5 +1,5 @@ /* - Copyright © 2012, The AROS Development Team. All rights reserved. + Copyright © 2015, The AROS Development Team. All rights reserved. $Id$ */ @@ -49,7 +49,7 @@ { AROS_LIBFUNC_INIT - struct ETask *et = GetETask(FindTask(NULL)); + struct ETask *et = GetETask(GET_THIS_TASK); IPTR *taskstorage, *tsout; IPTR slots; diff --git a/rom/exec/semaphores.c b/rom/exec/semaphores.c index 1ecd7c4605..d6cb512eb9 100644 --- a/rom/exec/semaphores.c +++ b/rom/exec/semaphores.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2012, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ Desc: Semaphore internal handling @@ -21,10 +21,10 @@ BOOL CheckSemaphore(struct SignalSemaphore *sigSem, struct TraceLocation *caller if (KernelBase && KrnIsSuper()) { /* FindTask() is called only here, for speedup */ - struct Task *me = FindTask(NULL); + struct Task *ThisTask = GET_THIS_TASK; kprintf("%s called in supervisor mode!!!\n" - "sem = 0x%p task = 0x%p (%s)\n\n", caller->function, sigSem, me, me->tc_Node.ln_Name); + "sem = 0x%p task = 0x%p (%s)\n\n", caller->function, sigSem, ThisTask, ThisTask->tc_Node.ln_Name); Exec_ExtAlert(ACPU_PrivErr & ~AT_DeadEnd, __builtin_return_address(0), CALLER_FRAME, 0, NULL, SysBase); return FALSE; @@ -32,10 +32,10 @@ BOOL CheckSemaphore(struct SignalSemaphore *sigSem, struct TraceLocation *caller if ((sigSem->ss_Link.ln_Type != NT_SIGNALSEM) || (sigSem->ss_WaitQueue.mlh_Tail != NULL)) { - struct Task *me = FindTask(NULL); + struct Task *ThisTask = GET_THIS_TASK; kprintf("%s called on a not initialized semaphore!!!\n" - "sem = 0x%p task = 0x%p (%s)\n\n", caller->function, sigSem, me, me->tc_Node.ln_Name); + "sem = 0x%p task = 0x%p (%s)\n\n", caller->function, sigSem, ThisTask, ThisTask->tc_Node.ln_Name); Exec_ExtAlert(AN_SemCorrupt, __builtin_return_address(0), CALLER_FRAME, 0, NULL, SysBase); return FALSE; @@ -46,21 +46,21 @@ BOOL CheckSemaphore(struct SignalSemaphore *sigSem, struct TraceLocation *caller void InternalObtainSemaphore(struct SignalSemaphore *sigSem, struct Task *owner, struct TraceLocation *caller, struct ExecBase *SysBase) { - struct Task *me = FindTask(NULL); + struct Task *ThisTask = GET_THIS_TASK; /* * If there's no ThisTask, the function is called from within memory * allocator in exec's pre-init code. We are already single-threaded, * just return. :) */ - if (!me) + if (!ThisTask) return; /* * Freeing memory during RemTask(NULL). We are already single-threaded by * Forbid(), and waiting isn't possible because task context is being deallocated. */ - if (me->tc_State == TS_REMOVED) + if (ThisTask->tc_State == TS_REMOVED) return; if (!CheckSemaphore(sigSem, caller, SysBase)) @@ -88,14 +88,14 @@ void InternalObtainSemaphore(struct SignalSemaphore *sigSem, struct Task *owner, /* * The semaphore is in use. * It could be either shared (ss_Owner == NULL) or it could already be exclusively owned - * by me (ss_Owner == me). + * by this task (ss_Owner == ThisTask). * Exclusive or shared mode of this function is determined by 'owner' parameter. * Actually it's pointer to a task which is allowed to share the lock with us. - * If it's equal to 'me', we are locking the semaphore in exclusive more. If it's NULL, + * If it's equal to 'ThisTask', we are locking the semaphore in exclusive more. If it's NULL, * we are locking in shared mode. This helps to optimize code against speed, and remove * extra comparisons. */ - else if ((sigSem->ss_Owner == me) || (sigSem->ss_Owner == owner)) + else if ((sigSem->ss_Owner == ThisTask) || (sigSem->ss_Owner == owner)) { /* Yes, just increase the nesting count */ sigSem->ss_NestCount++; @@ -108,7 +108,7 @@ void InternalObtainSemaphore(struct SignalSemaphore *sigSem, struct Task *owner, * stack memory. */ struct SemaphoreRequest sr; - sr.sr_Waiter = me; + sr.sr_Waiter = ThisTask; if (owner == NULL) sr.sr_Waiter = (struct Task *)((IPTR)(sr.sr_Waiter) | SM_SHARED); @@ -121,7 +121,7 @@ void InternalObtainSemaphore(struct SignalSemaphore *sigSem, struct Task *owner, */ /* This must be atomic! */ - AROS_ATOMIC_AND(me->tc_SigRecvd, ~SIGF_SINGLE); + AROS_ATOMIC_AND(ThisTask->tc_SigRecvd, ~SIGF_SINGLE); AddTail((struct List *)&sigSem->ss_WaitQueue, (struct Node *)&sr); @@ -138,7 +138,7 @@ void InternalObtainSemaphore(struct SignalSemaphore *sigSem, struct Task *owner, ULONG InternalAttemptSemaphore(struct SignalSemaphore *sigSem, struct Task *owner, struct TraceLocation *caller, struct ExecBase *SysBase) { - struct Task *me = FindTask(NULL); + struct Task *ThisTask = GET_THIS_TASK; ULONG retval = TRUE; if (!CheckSemaphore(sigSem, caller, SysBase)) @@ -159,9 +159,9 @@ ULONG InternalAttemptSemaphore(struct SignalSemaphore *sigSem, struct Task *owne sigSem->ss_Owner = owner; sigSem->ss_NestCount++; } - else if ((sigSem->ss_Owner == me) || (sigSem->ss_Owner == owner)) + else if ((sigSem->ss_Owner == ThisTask) || (sigSem->ss_Owner == owner)) { - /* The semaphore was owned by me or is shared, just increase the nest count */ + /* The semaphore was owned by this task, or is shared, just increase the nest count */ sigSem->ss_NestCount++; } else diff --git a/rom/exec/service.c b/rom/exec/service.c index 5948c11189..c4104aba71 100644 --- a/rom/exec/service.c +++ b/rom/exec/service.c @@ -70,12 +70,12 @@ void ServiceTask(struct ExecBase *SysBase) task->tc_State = TS_READY; #if defined(__AROSEXEC_SMP__) EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskReadySpinLock, SPINLOCK_MODE_READ); - Disable(); + Forbid(); #endif - Enqueue(&SysBase->TaskReady,&task->tc_Node); + Enqueue(&SysBase->TaskReady, &task->tc_Node); #if defined(__AROSEXEC_SMP__) EXEC_SPINLOCK_UNLOCK(&PrivExecBase(SysBase)->TaskReadySpinLock); - Enable(); + Permit(); #endif break; } diff --git a/rom/exec/setexcept.c b/rom/exec/setexcept.c index fa8ff66fc7..b724798003 100644 --- a/rom/exec/setexcept.c +++ b/rom/exec/setexcept.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2011, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ Desc: Examine and/or modify the signals which cause an exception. @@ -10,6 +10,11 @@ #include #include +#include "exec_intern.h" +#if defined(__AROSEXEC_SMP__) +#include "etask.h" +#endif + /***************************************************************************** NAME */ @@ -51,27 +56,33 @@ AROS_LIBFUNC_INIT /* Get pointer to current task */ - struct Task *me = FindTask(NULL); + struct Task *ThisTask = GET_THIS_TASK; ULONG old; /* Protect mask of sent signals and task lists */ +#if defined(__AROSEXEC_SMP__) + EXEC_SPINLOCK_LOCK(&IntETask(ThisTask->tc_UnionETask.tc_ETask)->iet_TaskLock, SPINLOCK_MODE_WRITE); +#endif Disable(); /* Get returncode */ - old=me->tc_SigExcept; + old = ThisTask->tc_SigExcept; /* Change exception mask */ - me->tc_SigExcept=(old&~signalSet)|(newSignals&signalSet); + ThisTask->tc_SigExcept = (old & ~signalSet) | (newSignals & signalSet); /* Does this change include an exception? */ - if (me->tc_SigExcept & me->tc_SigRecvd) + if (ThisTask->tc_SigExcept & ThisTask->tc_SigRecvd) { /* Yes. Set the exception flag. */ - me->tc_Flags|=TF_EXCEPT; + ThisTask->tc_Flags |= TF_EXCEPT; /* And order rescheduling */ Reschedule(); } +#if defined(__AROSEXEC_SMP__) + EXEC_SPINLOCK_UNLOCK(&IntETask(ThisTask->tc_UnionETask.tc_ETask)->iet_TaskLock); +#endif Enable(); return old; diff --git a/rom/exec/setsignal.c b/rom/exec/setsignal.c index dc2f95c012..15dc2e04ca 100644 --- a/rom/exec/setsignal.c +++ b/rom/exec/setsignal.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2001, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ Desc: Examine and/or modify the signals of a task. @@ -10,6 +10,9 @@ #include #include "exec_intern.h" +#if defined(__AROSEXEC_SMP__) +#include "etask.h" +#endif /***************************************************************************** @@ -49,19 +52,26 @@ { AROS_LIBFUNC_INIT + struct Task *ThisTask = GET_THIS_TASK; ULONG *sig; ULONG old; /* Protect the signal mask against access by other tasks. */ +#if defined(__AROSEXEC_SMP__) + EXEC_SPINLOCK_LOCK(&IntETask(ThisTask->tc_UnionETask.tc_ETask)->iet_TaskLock, SPINLOCK_MODE_WRITE); +#endif Disable(); /* Get address */ - sig=&GET_THIS_TASK->tc_SigRecvd; + sig = &ThisTask->tc_SigRecvd; /* Change only the bits in 'mask' */ - old=*sig; - *sig=(old&~signalSet)|(newSignals&signalSet); + old = *sig; + *sig = (old & ~signalSet) | (newSignals & signalSet); +#if defined(__AROSEXEC_SMP__) + EXEC_SPINLOCK_UNLOCK(&IntETask(ThisTask->tc_UnionETask.tc_ETask)->iet_TaskLock); +#endif Enable(); return old; diff --git a/rom/exec/settaskstorageslot.c b/rom/exec/settaskstorageslot.c index f95747865a..9f83b2eb60 100644 --- a/rom/exec/settaskstorageslot.c +++ b/rom/exec/settaskstorageslot.c @@ -1,5 +1,5 @@ /* - Copyright © 2012, The AROS Development Team. All rights reserved. + Copyright © 2012-2015, The AROS Development Team. All rights reserved. $Id$ */ @@ -49,7 +49,7 @@ { AROS_LIBFUNC_INIT - struct ETask *et = GetETask(FindTask(NULL)); + struct ETask *et = GetETask(GET_THIS_TASK); IPTR *ts; D(bug("SetTaskStorage: %p: Set TaskStorageSlot %d to %p\n", et, id, (APTR)value)); diff --git a/rom/exec/signal.c b/rom/exec/signal.c index c289012056..75082dfdf2 100644 --- a/rom/exec/signal.c +++ b/rom/exec/signal.c @@ -86,8 +86,10 @@ } EXEC_SPINLOCK_LOCK(task_listlock, SPINLOCK_MODE_WRITE); D(bug("[Exec] Signal: initial lock @ 0x%p\n", task_listlock)); -#endif + Forbid(); +#else Disable(); +#endif D(bug("[Exec] Signal: multitasking disabled\n")); @@ -116,16 +118,19 @@ #endif /* Order a reschedule */ Reschedule(); + #if defined(__AROSEXEC_SMP__) } else { D(bug("[Exec] Signal:\n")); } -#endif - /* All done. */ + Permit(); +#else Enable(); +#endif + /* All done. */ return; } } @@ -144,9 +149,9 @@ task->tc_State = TS_READY; #if defined(__AROSEXEC_SMP__) EXEC_SPINLOCK_UNLOCK(task_listlock); - Enable(); + Permit(); task_listlock = EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskReadySpinLock, SPINLOCK_MODE_WRITE); - Disable(); + Forbid(); #endif Enqueue(&SysBase->TaskReady, &task->tc_Node); #if defined(__AROSEXEC_SMP__) @@ -175,9 +180,11 @@ if (task_listlock) { EXEC_SPINLOCK_UNLOCK(task_listlock); + Permit(); } -#endif +#else Enable(); +#endif D(bug("[Exec] Signal: 0x%p finished signal processing\n", task)); diff --git a/rom/exec/supervisoralert.c b/rom/exec/supervisoralert.c index fffecba5d8..2f55ce1164 100644 --- a/rom/exec/supervisoralert.c +++ b/rom/exec/supervisoralert.c @@ -1,5 +1,5 @@ /* - Copyright © 2012, The AROS Development Team. All rights reserved. + Copyright © 2012-2015, The AROS Development Team. All rights reserved. $Id$ Desc: Display an alert passed from supervisor mode. @@ -36,7 +36,7 @@ void SupervisorAlertTask(struct ExecBase *SysBase) struct Task * t = NULL; ULONG alertNum = 0; - IntSysBase->SAT.sat_Task = FindTask(NULL); + IntSysBase->SAT.sat_Task = GET_THIS_TASK; IntSysBase->SAT.sat_IsAvailable = TRUE; while(TRUE) diff --git a/rom/exec/traphandler.c b/rom/exec/traphandler.c index 8b570aa863..c5239d898c 100644 --- a/rom/exec/traphandler.c +++ b/rom/exec/traphandler.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2012, The AROS Development Team. All rights reserved. + Copyright © 1995-2015, The AROS Development Team. All rights reserved. $Id$ Desc: Default trap handler @@ -20,8 +20,8 @@ */ static void Exec_CrashHandler(void) { - struct Task *task = FindTask(NULL); - struct IntETask *iet = GetIntETask(task); + struct Task *ThisTask = GET_THIS_TASK; + struct IntETask *iet = GetIntETask(ThisTask); /* Makes Alert() attempting to bring up Intuition requester */ iet->iet_AlertFlags &= ~AF_Alert; @@ -67,7 +67,7 @@ void Exec__TrapHandler(ULONG trapNum, struct ExceptionContext *ctx) void Exec_TrapHandler(ULONG trapNum, struct ExceptionContext *ctx) #endif { - struct Task *task = GET_THIS_TASK; + struct Task *ThisTask = GET_THIS_TASK; /* Our situation is deadend */ trapNum |= AT_DeadEnd; @@ -76,10 +76,10 @@ void Exec_TrapHandler(ULONG trapNum, struct ExceptionContext *ctx) * We must have a valid ETask in order to be able * to display a requester in user mode. */ - if (task && (task->tc_Flags & TF_ETASK) && (task->tc_State != TS_REMOVED)) + if (ThisTask && (ThisTask->tc_Flags & TF_ETASK) && (ThisTask->tc_State != TS_REMOVED)) { /* Get internal task structure */ - struct IntETask *iet = GetIntETask(task); + struct IntETask *iet = GetIntETask(ThisTask); if (iet->iet_AlertFlags & AF_Alert) { diff --git a/rom/exec/wait.c b/rom/exec/wait.c index 468fad2cc9..edc004cdd6 100644 --- a/rom/exec/wait.c +++ b/rom/exec/wait.c @@ -14,6 +14,9 @@ #include #include "exec_intern.h" +#if defined(__AROSEXEC_SMP__) +#include "etask.h" +#endif /***************************************************************************** @@ -60,32 +63,32 @@ { AROS_LIBFUNC_INIT + struct Task *ThisTask = GET_THIS_TASK; #if defined(__AROSEXEC_SMP__) spinlock_t *task_listlock = NULL; #endif ULONG rcvd; - struct Task *me; - - /* Get pointer to current task - I'll need it very often */ - me = FindTask(NULL); D(bug("[Exec] Wait(%08lX)\n", signalSet)); +#if !defined(__AROSEXEC_SMP__) + Disable(); +#endif /* If at least one of the signals is already set do not wait. */ - while (!(me->tc_SigRecvd & signalSet)) + while (!(ThisTask->tc_SigRecvd & signalSet)) { /* Set the wait signal mask */ - me->tc_SigWait = signalSet; + ThisTask->tc_SigWait = signalSet; #if defined(__AROSEXEC_SMP__) - if (me->tc_State != TS_WAIT) + if (ThisTask->tc_State != TS_WAIT) { #endif - D(bug("[Exec] Moving '%s' @ 0x%p to Task Wait queue\n", me->tc_Node.ln_Name, me)); - D(bug("[Exec] Task state = %08x\n", me->tc_State)); + D(bug("[Exec] Moving '%s' @ 0x%p to Task Wait queue\n", ThisTask->tc_Node.ln_Name, ThisTask)); + D(bug("[Exec] Task state = %08x\n", ThisTask->tc_State)); /* Protect the task lists against access by other tasks. */ #if defined(__AROSEXEC_SMP__) - switch (me->tc_State) + switch (ThisTask->tc_State) { case TS_RUN: task_listlock = &PrivExecBase(SysBase)->TaskRunningSpinLock; @@ -95,32 +98,30 @@ break; } EXEC_SPINLOCK_LOCK(task_listlock, SPINLOCK_MODE_WRITE); -#endif - Disable(); -#if defined(__AROSEXEC_SMP__) - Remove(&me->tc_Node); + Forbid(); + Remove(&ThisTask->tc_Node); EXEC_SPINLOCK_UNLOCK(task_listlock); - Enable(); + Permit(); EXEC_SPINLOCK_LOCK(&PrivExecBase(SysBase)->TaskWaitSpinLock, SPINLOCK_MODE_WRITE); - Disable(); + Forbid(); #endif /* Clear TDNestCnt (because Switch() will not care about it), but memorize it first. IDNestCnt is handled by Switch(). */ - me->tc_TDNestCnt = TDNESTCOUNT_GET; + ThisTask->tc_TDNestCnt = TDNESTCOUNT_GET; TDNESTCOUNT_SET(-1); /* Move current task to the waiting list. */ - me->tc_State = TS_WAIT; - Enqueue(&SysBase->TaskWait, &me->tc_Node); + ThisTask->tc_State = TS_WAIT; + Enqueue(&SysBase->TaskWait, &ThisTask->tc_Node); #if defined(__AROSEXEC_SMP__) EXEC_SPINLOCK_UNLOCK(&PrivExecBase(SysBase)->TaskWaitSpinLock); } else { - Disable(); - me->tc_TDNestCnt = TDNESTCOUNT_GET; + Forbid(); + ThisTask->tc_TDNestCnt = TDNESTCOUNT_GET; TDNESTCOUNT_SET(-1); } #endif @@ -128,21 +129,31 @@ KrnSwitch(); /* - OK. Somebody awakened me. This means that either the + OK. Somebody awakened us. This means that either the signals are there or it's just a finished task exception. Test again to be sure (see above). */ /* Restore TDNestCnt. */ - TDNESTCOUNT_SET(me->tc_TDNestCnt); + TDNESTCOUNT_SET(ThisTask->tc_TDNestCnt); - Enable(); +#if defined(__AROSEXEC_SMP__) + Permit(); +#endif } /* Get active signals. */ - rcvd = (me->tc_SigRecvd & signalSet); + rcvd = (ThisTask->tc_SigRecvd & signalSet); /* And clear them. */ - me->tc_SigRecvd &= ~signalSet; +#if defined(__AROSEXEC_SMP__) + EXEC_SPINLOCK_LOCK(&IntETask(ThisTask->tc_UnionETask.tc_ETask)->iet_TaskLock, SPINLOCK_MODE_WRITE); + Disable(); +#endif + ThisTask->tc_SigRecvd &= ~signalSet; +#if defined(__AROSEXEC_SMP__) + EXEC_SPINLOCK_UNLOCK(&IntETask(ThisTask->tc_UnionETask.tc_ETask)->iet_TaskLock); +#endif + Enable(); /* All done. */ return rcvd; -- 2.11.4.GIT