[kernel] Consolodate koid and close syscalls

A number of object types had _close or _koid syscalls. Moved those to be
generic for kobject.
This commit is contained in:
2020-10-05 21:51:42 -07:00
parent 1904e240cf
commit 97ea77bd27
18 changed files with 79 additions and 94 deletions

View File

@@ -78,8 +78,8 @@ channel::dequeue(size_t *len, void *data)
void
channel::close()
{
kobject::close();
g_kernel_buffers.return_buffer(m_data);
assert_signal(j6_signal_channel_closed);
}
void

View File

@@ -37,10 +37,7 @@ public:
/// Mark this channel as closed, all future calls to enqueue or
/// dequeue messages will fail with j6_status_closed.
void close();
/// Check if this channel has been closed
inline bool closed() { return check_signal(j6_signal_channel_closed); }
virtual void close() override;
protected:
virtual void on_no_handles() override;

View File

@@ -10,14 +10,15 @@ endpoint::endpoint() :
endpoint::~endpoint()
{
if (!check_signal(j6_signal_endpoint_closed))
if (!check_signal(j6_signal_closed))
close();
}
void
endpoint::close()
{
assert_signal(j6_signal_endpoint_closed);
kobject::close();
for (auto &data : m_blocked) {
if (data.th)
data.th->wake_on_result(this, j6_status_closed);

View File

@@ -16,7 +16,7 @@ public:
static constexpr kobject::type type = kobject::type::endpoint;
/// Close the endpoint, waking all waiting processes with an error
void close();
virtual void close() override;
/// Check if the endpoint has space for a message to be sent
inline bool can_send() const { return check_signal(j6_signal_endpoint_can_send); }

View File

@@ -61,6 +61,12 @@ kobject::notify_signal_observers()
}
}
void
kobject::close()
{
assert_signal(j6_signal_closed);
}
void
kobject::on_no_handles()
{

View File

@@ -3,6 +3,7 @@
/// Definition of base type for user-interactable kernel objects
#include "j6/errors.h"
#include "j6/signals.h"
#include "j6/types.h"
#include "kutil/vector.h"
@@ -76,6 +77,12 @@ public:
/// Remove the given thread from the list of threads waiting on this object.
inline void remove_blocked_thread(thread *t) { m_blocked_threads.remove_swap(t); }
/// Perform any cleanup actions necessary to mark this object closed
virtual void close();
/// Check if this object has been closed
inline bool closed() const { return check_signal(j6_signal_closed); }
protected:
/// Interface for subclasses to handle when all handles are closed. Subclasses
/// should either call the base version, or assert j6_signal_no_handles.

View File

@@ -1,4 +1,3 @@
#include "j6/signals.h"
#include "kutil/assert.h"
#include "kutil/no_construct.h"
#include "cpu.h"
@@ -62,7 +61,7 @@ process::exit(unsigned code)
thread->exit(code);
}
m_return_code = code;
assert_signal(j6_signal_process_exit);
close();
if (this == bsp_cpu_data.p)
scheduler::get().schedule();

View File

@@ -139,7 +139,7 @@ thread::exit(uint32_t code)
m_return_code = code;
set_state(state::exited);
clear_state(state::ready);
assert_signal(j6_signal_thread_exit);
close();
schedule_if_current(this);
}