refactored some code. compiles now without suppresing any warning with gcc-6.3.0.
[AROS.git] / rom / task / QueryTaskTagList.c
blobfec5e98c215d5488de21671a01f032d25620a7e0
1 /*
2 Copyright © 2015-2017, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
8 #include <aros/debug.h>
9 #include <exec/types.h>
10 #include <aros/libcall.h>
11 #include <proto/utility.h>
12 #include <resources/task.h>
14 #include "etask.h"
16 #include "task_intern.h"
18 /*****************************************************************************
20 NAME */
21 #include <proto/task.h>
23 AROS_LH2(void, QueryTaskTagList,
25 /* SYNOPSIS */
26 AROS_LHA(struct Task *, task, A0),
27 AROS_LHA(struct TagItem *, tagList, A1),
29 /* LOCATION */
30 struct TaskResBase *, TaskResBase, 6, Task)
32 /* FUNCTION
34 Provides information about selected system Task
36 INPUTS
38 Function takes an array of tags. Data is returned for each tag. See
39 specific tag description.
41 TAGS
43 TaskTag_CPUNumber - (IPTR *) Returns the CPU Number the task is currently running on
44 TaskTag_CPUAffinity - (IPTR *) Returns the CPU Affinity mask
45 TaskTag_CPUTime - (struct timeval *) Returns the amount of cpu time a task has used .
46 TaskTag_StartTime - (struct timeval *) Returns the time the task was launched .
48 RESULT
50 None
52 NOTES
54 EXAMPLE
56 BUGS
58 SEE ALSO
60 INTERNALS
62 ******************************************************************************/
64 AROS_LIBFUNC_INIT
66 struct TagItem * Tag = NULL;
67 struct Library *UtilityBase = TaskResBase->trb_UtilityBase;
68 struct IntETask *task_et = GetIntETask(task);
71 bug("[TaskRes] %s: task @ 0x%p\n", __func__, task);
72 bug("[TaskRes] %s: taglist @ 0x%p\n", __func__, tagList);
75 /* This is the default implementation */
77 while ((Tag = NextTagItem(&tagList)) != NULL)
79 switch(Tag->ti_Tag)
81 case(TaskTag_CPUNumber):
82 #if defined(__AROSEXEC_SMP__)
83 *((IPTR *)Tag->ti_Data) = task_et->iet_CpuNumber;
84 #else
85 *((IPTR *)Tag->ti_Data) = 0;
86 #endif
87 break;
88 case(TaskTag_CPUAffinity):
89 #if defined(__AROSEXEC_SMP__)
91 int i, count = KrnGetCPUCount();
92 for (i = 0; i < count; i ++)
94 if (KrnCPUInMask(i, task_et->iet_CpuAffinity))
95 KrnGetCPUMask(i, (void *)Tag->ti_Data);
98 #endif
99 break;
100 case(TaskTag_CPUTime):
102 struct timeval *storeval = (struct timeval *)Tag->ti_Data;
103 if (task_et)
105 storeval->tv_micro = (task_et->iet_CpuTime.tv_nsec + 500) / 1000;
106 storeval->tv_secs = task_et->iet_CpuTime.tv_sec;
109 break;
110 case(TaskTag_CPUUsage):
112 if (task_et)
113 *(ULONG *)(Tag->ti_Data) = task_et->iet_CpuUsage;
114 else
115 *(ULONG *)(Tag->ti_Data) = 0;
117 break;
118 case(TaskTag_StartTime):
120 struct timeval *storeval = (struct timeval *)Tag->ti_Data;
121 if (task_et)
123 storeval->tv_micro = (task_et->iet_StartTime.tv_nsec + 500) / 1000;
124 storeval->tv_secs = task_et->iet_StartTime.tv_sec;
127 break;
131 AROS_LIBFUNC_EXIT
132 } /* QueryTaskTagList() */