Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / system / SysMon / tasks.c
bloba61031ea8bccc31edede79d1c55632e2aa086978
1 /*
2 Copyright 2010-2016, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/execbase.h>
7 #include <resources/task.h>
8 #include <clib/alib_protos.h>
10 #include <proto/task.h>
11 #include <proto/dos.h>
13 #include "locale.h"
15 #include "sysmon_intern.h"
17 //#define DEBUG 1
18 #include <aros/debug.h>
21 APTR TaskResBase = NULL;
23 /* Task information handling*/
24 struct TaskInfo
26 struct Node TINode;
27 struct Task *Task;
28 ULONG TimeCurrent;
29 ULONG TimeLast;
32 VOID UpdateTasksInformation(struct SysMonData * smdata)
34 struct Task * task;
35 IPTR firstvis = 0, entryid = 0;
36 struct Task *selected = smdata->sm_TaskSelected;
37 struct TaskList *systasklist;
39 set(smdata->tasklist, MUIA_List_Quiet, TRUE);
41 get(smdata->tasklist, MUIA_List_First, &firstvis);
43 DoMethod(smdata->tasklist, MUIM_List_Clear);
45 smdata->sm_TasksWaiting = 0;
46 smdata->sm_TasksReady = 0;
47 smdata->sm_TaskTotalRuntime = 0;
49 #if 0
50 /* We are unlikely to disappear and this code still run... so don't disable yet */
51 if ((entryid = DoMethod(smdata->tasklist, MUIM_List_InsertSingle, smdata->sm_Task, MUIV_List_Insert_Bottom)) == 0)
53 return;
55 #endif
56 if (smdata->sm_Task == selected)
58 set(smdata->tasklist, MUIA_List_Active, entryid);
61 systasklist = LockTaskList(0);
62 while ((task = NextTaskEntry(systasklist, 0)) != NULL)
64 D(bug("[SysMon] task %s state %d\n", task->tc_Node.ln_Name, task->tc_State));
66 if (task->tc_State == TS_READY)
68 smdata->sm_TasksReady++;
70 if (task->tc_State == TS_WAIT)
72 smdata->sm_TasksWaiting++;
75 entryid = DoMethod(smdata->tasklist, MUIM_List_InsertSingle, task, MUIV_List_Insert_Bottom);
76 if (task == selected)
78 set(smdata->tasklist, MUIA_List_Active, entryid);
81 UnLockTaskList(0);
83 if (XGET(smdata->tasklist, MUIA_List_Active) == 0)
84 smdata->sm_TaskSelected = NULL;
86 /* Keep the "pre-refresh" view on List as much as possible */
87 LONG v = (LONG)firstvis;
88 if (firstvis + XGET(smdata->tasklist, MUIA_List_Visible) >= XGET(smdata->tasklist, MUIA_List_Entries))
90 v = XGET(smdata->tasklist, MUIA_List_Entries) - XGET(smdata->tasklist, MUIA_List_Visible);
91 if (v < 0) v = 0;
94 set(smdata->tasklist, MUIA_List_First, v);
96 __sprintf(smdata->tasklistinfobuf, "%ld ready, %ld waiting", smdata->sm_TasksReady, smdata->sm_TasksWaiting);
97 set(smdata->tasklistinfo, MUIA_Text_Contents, smdata->tasklistinfobuf);
98 set(smdata->tasklist, MUIA_List_Quiet, FALSE);
101 AROS_UFH3(struct TaskInfo *, TasksListConstructFunction,
102 AROS_UFHA(struct Hook *, h, A0),
103 AROS_UFHA(APTR, pool, A2),
104 AROS_UFHA(struct Task *, curTask, A1))
106 AROS_USERFUNC_INIT
108 struct TaskInfo *ti = NULL;
110 if ((ti = AllocVecPooled(pool, sizeof(struct TaskInfo))) != NULL)
112 ti->Task = curTask;
114 /* Cache values we need incase something happens to the task .. */
115 ti->TINode.ln_Type = curTask->tc_Node.ln_Type;
116 ti->TINode.ln_Pri = (WORD)curTask->tc_Node.ln_Pri;
117 ti->TINode.ln_Name = StrDup(curTask->tc_Node.ln_Name);
119 AddTail(&((struct SysMonData *)h->h_Data)->sm_TaskList, &ti->TINode);
121 return ti;
123 AROS_USERFUNC_EXIT
126 AROS_UFH3(VOID, TasksListDestructFunction,
127 AROS_UFHA(struct Hook *, h, A0),
128 AROS_UFHA(APTR, pool, A2),
129 AROS_UFHA(struct TaskInfo *, ti, A1))
131 AROS_USERFUNC_INIT
133 Remove(&ti->TINode);
134 FreeVec(ti->TINode.ln_Name);
135 FreeVecPooled(pool, ti);
137 AROS_USERFUNC_EXIT
140 AROS_UFH3(VOID, TaskSelectedFunction,
141 AROS_UFHA(struct Hook *, h, A0),
142 AROS_UFHA(Object *, obj, A2),
143 AROS_UFHA(APTR, msg, A1))
145 AROS_USERFUNC_INIT
147 struct SysMonData *smdata = h->h_Data;
148 struct TaskInfo *ti = NULL;
150 DoMethod(smdata->tasklist, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &ti);
152 if (ti != NULL)
154 smdata->sm_TaskSelected = ti->Task;
156 else
157 smdata->sm_TaskSelected = NULL;
159 AROS_USERFUNC_EXIT
163 AROS_UFH3(VOID, TasksListDisplayFunction,
164 AROS_UFHA(struct Hook *, h, A0),
165 AROS_UFHA(STRPTR *, strings, A2),
166 AROS_UFHA(struct TaskInfo *, ti, A1))
168 AROS_USERFUNC_INIT
170 static TEXT bufprio[8];
172 if (ti)
174 __sprintf(bufprio, "%d", (LONG)ti->TINode.ln_Pri);
176 strings[0] = ti->TINode.ln_Name;
177 strings[1] = bufprio;
178 strings[2] = ti->TINode.ln_Type == NT_TASK ? (STRPTR)_(MSG_TASK) : (STRPTR)_(MSG_PROCESS);
180 else
182 strings[0] = (STRPTR)_(MSG_TASK_NAME);
183 strings[1] = (STRPTR)_(MSG_TASK_PRIORITY);
184 strings[2] = (STRPTR)_(MSG_TASK_TYPE);
187 AROS_USERFUNC_EXIT
190 static BOOL InitTasks(struct SysMonData *smdata)
192 TaskResBase = OpenResource("task.resource");
193 if (TaskResBase == NULL)
195 FPuts(Output(), "Can't open task.resource\n");
196 return FALSE;
199 smdata->sm_Task = FindTask(NULL);
200 NewList(&smdata->sm_TaskList);
202 smdata->tasklistinfobuf = AllocVec(30, MEMF_PUBLIC);
204 smdata->sm_TaskSelected = NULL;
205 smdata->sm_TaskTotalRuntime = 0;
207 return TRUE;
210 static VOID DeInitTasks(struct SysMonData *smdata)
214 struct SysMonModule tasksmodule =
216 .Init = InitTasks,
217 .DeInit = DeInitTasks,