void fun2() { Console::puts("THREAD: "); Console::puti(Thread::CurrentThread()->ThreadId()); Console::puts("\n"); Console::puts("FUN 2 INVOKED!\n"); #ifdef _USES_DISK_ unsigned char buf[512]; int read_block = 1; int write_block = 0; #endif for(int j = 0;; j++) { Console::puts("FUN 2 IN ITERATION["); Console::puti(j); Console::puts("]\n"); #ifdef _USES_DISK_ /* -- Read */ Console::puts("Reading a block from disk...\n"); /* UNCOMMENT THE FOLLOWING LINE IN FINAL VERSION. */ SYSTEM_DISK->read(read_block, buf); /* -- Display */ int i; for (i = 0; i < 512; i++) { Console::putch(buf[i]); } #ifndef _USES_FILESYSTEM_ /* -- Write -- ONLY IF THERE IS NO FILE SYSTEM BEING EXERCISED! */ /* Running this piece of code on a disk with a */ /* file system would corrupt the file system. */ Console::puts("Writing a block to disk...\n"); /* UNCOMMENT THE FOLLOWING LINE IN FINAL VERSION. */ SYSTEM_DISK->write(write_block, buf); #endif /* -- Move to next block */ write_block = read_block; read_block = (read_block + 1) % 10; #else for (int i = 0; i < 10; i++) { //for (int i = 0; i < 0; i++) { Console::puts("FUN 2: TICK ["); Console::puti(i); Console::puts("]\n"); } #endif /* -- Give up the CPU */ pass_on_CPU(thread3); } }
void fun3() { Console::puts("THREAD: "); Console::puti(Thread::CurrentThread()->ThreadId()); Console::puts("\n"); Console::puts("FUN 3 INVOKED!\n"); #ifdef _USES_FILESYSTEM_ exercise_file_system(FILE_SYSTEM); #else for(int j = 0;; j++) { Console::puts("FUN 3 IN BURST["); Console::puti(j); Console::puts("]\n"); for (int i = 0; i < 10; i++) { Console::puts("FUN 3: TICK ["); Console::puti(i); Console::puts("]\n"); } #endif pass_on_CPU(thread4); } void fun4() { Console::puts("THREAD: "); Console::puti(Thread::CurrentThread()->ThreadId()); Console::puts("\n"); for(int j = 0;; j++) { Console::puts("FUN 4 IN BURST["); Console::puti(j); Console::puts("]\n"); for (int i = 0; i < 10; i++) { Console::puts("FUN 4: TICK ["); Console::puti(i); Console::puts("]\n"); } pass_on_CPU(thread1); } }
void fun4() { Console::puts("THREAD: "); Console::puti(Thread::CurrentThread()->ThreadId()); Console::puts("\n"); for(int j = 0;; j++) { Console::puts("FUN 4 IN BURST["); Console::puti(j); Console::puts("]\n"); for (int i = 0; i < 10; i++) { Console::puts("FUN 4: TICK ["); Console::puti(i); Console::puts("]\n"); } pass_on_CPU(thread1); } }
void fun1() { Console::puts("THREAD: "); Console::puti(Thread::CurrentThread()->ThreadId()+1); Console::puts("\n"); Console::puts("FUN 1 INVOKED!\n"); for(int j = 0;; j++) { Console::puts("FUN 1 IN ITERATION["); Console::puti(j); Console::puts("]\n"); for (int i = 0; i < 10; i++) { Console::puts("FUN 1: TICK ["); Console::puti(i); Console::puts("]\n"); } pass_on_CPU(thread2); } }
void fun3() { Console::puts("THREAD: "); Console::puti(Thread::CurrentThread()->ThreadId()+1); Console::puts("\n"); Console::puts("FUN 3 INVOKED!\n"); #ifdef _USES_FILESYSTEM_ for(int j = 0;; j++) { //exercise_file_system(FILE_SYSTEM, SYSTEM_DISK); FileSystem* _file_system=FILE_SYSTEM; BlockingDisk* _blocking_disk=SYSTEM_DISK; _file_system->Format(_blocking_disk,512); _file_system->Mount(_blocking_disk); File* file; _file_system->CreateFile(j); _file_system->DeleteFile(j); if (_file_system->LookupFile(j, file)==TRUE)//test delete assert(FALSE); _file_system->CreateFile(j); if (_file_system->LookupFile(j, file)==FALSE)//test lookup assert(FALSE); char buffer[BUFFER_SIZE*2]; char buffer2[BUFFER_SIZE*2]; char *str1="BUFFER 1 STRING TEST\n"; char *str2="JUNK BUFFER\n"; Console::puts("BUFFER CONTENT:\n"); memcpy(buffer,str1,BUFFER_SIZE*2); memcpy(buffer2,str2,BUFFER_SIZE*2); Console::puts(buffer); Console::puts(buffer2); file->Write(BUFFER_SIZE,buffer); Console::puts("Writing BUFFER 1 to file\n"); file->Reset(); file->Read(BUFFER_SIZE,buffer2); Console::puts("Reading from file into BUFFER 2\n"); Console::puts("BUFFER CONTENT:\n"); Console::puts(buffer); Console::puts(buffer2); if (buffer[0]!=buffer2[0]) assert(FALSE); Console::puts("END OF TEST\n"); for(;;); #else for(int j = 0;; j++) { Console::puts("FUN 3 IN BURST["); Console::puti(j); Console::puts("]\n"); for (int i = 0; i < 10; i++) { Console::puts("FUN 3: TICK ["); Console::puti(i); Console::puts("]\n"); } pass_on_CPU(thread4); #endif } } void fun4() { Console::puts("THREAD: "); Console::puti(Thread::CurrentThread()->ThreadId()+1); Console::puts("\n"); for(int j = 0;; j++) { Console::puts("FUN 4 IN BURST["); Console::puti(j); Console::puts("]\n"); for (int i = 0; i < 10; i++) { Console::puts("FUN 4: TICK ["); Console::puti(i); Console::puts("]\n"); } pass_on_CPU(thread1); } }