Test current SDI headers.
[AROS.git] / rom / exec / alloctaskstorageslot.c
blob1b02a2f6fd9dfbbbae7a06d1e26f43285206d228
1 /*
2 Copyright © 2011-2015, 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(LONG, 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 slot - The allocated slot, or 0 if no slot could be allocated.
31 NOTES
32 After this function SetTaskStorageSlot(slot) may be used to store
33 values with each slot.
35 EXAMPLE
37 BUGS
39 SEE ALSO
40 FreeTaskStorageSlot(), GetTaskStorageSlot(), SetTaskStorageSlot()
42 INTERNALS
44 ******************************************************************************/
46 AROS_LIBFUNC_INIT
48 struct Task *ThisTask = GET_THIS_TASK;
49 struct TaskStorageFreeSlot *tsfs;
50 LONG slot;
51 struct IntETask *iet = GetIntETask(ThisTask);
53 if (!iet)
54 return 0;
56 Forbid();
57 tsfs = (struct TaskStorageFreeSlot *)
58 GetHead(&PrivExecBase(SysBase)->TaskStorageSlots);
59 if (!tsfs)
60 Alert(AT_DeadEnd|AN_MemoryInsane);
62 slot = tsfs->FreeSlot;
64 D(bug("[TSS] Task 0x%p (%s): Allocated slot %d\n", ThisTask, ThisTask->tc_Node.ln_Name, slot);)
66 if (GetSucc(tsfs) == NULL)
68 /* Last element always points to highest element and is a new slot */
69 tsfs->FreeSlot++;
71 else
73 Remove((struct Node *) tsfs);
74 FreeMem(tsfs, sizeof(struct TaskStorageFreeSlot));
76 Permit();
78 return slot;
80 AROS_LIBFUNC_EXIT