Changeset 538 for Whitix/branches/hybrid/kernel/sched.c
- Timestamp:
- 05/24/08 09:54:46 (6 months ago)
- Files:
-
- 1 modified
-
Whitix/branches/hybrid/kernel/sched.c (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Whitix/branches/hybrid/kernel/sched.c
r491 r538 17 17 */ 18 18 19 /* TODO: Clean up these includes. */ 19 20 #include <sched.h> 20 21 #include <error.h> … … 25 26 #include <malloc.h> 26 27 #include <fs/vfs.h> 28 #include <init.h> 27 29 #include <task.h> 28 30 #include <panic.h> … … 31 33 #include <net/socket.h> 32 34 #include <module.h> 35 #include <imports.h> 36 #include <sys.h> 33 37 34 38 /* List heads */ … … 55 59 56 60 /* Used when a thread is exiting */ 57 DWORD exitStack[PAGE_SIZE];61 BYTE exitStack[PAGE_SIZE/4]; 58 62 59 63 /*********************************************************************** … … 141 145 SpinLockIrq(&procListLock); 142 146 143 process=(struct Process*) MemCacheAlloc(processCache);147 process=(struct Process*)memCacheAlloc(processCache); 144 148 if (!process) 145 149 return NULL; … … 147 151 if (VirtMemManagerSetup(process)) 148 152 { 149 MemCacheFree(processCache,process);153 memCacheFree(processCache,process); 150 154 SpinUnlockIrq(&procListLock); 151 155 return NULL; … … 153 157 154 158 /* Allocate the process's name - used when listing processes or when faulting. */ 155 process->name=(char*) malloc(strlen(name)+1);156 strcpy(process->name, name);159 process->name=(char*)MemAlloc(strlen(name)+1); 160 strcpy(process->name, name); 157 161 158 162 /* Add to parent's children list */ … … 168 172 process->state=THR_RUNNING; 169 173 170 process->files=NULL; 174 process->files=NULL; /* FIXME */ 171 175 172 176 ListAddTail(&process->next,&processList); … … 176 180 return process; 177 181 } 182 183 SYMBOL_EXPORT(ThrCreateProcess); 178 184 179 185 /*********************************************************************** … … 200 206 ListRemove(&process->next); 201 207 202 free(process->name);203 MemCacheFree(processCache,process);208 MemFree(process->name); 209 memCacheFree(processCache,process); 204 210 205 211 IrqRestoreFlags(flags); 206 212 } 213 214 SYMBOL_EXPORT(ThrFreeProcess); 207 215 208 216 /*********************************************************************** … … 251 259 SpinLockIrq(&thrListLock); 252 260 253 ret=(struct Thread*) MemCacheAlloc(threadCache);261 ret=(struct Thread*)memCacheAlloc(threadCache); 254 262 if (!ret) 255 263 return NULL; … … 272 280 } 273 281 282 SYMBOL_EXPORT(ThrCreateThread); 283 274 284 /*********************************************************************** 275 285 * … … 295 305 } 296 306 307 SYMBOL_EXPORT(ThrSetPriority); 308 297 309 /*********************************************************************** 298 310 * … … 310 322 void _ThrFreeThread(struct Thread* thread) 311 323 { 312 free((void*)thread->currStack);324 MemFree((void*)thread->currStack); 313 325 currThread=NULL; 314 MemCacheFree(threadCache, thread);326 memCacheFree(threadCache, thread); 315 327 ThrSchedule(); 316 328 } … … 350 362 351 363 if (thread == currThread) 352 ArchSwitchStackCall(exitStack+PAGE_SIZE ,_ThrFreeThread,thread);364 ArchSwitchStackCall(exitStack+PAGE_SIZE/4,_ThrFreeThread,thread); 353 365 else{ 354 free((void*)(thread->currStack));355 MemCacheFree(threadCache,thread);366 MemFree((void*)(thread->currStack)); 367 memCacheFree(threadCache,thread); 356 368 } 357 369 … … 401 413 } 402 414 } 415 416 SYMBOL_EXPORT(ThrStartThread); 403 417 404 418 /*********************************************************************** … … 467 481 ***********************************************************************/ 468 482 483 /* TODO: Move to filesystem code. */ 484 469 485 static void ThrReleaseFsContext() 470 486 { … … 473 489 /* Now release the filesystem context */ 474 490 475 if (current->files)491 // if (current->files) 476 492 /* Close all files associated with the process */ 477 for (i=0; i<current->numFds; i++)478 DoCloseFile(¤t->files[i]);493 // for (i=0; i<current->numFds; i++) 494 // DoCloseFile(¤t->files[i]); 479 495 480 496 /* Does not apply to the KernelLoading process */ 481 if (current->exec)482 VNodeRelease(current->exec);483 484 VNodeRelease(current->cwd);485 VNodeRelease(current->root);486 487 free(current->files);488 free(current->sCwd);497 // if (current->exec) 498 // VNodeRelease(current->exec); 499 500 // VNodeRelease(current->cwd); 501 // VNodeRelease(current->root); 502 503 // free(current->files); 504 // free(current->sCwd); 489 505 } 490 506 … … 511 527 512 528 /* Release all vmm areas */ 513 MmapProcessRemove(current);529 // MmapProcessRemove(current); 514 530 ThrReleaseFsContext(); 515 531 … … 548 564 } 549 565 566 SYMBOL_EXPORT(ThrProcessExit); 567 550 568 /*********************************************************************** 551 569 * … … 599 617 } 600 618 } 619 620 SYMBOL_EXPORT(ThrResumeThread); 601 621 602 622 /*********************************************************************** … … 751 771 int SysExitThread(int threadId) 752 772 { 753 // printf("SysExitThread(%d)\n", threadId);754 773 if (threadId == -1) /* Exit current thread. */ 755 774 ThrDoExitThread(); … … 803 822 waitEntry.thread=currThread; 804 823 805 if (finishStatus)806 if (VirtCheckArea(finishStatus,sizeof(int),VER_WRITE))807 return -EFAULT;824 // if (finishStatus) 825 // if (VirtCheckArea(finishStatus,sizeof(int),VER_WRITE)) 826 // return -EFAULT; 808 827 809 828 if (pid >= 0) … … 903 922 ***********************************************************************/ 904 923 905 int Thr Init()924 int ThrEarlyInit() 906 925 { 907 926 ThrArchInit(); /* Set up arch-specific data structures for multitasking here */ 908 909 /* Allocate the general scheduling caches */910 processCache=MemCacheCreate("Process Cache", sizeof(struct Process), ThrProcessConstructor, NULL, 0);911 threadCache=MemCacheCreate("Thread Cache", sizeof(struct Thread), NULL, NULL, 0);912 927 913 928 currThread=idleTask; … … 919 934 return 0; 920 935 } 936 937 #define SYS_SCHED_BASE 34 938 939 struct SysCall schedSysCallTable[]= 940 { 941 { SysCreateThread, 12 }, 942 { SysGetCurrentThreadId, 0 }, 943 { SysGetCurrentProcessId, 0 }, 944 { SysExitThread, 4 }, 945 { SysExit, 4 }, 946 { SysWaitForProcessFinish, 8 }, 947 { SysYield, 0 }, 948 { 0, 0 }, 949 }; 950 951 int ThrInit() 952 { 953 /* Allocate the general scheduling caches */ 954 processCache=memCacheCreate("Process Cache", sizeof(struct Process), ThrProcessConstructor, NULL, 0); 955 threadCache=memCacheCreate("Thread Cache", sizeof(struct Thread), NULL, NULL, 0); 956 957 /* Register the threading system calls. */ 958 SysRegisterRange(SYS_SCHED_BASE, schedSysCallTable); 959 960 return 0; 961 } 962 963 CoreInit(ThrInit);