1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:07:45 +00:00

AK: Move the userspace SharedBuffer from LibC to AK

This always felt out-of-place in LibC.
This commit is contained in:
Andreas Kling 2020-01-01 18:53:34 +01:00
parent 38f93ef13b
commit fc86460134
22 changed files with 41 additions and 24 deletions

View file

@ -3,7 +3,7 @@
#include <AK/ByteBuffer.h>
#include <AK/Types.h>
#include <AK/Vector.h>
#include <LibC/SharedBuffer.h>
#include <AK/SharedBuffer.h>
// A single sample in an audio buffer.
// Values are floating point, and should range from -1.0 to +1.0

View file

@ -1,6 +1,6 @@
#include <AK/SharedBuffer.h>
#include <LibAudio/ABuffer.h>
#include <LibAudio/AClientConnection.h>
#include <SharedBuffer.h>
AClientConnection::AClientConnection()
: IServerConnection(*this, "/tmp/portal/audio")

View file

@ -9,10 +9,10 @@ AK_OBJS = \
../../AK/JsonParser.o \
../../AK/LogStream.o \
../../AK/MappedFile.o \
../../AK/SharedBuffer.o \
../../AK/Utf8View.o
LIBC_OBJS = \
SharedBuffer.o \
stdio.o \
unistd.o \
string.o \

View file

@ -1,94 +0,0 @@
#include <AK/kmalloc.h>
#include <Kernel/Syscall.h>
#include <SharedBuffer.h>
#include <stdio.h>
#include <unistd.h>
RefPtr<SharedBuffer> SharedBuffer::create_with_size(int size)
{
void* data;
int shared_buffer_id = create_shared_buffer(size, &data);
if (shared_buffer_id < 0) {
perror("create_shared_buffer");
return nullptr;
}
return adopt(*new SharedBuffer(shared_buffer_id, size, data));
}
bool SharedBuffer::share_with(pid_t peer)
{
int ret = share_buffer_with(shared_buffer_id(), peer);
if (ret < 0) {
perror("share_buffer_with");
return false;
}
return true;
}
bool SharedBuffer::share_globally()
{
int ret = share_buffer_globally(shared_buffer_id());
if (ret < 0) {
perror("share_buffer_globally");
return false;
}
return true;
}
RefPtr<SharedBuffer> SharedBuffer::create_from_shared_buffer_id(int shared_buffer_id)
{
void* data = get_shared_buffer(shared_buffer_id);
if (data == (void*)-1) {
perror("get_shared_buffer");
return nullptr;
}
int size = get_shared_buffer_size(shared_buffer_id);
if (size < 0) {
perror("get_shared_buffer_size");
return nullptr;
}
return adopt(*new SharedBuffer(shared_buffer_id, size, data));
}
SharedBuffer::SharedBuffer(int shared_buffer_id, int size, void* data)
: m_shared_buffer_id(shared_buffer_id)
, m_size(size)
, m_data(data)
{
}
SharedBuffer::~SharedBuffer()
{
if (m_shared_buffer_id >= 0) {
int rc = release_shared_buffer(m_shared_buffer_id);
if (rc < 0) {
perror("release_shared_buffer");
}
}
}
void SharedBuffer::seal()
{
int rc = seal_shared_buffer(m_shared_buffer_id);
if (rc < 0) {
perror("seal_shared_buffer");
ASSERT_NOT_REACHED();
}
}
void SharedBuffer::set_volatile()
{
u32 rc = syscall(SC_set_shared_buffer_volatile, m_shared_buffer_id, true);
ASSERT(rc == 0);
}
bool SharedBuffer::set_nonvolatile()
{
u32 rc = syscall(SC_set_shared_buffer_volatile, m_shared_buffer_id, false);
if (rc == 0)
return true;
if (rc == 1)
return false;
ASSERT_NOT_REACHED();
}

View file

@ -1,28 +0,0 @@
#pragma once
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
class SharedBuffer : public RefCounted<SharedBuffer> {
public:
static RefPtr<SharedBuffer> create_with_size(int);
static RefPtr<SharedBuffer> create_from_shared_buffer_id(int);
~SharedBuffer();
bool share_globally();
bool share_with(pid_t);
int shared_buffer_id() const { return m_shared_buffer_id; }
void seal();
int size() const { return m_size; }
void* data() { return m_data; }
const void* data() const { return m_data; }
void set_volatile();
[[nodiscard]] bool set_nonvolatile();
private:
SharedBuffer(int shared_buffer_id, int size, void*);
int m_shared_buffer_id { -1 };
int m_size { 0 };
void* m_data;
};

View file

@ -6,9 +6,9 @@
#include <AK/MappedFile.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/SharedBuffer.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <SharedBuffer.h>
class GraphicsBitmap : public RefCounted<GraphicsBitmap> {
public:
@ -105,7 +105,8 @@ public:
[[nodiscard]] bool set_nonvolatile();
private:
enum class Purgeable { No, Yes };
enum class Purgeable { No,
Yes };
GraphicsBitmap(Format, const Size&, Purgeable);
GraphicsBitmap(Format, const Size&, size_t pitch, RGBA32*);
GraphicsBitmap(Format, const Size&, MappedFile&&);

View file

@ -1,8 +1,8 @@
#pragma once
#include <AK/SharedBuffer.h>
#include <AK/Types.h>
#include <LibDraw/Color.h>
#include <SharedBuffer.h>
enum class ColorRole {
NoRole,

View file

@ -6,6 +6,10 @@
#include <LibDraw/Palette.h>
#include <LibGUI/GShortcut.h>
namespace AK {
class SharedBuffer;
}
class CEventLoop;
class GAction;
class GKeyEvent;
@ -14,7 +18,6 @@ class GWindow;
class GWindowServerConnection;
class Palette;
class Point;
class SharedBuffer;
class GApplication {
public:

View file

@ -1,4 +1,4 @@
#include <LibC/SharedBuffer.h>
#include <AK/SharedBuffer.h>
#include <LibGUI/GClipboard.h>
#include <LibGUI/GWindowServerConnection.h>

View file

@ -1,7 +1,7 @@
#include <AK/HashMap.h>
#include <AK/JsonObject.h>
#include <AK/NeverDestroyed.h>
#include <LibC/SharedBuffer.h>
#include <AK/SharedBuffer.h>
#include <LibC/stdio.h>
#include <LibC/stdlib.h>
#include <LibC/unistd.h>

View file

@ -1,4 +1,4 @@
#include <LibC/SharedBuffer.h>
#include <AK/SharedBuffer.h>
#include <LibCore/CFile.h>
#include <LibHTML/ResourceLoader.h>
#include <LibProtocol/Client.h>

View file

@ -1,6 +1,6 @@
#include <AK/SharedBuffer.h>
#include <LibProtocol/Client.h>
#include <LibProtocol/Download.h>
#include <SharedBuffer.h>
namespace LibProtocol {

View file

@ -1,4 +1,4 @@
#include <LibC/SharedBuffer.h>
#include <AK/SharedBuffer.h>
#include <LibProtocol/Client.h>
#include <LibProtocol/Download.h>

View file

@ -6,7 +6,9 @@
#include <AK/RefCounted.h>
#include <AK/WeakPtr.h>
namespace AK {
class SharedBuffer;
}
namespace LibProtocol {