2 Copyright © 2011, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
8 #include "exec_intern.h"
10 #include "taskstorage.h"
12 /*****************************************************************************
15 #include <proto/exec.h>
17 AROS_LH0(int, AllocTaskStorageSlot
,
20 struct ExecBase
*, SysBase
, 139, Exec
)
23 This function will allocate a slot in the taskstorage
29 The allocated slot, 0 if no slot could be allocated.
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.
46 ******************************************************************************/
50 struct TaskStorageFreeSlot
*tsfs
= (struct TaskStorageFreeSlot
*)GetHead(&PrivExecBase(SysBase
)->TaskStorageSlots
);
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
)
65 if (!Exec_ExpandTS(t
, SysBase
))
69 if (GetSucc(tsfs
) == NULL
)
71 /* Last element always points to highest element and is a new slot */
76 Remove((struct Node
*)tsfs
);
77 FreeMem(tsfs
, sizeof(struct TaskStorageFreeSlot
));
79 /* Clean previous values in slot on all tasks */
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;