graphics.library: MakeVPort() RastInfo based double-buffering fixes
[AROS.git] / rom / exec / alloctaskstorageslot.c
blob04c2ac530796c57ba933d02a840040ad9bbf9192
1 /*
2 Copyright © 2011-2012, 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. Data stored in a slot will be duplicated when
34 a Task creates another Task. It is left up to the caller to implement
35 a mechanism to check if this copied value is invalid.
37 EXAMPLE
39 BUGS
41 SEE ALSO
42 FreeTaskStorageSlot(), GetTaskStorageSlot(), SetTaskStorageSlot()
44 INTERNALS
46 ******************************************************************************/
48 AROS_LIBFUNC_INIT
50 struct TaskStorageFreeSlot *tsfs;
51 LONG slot;
52 struct IntETask *iet = GetIntETask(FindTask(NULL));
54 if (!iet)
55 return 0;
57 Forbid();
58 tsfs = (struct TaskStorageFreeSlot *)
59 GetHead(&PrivExecBase(SysBase)->TaskStorageSlots);
60 if (!tsfs)
61 Alert(AT_DeadEnd|AN_MemoryInsane);
63 slot = tsfs->FreeSlot;
65 D(bug("[TSS] Task 0x%p (%s): Allocated slot %d\n", FindTask(NULL), FindTask(NULL)->tc_Node.ln_Name, slot));
67 if (GetSucc(tsfs) == NULL)
69 /* Last element always points to highest element and is a new slot */
70 tsfs->FreeSlot++;
72 else
74 Remove((struct Node *) tsfs);
75 FreeMem(tsfs, sizeof(struct TaskStorageFreeSlot));
77 Permit();
79 return slot;
81 AROS_LIBFUNC_EXIT