revert between 56095 -> 55830 in arch
[AROS.git] / rom / exec / alloctaskstorageslot.c
blob092aaa9af143af49f11774e5fdd91b655c22b090
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 = ThisTask ? GetIntETask(ThisTask) : NULL;
53 if (!iet)
54 return 0;
56 Forbid();
57 tsfs = (struct TaskStorageFreeSlot *)
58 GetHead(&PrivExecBase(SysBase)->TaskStorageSlots);
59 if (!tsfs)
61 Alert(AT_DeadEnd|AN_MemoryInsane);
62 __builtin_unreachable();
65 slot = tsfs->FreeSlot;
67 D(bug("[TSS] Task 0x%p (%s): Allocated slot %d\n", ThisTask, ThisTask->tc_Node.ln_Name, slot);)
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 Permit();
81 return slot;
83 AROS_LIBFUNC_EXIT