diff options
-rw-r--r-- | AK/Lock.h | 6 | ||||
-rw-r--r-- | Kernel/Disk.cpp | 3 | ||||
-rw-r--r-- | Kernel/Process.cpp | 17 | ||||
-rw-r--r-- | Kernel/Process.h | 2 | ||||
-rw-r--r-- | Kernel/Syscall.cpp | 2 | ||||
-rw-r--r-- | VirtualFileSystem/FileDescriptor.cpp | 11 | ||||
-rw-r--r-- | VirtualFileSystem/FileDescriptor.h | 4 | ||||
-rw-r--r-- | VirtualFileSystem/Makefile | 2 | ||||
-rw-r--r-- | VirtualFileSystem/SyntheticFileSystem.cpp | 4 | ||||
-rw-r--r-- | VirtualFileSystem/VirtualFileSystem.cpp | 13 | ||||
-rw-r--r-- | VirtualFileSystem/VirtualFileSystem.h | 2 | ||||
-rw-r--r-- | VirtualFileSystem/test.cpp | 8 |
12 files changed, 40 insertions, 34 deletions
@@ -4,7 +4,9 @@ #ifdef SERENITY #include "i386.h" +int sched_yield(); #else +#include <sched.h> typedef int InterruptDisabler; #endif @@ -14,8 +16,6 @@ void log_try_lock(const char*); void log_locked(const char*); void log_unlocked(const char*); -void yield(); - namespace AK { static inline dword CAS(volatile dword* mem, dword newval, dword oldval) @@ -51,7 +51,7 @@ public: #endif return; } - yield(); + sched_yield(); } } diff --git a/Kernel/Disk.cpp b/Kernel/Disk.cpp index 815f31b4eb..9bd00f1a2c 100644 --- a/Kernel/Disk.cpp +++ b/Kernel/Disk.cpp @@ -7,6 +7,7 @@ #include "IO.h" #include "i386.h" #include "PIC.h" +#include <AK/Lock.h> //#define DISK_DEBUG @@ -55,7 +56,7 @@ static bool waitForInterrupt() #endif // FIXME: Add timeout. while (!interrupted) { - yield(); + sched_yield(); } #ifdef DISK_DEBUG kprintf("disk: got interrupt!\n"); diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 6501bb84e1..d41ac99284 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -388,7 +388,7 @@ int Process::exec(const String& path, Vector<String>&& arguments, Vector<String> #endif if (current == this) - yield(); + sched_yield(); return 0; } @@ -814,7 +814,7 @@ void Process::send_signal(int signal, Process* sender) dbgprintf("signal: %s(%u) sent %d to %s(%u)\n", sender->name().characters(), sender->pid(), signal, name().characters(), pid()); if (sender == this) { - yield(); + sched_yield(); ASSERT_NOT_REACHED(); } } @@ -865,7 +865,7 @@ void Process::doHouseKeeping() s_deadProcesses->clear(); } -void yield() +int sched_yield() { if (!current) { kprintf( "PANIC: yield() with !current" ); @@ -876,10 +876,11 @@ void yield() InterruptDisabler disabler; if (!scheduleNewProcess()) - return; + return 1; //kprintf("yield() jumping to new process: %x (%s)\n", current->farPtr().selector, current->name().characters()); switchNow(); + return 0; } void switchNow() @@ -1121,7 +1122,7 @@ ssize_t Process::sys$read(int fd, void* outbuf, size_t nread) if (!descriptor->hasDataAvailableForRead()) { m_fdBlockedOnRead = fd; block(BlockedRead); - yield(); + sched_yield(); } } nread = descriptor->read((byte*)outbuf, nread); @@ -1351,7 +1352,7 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options) m_waitee = waitee; m_waiteeStatus = 0; block(BlockedWait); - yield(); + sched_yield(); if (wstatus) *wstatus = m_waiteeStatus; return m_waitee; @@ -1374,7 +1375,7 @@ void Process::block(Process::State state) void block(Process::State state) { current->block(state); - yield(); + sched_yield(); } void sleep(DWORD ticks) @@ -1382,7 +1383,7 @@ void sleep(DWORD ticks) ASSERT(current->state() == Process::Running); current->setWakeupTime(system.uptime + ticks); current->block(Process::BlockedSleep); - yield(); + sched_yield(); } Process* Process::kernelProcess() diff --git a/Kernel/Process.h b/Kernel/Process.h index eb76f6b16e..0b6d27f461 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -284,7 +284,7 @@ static inline const char* toString(Process::State state) return nullptr; } -extern void yield(); +extern int sched_yield(); extern bool scheduleNewProcess(); extern void switchNow(); extern void block(Process::State); diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index 0a6acf8022..a6695c377f 100644 --- a/Kernel/Syscall.cpp +++ b/Kernel/Syscall.cpp @@ -48,7 +48,7 @@ static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2, ASSERT_INTERRUPTS_ENABLED(); switch (function) { case Syscall::SC_yield: - yield(); + sched_yield(); break; case Syscall::SC_putch: Console::the().putChar(arg1 & 0xff); diff --git a/VirtualFileSystem/FileDescriptor.cpp b/VirtualFileSystem/FileDescriptor.cpp index 547fdb8c52..93e66f91f3 100644 --- a/VirtualFileSystem/FileDescriptor.cpp +++ b/VirtualFileSystem/FileDescriptor.cpp @@ -3,9 +3,12 @@ #include "CharacterDevice.h" #include "sys-errno.h" #include "UnixTypes.h" -#include "TTY.h" #include <AK/BufferStream.h> +#ifdef SERENITY +#include "TTY.h" +#endif + RetainPtr<FileDescriptor> FileDescriptor::create(RetainPtr<VirtualFileSystem::Node>&& vnode) { return adopt(*new FileDescriptor(move(vnode))); @@ -178,7 +181,8 @@ ssize_t FileDescriptor::get_dir_entries(byte* buffer, Unix::size_t size) memcpy(buffer, tempBuffer.pointer(), stream.offset()); return stream.offset(); } - +\ +#ifdef SERENITY bool FileDescriptor::isTTY() const { if (auto* device = m_vnode->characterDevice()) @@ -199,6 +203,7 @@ TTY* FileDescriptor::tty() return static_cast<TTY*>(device); return nullptr; } +#endif int FileDescriptor::close() { @@ -207,7 +212,9 @@ int FileDescriptor::close() String FileDescriptor::absolute_path() const { +#ifdef SERENITY if (isTTY()) return tty()->ttyName(); +#endif return VirtualFileSystem::the().absolutePath(m_vnode->inode); } diff --git a/VirtualFileSystem/FileDescriptor.h b/VirtualFileSystem/FileDescriptor.h index 32e1cb8a8b..2c02e84189 100644 --- a/VirtualFileSystem/FileDescriptor.h +++ b/VirtualFileSystem/FileDescriptor.h @@ -5,7 +5,9 @@ #include <AK/ByteBuffer.h> #include <AK/Retainable.h> +#ifdef SERENITY class TTY; +#endif class FileDescriptor : public Retainable<FileDescriptor> { public: @@ -31,9 +33,11 @@ public: bool isDirectory() const; +#ifdef SERENITY bool isTTY() const; const TTY* tty() const; TTY* tty(); +#endif InodeMetadata metadata() const { return m_vnode->metadata(); } diff --git a/VirtualFileSystem/Makefile b/VirtualFileSystem/Makefile index cac239bf7c..9542483941 100644 --- a/VirtualFileSystem/Makefile +++ b/VirtualFileSystem/Makefile @@ -15,7 +15,7 @@ VFS_OBJS = \ FileSystem.o \ Ext2FileSystem.o \ VirtualFileSystem.o \ - FileHandle.o \ + FileDescriptor.o \ DiskBackedFileSystem.o \ SyntheticFileSystem.o \ InodeIdentifier.o \ diff --git a/VirtualFileSystem/SyntheticFileSystem.cpp b/VirtualFileSystem/SyntheticFileSystem.cpp index 52c2f921ff..a3e1408215 100644 --- a/VirtualFileSystem/SyntheticFileSystem.cpp +++ b/VirtualFileSystem/SyntheticFileSystem.cpp @@ -37,8 +37,8 @@ bool SyntheticFileSystem::initialize() m_inodes.set(RootInodeIndex, move(rootDir)); #ifndef SERENITY - addFile(createTextFile("file", "I'm a synthetic file!\n")); - addFile(createTextFile("message", "Hey! This isn't my bottle!\n")); + addFile(createTextFile("file", String("I'm a synthetic file!\n").toByteBuffer(), 0100644)); + addFile(createTextFile("message", String("Hey! This isn't my bottle!\n").toByteBuffer(), 0100644)); addFile(createGeneratedFile("lunk", [] { return String("/home/andreas/file1").toByteBuffer(); }, 00120777)); #endif return true; diff --git a/VirtualFileSystem/VirtualFileSystem.cpp b/VirtualFileSystem/VirtualFileSystem.cpp index 2e140b1bf8..9e4e59f9a1 100644 --- a/VirtualFileSystem/VirtualFileSystem.cpp +++ b/VirtualFileSystem/VirtualFileSystem.cpp @@ -12,24 +12,19 @@ static VirtualFileSystem* s_the; +#ifndef SERENITY +typedef int InterruptDisabler; +#endif + VirtualFileSystem& VirtualFileSystem::the() { ASSERT(s_the); return *s_the; } -static SpinLock* s_vfsLock; - -SpinLock& VirtualFileSystem::lock() -{ - ASSERT(s_vfsLock); - return *s_vfsLock; -} - void VirtualFileSystem::initializeGlobals() { s_the = nullptr; - s_vfsLock = new SpinLock; FileSystem::initializeGlobals(); } diff --git a/VirtualFileSystem/VirtualFileSystem.h b/VirtualFileSystem/VirtualFileSystem.h index f5359a7099..082be01d35 100644 --- a/VirtualFileSystem/VirtualFileSystem.h +++ b/VirtualFileSystem/VirtualFileSystem.h @@ -5,7 +5,6 @@ #include <AK/RetainPtr.h> #include <AK/String.h> #include <AK/Vector.h> -#include <AK/Lock.h> #include <AK/Function.h> #include "InodeIdentifier.h" #include "InodeMetadata.h" @@ -31,7 +30,6 @@ class VirtualFileSystem { AK_MAKE_ETERNAL public: static void initializeGlobals(); - static SpinLock& lock(); class Mount { public: diff --git a/VirtualFileSystem/test.cpp b/VirtualFileSystem/test.cpp index e0c95d936f..5cb14dfd2e 100644 --- a/VirtualFileSystem/test.cpp +++ b/VirtualFileSystem/test.cpp @@ -26,16 +26,16 @@ int main(int c, char** v) VirtualFileSystem vfs; auto zero = make<ZeroDevice>(); - vfs.registerCharacterDevice(1, 5, *zero); + vfs.registerCharacterDevice(*zero); auto null = make<NullDevice>(); - vfs.registerCharacterDevice(1, 3, *null); + vfs.registerCharacterDevice(*null); auto full = make<FullDevice>(); - vfs.registerCharacterDevice(1, 7, *full); + vfs.registerCharacterDevice(*full); auto random = make<RandomDevice>(); - vfs.registerCharacterDevice(1, 8, *random); + vfs.registerCharacterDevice(*random); if (!vfs.mountRoot(makeFileSystem(filename))) { printf("Failed to mount root :(\n"); |