From 1cbd21ded760ffb33c8a2f16d05c574e58166148 Mon Sep 17 00:00:00 2001 From: deadwood Date: Fri, 1 Aug 2014 16:06:20 +0000 Subject: [PATCH] exec.library: implement GetParentTaskStorageSlot() git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@49201 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- rom/exec/exec.conf | 1 + rom/exec/getparenttaskstorageslot.c | 66 +++++++++++++++++++++++++++++++++++++ rom/exec/gettaskstorageslot.c | 19 +++++++---- rom/exec/mmakefile.src | 3 +- rom/exec/settaskstorageslot.c | 2 ++ rom/exec/taskstorage.h | 4 ++- 6 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 rom/exec/getparenttaskstorageslot.c diff --git a/rom/exec/exec.conf b/rom/exec/exec.conf index 6497eaf1c9..4c534f7a35 100644 --- a/rom/exec/exec.conf +++ b/rom/exec/exec.conf @@ -268,4 +268,5 @@ APTR SaveTaskStorage() () void RestoreTaskStorage(APTR id) (A0) BOOL SetTaskStorageSlot(LONG id, IPTR value) (D0, D1) IPTR GetTaskStorageSlot(LONG id) (D0) +IPTR GetParentTaskStorageSlot(LONG id) (D0) ##end functionlist diff --git a/rom/exec/getparenttaskstorageslot.c b/rom/exec/getparenttaskstorageslot.c new file mode 100644 index 0000000000..6230da210a --- /dev/null +++ b/rom/exec/getparenttaskstorageslot.c @@ -0,0 +1,66 @@ +/* + Copyright © 2014, The AROS Development Team. All rights reserved. + $Id$ +*/ + +#include + +#include "taskstorage.h" + +/***************************************************************************** + + NAME */ +#include + + AROS_LH1(IPTR, GetParentTaskStorageSlot, + +/* LOCATION */ + AROS_LHA(LONG, id, D0), + struct ExecBase *, SysBase, 186, Exec) + +/* FUNCTION + Get a value for a task storage slot of parent task. + + INPUTS + id - slot ID returned from AllocTaskStorageSlot(). + + RESULT + Value stored by SetTaskStorageSlot() on parent task, or + (IPTR)NULL if the slot was never used. + + NOTES + Since you are accessing value of another task, the value + might be invalid/freed by the time this function returns. + To be sure value is still valid, call this function under + Forbid(). + + EXAMPLE + + BUGS + + SEE ALSO + AllocTaskStorageSlot(), FreeTaskStorageSlot(), SetTaskStorageSlot(), + GetTaskStorageSlot() + + INTERNALS + +******************************************************************************/ +{ + AROS_LIBFUNC_INIT + + struct ETask *et = GetETask(FindTask(NULL)); + IPTR result = (IPTR)NULL; + + if (!et) + return (IPTR)NULL; + + Forbid(); /* Accessing other task's et_TaskStorage */ + + result = TaskGetStorageSlot(et->et_Parent, id); + + Permit(); + + return result; + + AROS_LIBFUNC_EXIT +} diff --git a/rom/exec/gettaskstorageslot.c b/rom/exec/gettaskstorageslot.c index 5aef24dfbc..9795d2c2c1 100644 --- a/rom/exec/gettaskstorageslot.c +++ b/rom/exec/gettaskstorageslot.c @@ -1,5 +1,5 @@ /* - Copyright © 2012, The AROS Development Team. All rights reserved. + Copyright © 2012-2014, The AROS Development Team. All rights reserved. $Id$ */ @@ -48,24 +48,29 @@ { AROS_LIBFUNC_INIT - struct ETask *et = GetETask(FindTask(NULL)); + return TaskGetStorageSlot(FindTask(NULL), id); + + AROS_LIBFUNC_EXIT +} + +IPTR TaskGetStorageSlot(struct Task * t, LONG id) +{ + struct ETask *et = GetETask(t); IPTR *ts; - D(bug("GetTaskStorage: %p: Get TaskStorageSlot %d\n", et, id)); + D(bug("TaskGetStorageSlot: %p: Get TaskGetStorageSlot %d\n", et, id)); if (!et) { /* Only ETasks can do this */ - D(bug("GetTaskStorage: Not an ETask!\n")); + D(bug("TaskGetStorageSlot: Not an ETask!\n")); return (IPTR)NULL; } ts = et->et_TaskStorage; if (ts == NULL || ts[__TS_FIRSTSLOT] <= id) { - D(bug("GetTaskStorage: ID %d was not set!\n", id)); + D(bug("TaskGetStorageSlot: ID %d was not set!\n", id)); return (IPTR)NULL; } return ts[id]; - - AROS_LIBFUNC_EXIT } diff --git a/rom/exec/mmakefile.src b/rom/exec/mmakefile.src index 1f50e1793e..ebb337fbd7 100644 --- a/rom/exec/mmakefile.src +++ b/rom/exec/mmakefile.src @@ -35,7 +35,8 @@ ALL_FUNCTIONS := \ newaddtask newminlist avl vnewrawdofmt shutdowna useralert \ addresetcallback remresetcallback doresetcallbacks newcreatetaska \ alloctaskstorageslot freetaskstorageslot savetaskstorage \ - restoretaskstorage settaskstorageslot gettaskstorageslot + restoretaskstorage settaskstorageslot gettaskstorageslot \ + getparenttaskstorageslot INIT_FILES := exec_init prepareexecbase FILES := alertextra alert_cpu systemalert initkicktags intservers \ diff --git a/rom/exec/settaskstorageslot.c b/rom/exec/settaskstorageslot.c index da31409f94..f95747865a 100644 --- a/rom/exec/settaskstorageslot.c +++ b/rom/exec/settaskstorageslot.c @@ -78,6 +78,7 @@ ts[__TS_FIRSTSLOT] = slots; + /* Replacing of the pointer needs to be atomic due to GetParentTaskStorageSlot() */ et->et_TaskStorage = ts; } else if (ts[__TS_FIRSTSLOT] <= id) { IPTR *newts; @@ -96,6 +97,7 @@ (oldslots-1) * sizeof(ts[0])); memset(&newts[oldslots], 0, (newslots - oldslots) * sizeof(ts[0])); + /* Replacing of the pointer needs to be atomic due to GetParentTaskStorageSlot() */ et->et_TaskStorage = newts; FreeMem(ts, oldslots * sizeof(ts[0])); } diff --git a/rom/exec/taskstorage.h b/rom/exec/taskstorage.h index 4c21ca699a..8cd86d1701 100644 --- a/rom/exec/taskstorage.h +++ b/rom/exec/taskstorage.h @@ -1,5 +1,5 @@ /* - Copyright © 2011-2012, The AROS Development Team. All rights reserved. + Copyright © 2011-2014, The AROS Development Team. All rights reserved. $Id$ */ #ifndef TASKSTORAGE_H @@ -16,4 +16,6 @@ struct TaskStorageFreeSlot #define __TS_FIRSTSLOT 0 +IPTR TaskGetStorageSlot(struct Task * t, LONG id); + #endif /* TASKSTORAGE_H */ -- 2.11.4.GIT