Lines Matching refs:thr
85 //PAlloc_Release((void *)thr->kstack);
86 //thr->kstack = 0;
98 Thread *thr = (Thread *)Slab_Alloc(&threadSlab);
100 if (!thr)
103 memset(thr, 0, sizeof(*thr));
107 thr->tid = proc->nextThreadID++;
108 thr->kstack = (uintptr_t)PAlloc_AllocPage();
109 if (thr->kstack == 0) {
110 Slab_Free(&threadSlab, thr);
117 thr->proc = proc;
119 TAILQ_INSERT_TAIL(&proc->threadList, thr, threadList);
120 thr->space = proc->space;
121 thr->ustack = proc->ustackNext;
125 thr->schedState = SCHED_STATE_NULL;
126 thr->timerEvt = NULL;
127 thr->refCount = 1;
129 Thread_InitArch(thr);
132 return thr;
138 Thread *thr = Thread_Create(kernelProcess);
139 if (!thr)
142 Thread_SetupKThread(thr, f, (uintptr_t)arg, 0, 0);
144 return thr;
151 Thread *thr = (Thread *)Slab_Alloc(&threadSlab);
153 if (!thr)
156 memset(thr, 0, sizeof(*thr));
158 thr->tid = proc->nextThreadID++;
159 thr->kstack = (uintptr_t)PAlloc_AllocPage();
160 if (thr->kstack == 0) {
161 Slab_Free(&threadSlab, thr);
165 thr->space = oldThr->space;
166 thr->schedState = SCHED_STATE_NULL;
167 thr->refCount = 1;
170 thr->ustack = proc->ustackNext;
174 PMap_AllocMap(thr->space, thr->ustack, MEM_USERSPACE_STKLEN, PTE_W);
177 Thread_InitArch(thr);
180 Thread_SetupUThread(thr, rip, arg);
185 thr->proc = proc;
188 TAILQ_INSERT_TAIL(&proc->threadList, thr, threadList);
191 return thr;
195 Thread_Destroy(Thread *thr)
197 Process *proc = thr->proc;
206 TAILQ_REMOVE(&proc->threadList, thr, threadList);
210 PAlloc_Release((void *)thr->kstack);
213 Process_Release(thr->proc);
215 Slab_Free(&threadSlab, thr);
232 Thread *thr = NULL;
238 thr = t;
244 return thr;
253 Thread_Retain(Thread *thr)
255 ASSERT(thr->refCount != 0);
256 __sync_fetch_and_add(&thr->refCount, 1);
265 Thread_Release(Thread *thr)
267 ASSERT(thr->refCount != 0);
268 if (__sync_fetch_and_sub(&thr->refCount, 1) == 1) {
269 Thread_Destroy(thr);
279 Thread_Wait(Thread *thr, uint64_t tid)
284 ASSERT(thr->proc != NULL);
287 t = TAILQ_FIRST(&thr->proc->zombieQueue);
292 TAILQ_REMOVE(&thr->proc->zombieQueue, t, schedQueue);
299 TAILQ_FOREACH(t, &thr->proc->zombieQueue, schedQueue) {
301 TAILQ_REMOVE(&thr->proc->zombieQueue, t, schedQueue);
328 Thread_Dump(Thread *thr)
338 // Thread_DumpArch(thr)
339 kprintf("space %016llx\n", thr->space);
340 kprintf("kstack %016llx\n", thr->kstack);
341 kprintf("tid %llu\n", thr->tid);
342 kprintf("refCount %d\n", thr->refCount);
343 kprintf("state %s\n", states[thr->schedState]);
344 kprintf("ctxswtch %llu\n", thr->ctxSwitches);
345 kprintf("utime %llu\n", thr->userTime);
346 kprintf("ktime %llu\n", thr->kernTime);
347 kprintf("wtime %llu\n", thr->waitTime);
348 if (thr->proc) {
349 Process_Dump(thr->proc);
356 Thread *thr;
361 thr = curProc[i];
362 if (thr) {
363 kprintf("Running Thread CPU %d: %d(%016llx) %d\n", i, thr->tid, thr, thr->ctxSwitches);
364 Thread_Dump(thr);
367 TAILQ_FOREACH(thr, &runnableQueue, schedQueue)
369 kprintf("Runnable Thread: %d(%016llx) %d\n", thr->tid, thr, thr->ctxSwitches);
370 Thread_Dump(thr);
372 TAILQ_FOREACH(thr, &waitQueue, schedQueue)
374 kprintf("Waiting Thread: %d(%016llx) %d\n", thr->tid, thr, thr->ctxSwitches);
375 Thread_Dump(thr);
386 Thread *thr = curProc[CPU()];
389 Thread_Dump(thr);