mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:57:34 +00:00
AK: Enable AK::SharedBuffer for all platforms
A future patch could do some MacOS specific things for set_volatile/set_nonvolatile. For now, swap out the defined(__linux__) branches for simple not __serenity__ branches.
This commit is contained in:
parent
02fcf3974e
commit
8ce7df73fb
2 changed files with 30 additions and 39 deletions
|
@ -24,16 +24,13 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(__serenity__) || defined(__linux__)
|
||||
|
||||
#include <AK/SharedBuffer.h>
|
||||
# include <AK/kmalloc.h>
|
||||
# include <Kernel/API/Syscall.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(__serenity__)
|
||||
# include <Kernel/API/Syscall.h>
|
||||
# include <serenity.h>
|
||||
# elif defined(__linux__)
|
||||
#else
|
||||
# include <AK/String.h>
|
||||
# include <fcntl.h>
|
||||
# include <sys/mman.h>
|
||||
|
@ -56,7 +53,7 @@ RefPtr<SharedBuffer> SharedBuffer::create_with_size(int size)
|
|||
perror("shbuf_create");
|
||||
return nullptr;
|
||||
}
|
||||
# elif defined(__linux__)
|
||||
#else
|
||||
// Not atomic, so don't create shared buffers from many threads too hard under lagom.
|
||||
static unsigned g_shm_id = 0;
|
||||
|
||||
|
@ -120,7 +117,7 @@ RefPtr<SharedBuffer> SharedBuffer::create_from_shbuf_id(int shbuf_id)
|
|||
void* data = shbuf_get(shbuf_id, &size);
|
||||
if (data == (void*)-1)
|
||||
return nullptr;
|
||||
# elif defined(__linux__)
|
||||
#else
|
||||
int fd = shm_open(shbuf_shm_name(shbuf_id).characters(), O_RDWR, S_IRUSR | S_IWUSR);
|
||||
if (fd < 0) {
|
||||
perror("shm_open");
|
||||
|
@ -171,7 +168,7 @@ SharedBuffer::~SharedBuffer()
|
|||
if (rc < 0) {
|
||||
perror("shbuf_release");
|
||||
}
|
||||
# elif defined(__linux__)
|
||||
#else
|
||||
if (munmap(reinterpret_cast<u8*>(m_data) - sizeof(size_t), m_size + sizeof(size_t)) < 0)
|
||||
perror("munmap");
|
||||
if (shm_unlink(shbuf_shm_name(m_shbuf_id).characters()) < 0)
|
||||
|
@ -211,5 +208,3 @@ bool SharedBuffer::set_nonvolatile()
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#if defined(__serenity__) || defined(__linux__)
|
||||
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/RefPtr.h>
|
||||
|
||||
|
@ -73,5 +71,3 @@ private:
|
|||
}
|
||||
|
||||
using AK::SharedBuffer;
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue