Added a few more functions to the host platform BeOS compatibility layer:
* thread related functions, * semaphore related functions, * atomic_*() functions, * readv_pos(), writev_pos(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20858 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -22,7 +22,11 @@ extern size_t strnlen(const char *string, size_t length);
|
|||||||
|
|
||||||
// BeOS only
|
// BeOS only
|
||||||
extern ssize_t read_pos(int fd, off_t pos, void *buffer, size_t count);
|
extern ssize_t read_pos(int fd, off_t pos, void *buffer, size_t count);
|
||||||
extern ssize_t write_pos(int fd, off_t pos, const void *buffer,size_t count);
|
extern ssize_t write_pos(int fd, off_t pos, const void *buffer, size_t count);
|
||||||
|
extern ssize_t readv_pos(int fd, off_t pos, const struct iovec *vec,
|
||||||
|
size_t count);
|
||||||
|
extern ssize_t writev_pos(int fd, off_t pos, const struct iovec *vec,
|
||||||
|
size_t count);
|
||||||
|
|
||||||
|
|
||||||
// There's no O_NOTRAVERSE under Linux and FreeBSD, but there's a O_NOFOLLOW, which
|
// There's no O_NOTRAVERSE under Linux and FreeBSD, but there's a O_NOFOLLOW, which
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ UseHeaders [ FDirName $(HAIKU_TOP) headers build private kernel ] : true ;
|
|||||||
MakeLocate libroot_build.so : $(HOST_BUILD_COMPATIBILITY_LIB_DIR) ;
|
MakeLocate libroot_build.so : $(HOST_BUILD_COMPATIBILITY_LIB_DIR) ;
|
||||||
|
|
||||||
BuildPlatformSharedLibrary libroot_build.so :
|
BuildPlatformSharedLibrary libroot_build.so :
|
||||||
|
atomic.cpp
|
||||||
byteorder.cpp
|
byteorder.cpp
|
||||||
errors.cpp
|
errors.cpp
|
||||||
fs.cpp
|
fs.cpp
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
#include <BeOSBuildCompatibility.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <OS.h>
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
atomic_set(vint32 *value, int32 newValue)
|
||||||
|
{
|
||||||
|
int32 oldValue = *value;
|
||||||
|
*value = newValue;
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
atomic_test_and_set(vint32 *value, int32 newValue, int32 testAgainst)
|
||||||
|
{
|
||||||
|
int32 oldValue = *value;
|
||||||
|
if (oldValue == testAgainst)
|
||||||
|
*value = newValue;
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
atomic_add(vint32 *value, int32 addValue)
|
||||||
|
{
|
||||||
|
int32 oldValue = *value;
|
||||||
|
value += addValue;
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
atomic_and(vint32 *value, int32 andValue)
|
||||||
|
{
|
||||||
|
int32 oldValue = *value;
|
||||||
|
*value &= andValue;
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
atomic_or(vint32 *value, int32 orValue)
|
||||||
|
{
|
||||||
|
int32 oldValue = *value;
|
||||||
|
*value |= orValue;
|
||||||
|
return oldValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
atomic_get(vint32 *value)
|
||||||
|
{
|
||||||
|
return *value;
|
||||||
|
}
|
||||||
@@ -959,3 +959,41 @@ write_pos(int fd, off_t pos, const void *buffer, size_t bufferSize)
|
|||||||
|
|
||||||
return bytesWritten;
|
return bytesWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// readv_pos
|
||||||
|
ssize_t
|
||||||
|
readv_pos(int fd, off_t pos, const struct iovec *vec, size_t count)
|
||||||
|
{
|
||||||
|
// seek
|
||||||
|
off_t result = lseek(fd, pos, SEEK_SET);
|
||||||
|
if (result < 0)
|
||||||
|
return errno;
|
||||||
|
|
||||||
|
// read
|
||||||
|
ssize_t bytesRead = readv(fd, vec, count);
|
||||||
|
if (bytesRead < 0) {
|
||||||
|
errno = bytesRead;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bytesRead;
|
||||||
|
}
|
||||||
|
|
||||||
|
// writev_pos
|
||||||
|
ssize_t
|
||||||
|
writev_pos(int fd, off_t pos, const struct iovec *vec, size_t count)
|
||||||
|
{
|
||||||
|
// seek
|
||||||
|
off_t result = lseek(fd, pos, SEEK_SET);
|
||||||
|
if (result < 0)
|
||||||
|
return errno;
|
||||||
|
|
||||||
|
// read
|
||||||
|
ssize_t bytesWritten = writev(fd, vec, count);
|
||||||
|
if (bytesWritten < 0) {
|
||||||
|
errno = bytesWritten;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bytesWritten;
|
||||||
|
}
|
||||||
|
|||||||
@@ -142,11 +142,63 @@ release_sem_etc(sem_id id, int32 count, uint32 flags)
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// atomic_add
|
// get_sem_count
|
||||||
int32
|
status_t
|
||||||
atomic_add(vint32 *value, int32 addValue)
|
get_sem_count(sem_id id, int32 *threadCount)
|
||||||
{
|
{
|
||||||
int32 oldValue = *value;
|
if (!check_sem(id))
|
||||||
value += addValue;
|
return B_BAD_SEM_ID;
|
||||||
return oldValue;
|
|
||||||
|
if (!threadCount)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
*threadCount = sSemaphores[id].count;
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set_sem_owner
|
||||||
|
status_t
|
||||||
|
set_sem_owner(sem_id id, team_id team)
|
||||||
|
{
|
||||||
|
if (!check_sem(id))
|
||||||
|
return B_BAD_SEM_ID;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// _get_sem_info
|
||||||
|
status_t
|
||||||
|
_get_sem_info(sem_id id, struct sem_info *info, size_t infoSize)
|
||||||
|
{
|
||||||
|
if (!check_sem(id))
|
||||||
|
return B_BAD_SEM_ID;
|
||||||
|
|
||||||
|
if (!info)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
info->sem = id;
|
||||||
|
info->team = 1;
|
||||||
|
info->name[0] = '\0';
|
||||||
|
info->count = sSemaphores[id].count;
|
||||||
|
info->latest_holder = -1;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// _get_next_sem_info
|
||||||
|
status_t
|
||||||
|
_get_next_sem_info(team_id team, int32 *cookie, struct sem_info *info,
|
||||||
|
size_t infoSize)
|
||||||
|
{
|
||||||
|
if (team < 0 || team > 2)
|
||||||
|
return B_BAD_TEAM_ID;
|
||||||
|
|
||||||
|
for (int i = *cookie; i < kSemaphoreCount; i++) {
|
||||||
|
if (sSemaphores[i].inUse) {
|
||||||
|
*cookie = i + 1;
|
||||||
|
return _get_sem_info(i, info, infoSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_ENTRY_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,28 @@
|
|||||||
|
|
||||||
static const thread_id kMainThreadID = 3;
|
static const thread_id kMainThreadID = 3;
|
||||||
|
|
||||||
|
|
||||||
|
// kill_thread
|
||||||
|
status_t
|
||||||
|
kill_thread(thread_id thread)
|
||||||
|
{
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// resume_thread
|
||||||
|
status_t
|
||||||
|
resume_thread(thread_id thread)
|
||||||
|
{
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// suspend_thread
|
||||||
|
status_t
|
||||||
|
suspend_thread(thread_id thread)
|
||||||
|
{
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
// find_thread
|
// find_thread
|
||||||
thread_id
|
thread_id
|
||||||
find_thread(const char *name)
|
find_thread(const char *name)
|
||||||
|
|||||||
Reference in New Issue
Block a user