exec.library: Move task storage slot functions to the end, bump the ABI version
[AROS.git] / rom / exec / alloctaskstorageslot.c
blob898b0159ce34b74be1d8cf84e48b02c7a4d30f16
1 /*
2 Copyright © 2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
8 #include "exec_intern.h"
9 #include "exec_util.h"
10 #include "taskstorage.h"
12 /*****************************************************************************
14 NAME */
15 #include <proto/exec.h>
17 AROS_LH0(int, AllocTaskStorageSlot,
19 /* LOCATION */
20 struct ExecBase *, SysBase, 180, Exec)
22 /* FUNCTION
23 This function will allocate a slot in the taskstorage
25 INPUTS
26 None.
28 RESULT
29 The allocated slot, 0 if no slot could be allocated.
31 NOTES
32 After this function FindTask(NULL)->tc_UnionETask.tc_TaskStorage[slot]
33 may be used to store values with each slot. Data stored in a slot
34 will be duplicated when a Task creates another Task. It is left up to the
35 to implement a mechanism to check if this copied value is invalid.
37 EXAMPLE
39 BUGS
41 SEE ALSO
42 FreeTaskStorageSlot()
44 INTERNALS
46 ******************************************************************************/
48 AROS_LIBFUNC_INIT
50 struct TaskStorageFreeSlot *tsfs = (struct TaskStorageFreeSlot *)GetHead(&PrivExecBase(SysBase)->TaskStorageSlots);
51 int slot;
52 struct Task *t;
54 if (!tsfs)
55 Alert(AT_DeadEnd|AN_MemoryInsane);
57 slot = tsfs->FreeSlot;
59 D(bug("[TSS] Task 0x%p (%s): Allocated slot %d\n", FindTask(NULL), FindTask(NULL)->tc_Node.ln_Name, slot));
61 if ((slot + 1)*sizeof(IPTR) > PrivExecBase(SysBase)->TaskStorageSize)
63 t = FindTask(NULL);
65 if (!Exec_ExpandTS(t, SysBase))
66 return 0;
69 if (GetSucc(tsfs) == NULL)
71 /* Last element always points to highest element and is a new slot */
72 tsfs->FreeSlot++;
74 else
76 Remove((struct Node *)tsfs);
77 FreeMem(tsfs, sizeof(struct TaskStorageFreeSlot));
79 /* Clean previous values in slot on all tasks */
80 Forbid();
81 ForeachNode(&SysBase->TaskReady, t)
83 if (t->tc_Flags & TF_ETASK)
84 t->tc_UnionETask.tc_TaskStorage[slot] = (IPTR)0;
86 ForeachNode(&SysBase->TaskWait, t)
88 if (t->tc_Flags & TF_ETASK)
89 t->tc_UnionETask.tc_TaskStorage[slot] = (IPTR)0;
91 Permit();
94 return slot;
96 AROS_LIBFUNC_EXIT