Skip to content

Commit

Permalink
Paper over a race in DoubleBuffer.
Browse files Browse the repository at this point in the history
I'm still somewhat okay throwing InterruptDisabler at races as they screw me.
Eventually I'm gonna have to devise a different strategy though.
  • Loading branch information
awesomekling committed Jan 12, 2019
1 parent 2e2d883 commit 3ac977f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
6 changes: 5 additions & 1 deletion Kernel/DoubleBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

void DoubleBuffer::flip()
{
InterruptDisabler disabler;
ASSERT(m_read_buffer_index == m_read_buffer->size());
swap(m_read_buffer, m_write_buffer);
m_write_buffer->clear();
if (m_write_buffer->capacity() < 32)
m_write_buffer->clear_with_capacity();
else
m_write_buffer->clear();
m_read_buffer_index = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion Kernel/kmalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void* kmalloc_page_aligned(size_t size)
return ptr;
}

void* kmalloc(dword size)
void* kmalloc_impl(dword size)
{
InterruptDisabler disabler;

Expand Down
10 changes: 9 additions & 1 deletion Kernel/kmalloc.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

void kmalloc_init();
void *kmalloc(dword size) __attribute__ ((malloc));
void* kmalloc_impl(dword size) __attribute__ ((malloc));
void* kmalloc_eternal(size_t) __attribute__ ((malloc));
void* kmalloc_page_aligned(size_t) __attribute__ ((malloc));
void* kmalloc_aligned(size_t, size_t alignment) __attribute__ ((malloc));
Expand All @@ -17,3 +17,11 @@ extern volatile size_t kmalloc_sum_page_aligned;

inline void* operator new(size_t, void* p) { return p; }
inline void* operator new[](size_t, void* p) { return p; }

ALWAYS_INLINE void* kmalloc(size_t size)
{
// Any kernel allocation >= 32K is very suspicious, catch them.
if (size >= 0x8000)
asm volatile("cli;hlt");
return kmalloc_impl(size);
}
6 changes: 5 additions & 1 deletion Widgets/EventLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ int EventLoop::exec()
for (;;) {
if (m_queuedEvents.is_empty())
waitForEvent();
auto events = move(m_queuedEvents);
Vector<QueuedEvent> events;
{
InterruptDisabler disabler;
events = move(m_queuedEvents);
}
for (auto& queuedEvent : events) {
auto* receiver = queuedEvent.receiver;
auto& event = *queuedEvent.event;
Expand Down

0 comments on commit 3ac977f

Please sign in to comment.