arosc.library: Centralized exit handling code in __arosc_startup.c
[AROS.git] / workbench / system / SysMon / tasks.c
blob4eeee62b745bf671bd8fdc6b194c9ca447b01ba7
1 #include "sysmon_intern.h"
3 #include <exec/execbase.h>
4 #include <clib/alib_protos.h>
6 #include "locale.h"
8 /* Task information handling*/
9 struct TaskInfo
11 STRPTR Name;
12 WORD Type;
13 WORD Priority;
14 struct TaskInfo * Next;
15 UBYTE Private; /* MUST ALWAYS BE LAST. HERE NAME WILL BE COPIED */
18 UBYTE taskinfobuffer[16 * 1024]; /* 16 kB buffer */
20 static LONG AddTaskInfo(struct Task * task, struct TaskInfo * ti)
22 ti->Type = task->tc_Node.ln_Type;
23 ti->Priority = (WORD)task->tc_Node.ln_Pri;
24 ti->Name = (STRPTR)&ti->Private;
25 ULONG namesize = 0;
26 STRPTR src = task->tc_Node.ln_Name;
28 if (src)
30 while(*src != 0)
32 ti->Name[namesize++] = *src;
33 src++;
37 *(ti->Name + namesize) = 0; /* Terminate */
39 /* Calculate next item */
40 ti->Next = (struct TaskInfo *)(((UBYTE *)ti) + sizeof(struct TaskInfo) + namesize);
42 return 1;
45 static BOOL FillTaskInfoBuffer(UBYTE * buffer)
47 struct TaskInfo * current = (struct TaskInfo *)buffer;
48 struct Task * task;
50 Disable();
51 if(!AddTaskInfo(SysBase->ThisTask, current))
53 Enable();
54 return FALSE;
57 for(task=(struct Task *)SysBase->TaskReady.lh_Head;
58 task->tc_Node.ln_Succ!=NULL;
59 task=(struct Task *)task->tc_Node.ln_Succ)
61 current = current->Next;
63 if(!AddTaskInfo(task, current))
65 Enable();
66 return FALSE;
70 for(task=(struct Task *)SysBase->TaskWait.lh_Head;
71 task->tc_Node.ln_Succ!=NULL;
72 task=(struct Task *)task->tc_Node.ln_Succ)
74 current = current->Next;
76 if(!AddTaskInfo(task, current))
78 Enable();
79 return FALSE;
83 current->Next = NULL; /* "stop" list */
85 Enable();
86 return TRUE;
89 VOID UpdateTasksInformation(struct SysMonData * smdata)
91 set(smdata->tasklist, MUIA_List_Quiet, TRUE);
93 /* Clear prior to reading information, because list contains items
94 from the taskinfobuffer. Once FillTaskInfoBuffer is executed old items
95 are invalid and could crash list */
96 DoMethod(smdata->tasklist, MUIM_List_Clear);
98 if (FillTaskInfoBuffer(taskinfobuffer))
100 struct TaskInfo * ti = (struct TaskInfo *)taskinfobuffer;
102 for (; ti->Next != NULL; ti = ti->Next)
104 DoMethod(smdata->tasklist, MUIM_List_InsertSingle, ti, MUIV_List_Insert_Bottom);
108 set(smdata->tasklist, MUIA_List_Quiet, FALSE);
111 AROS_UFH3(VOID, TasksListDisplayFunction,
112 AROS_UFHA(struct Hook *, h, A0),
113 AROS_UFHA(STRPTR *, strings, A2),
114 AROS_UFHA(struct TaskInfo *, obj, A1))
116 AROS_USERFUNC_INIT
118 static TEXT bufprio[8];
120 if (obj)
122 __sprintf(bufprio, "%ld", (LONG)obj->Priority);
123 strings[0] = obj->Name;
124 strings[1] = bufprio;
125 strings[2] = obj->Type == NT_TASK ? (STRPTR)_(MSG_TASK) : (STRPTR)_(MSG_PROCESS);
127 else
129 strings[0] = (STRPTR)_(MSG_TASK_NAME);
130 strings[1] = (STRPTR)_(MSG_TASK_PRIORITY);
131 strings[2] = (STRPTR)_(MSG_TASK_TYPE);
134 AROS_USERFUNC_EXIT
137 static BOOL InitTasks()
139 return TRUE;
142 static VOID DeInitTasks()
146 struct SysMonModule tasksmodule =
148 .Init = InitTasks,
149 .DeInit = DeInitTasks,