Added support for POSIX semaphores (the ones from the XSI extension
Realtime option group). The implementation should be complete, but is totally untested yet. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25326 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2008, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _SEMAPHORE_H_
|
||||
#define _SEMAPHORE_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
typedef struct {
|
||||
int id;
|
||||
} sem_t;
|
||||
|
||||
#define SEM_FAILED ((sem_t*)(long)-1)
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
sem_t* sem_open(const char* name, int openFlags,...);
|
||||
int sem_close(sem_t* semaphore);
|
||||
int sem_unlink(const char* name);
|
||||
|
||||
int sem_init(sem_t* semaphore, int shared, unsigned value);
|
||||
int sem_destroy(sem_t* semaphore);
|
||||
|
||||
int sem_post(sem_t* semaphore);
|
||||
int sem_timedwait(sem_t* semaphore, const struct timespec* timeout);
|
||||
int sem_trywait(sem_t* semaphore);
|
||||
int sem_wait(sem_t* semaphore);
|
||||
int sem_getvalue(sem_t* semaphore, int* value);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
||||
#endif /* _SEMAPHORE_H_ */
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2008, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef KERNEL_REALTIME_SEM_H
|
||||
#define KERNEL_REALTIME_SEM_H
|
||||
|
||||
#include <semaphore.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <OS.h>
|
||||
|
||||
|
||||
struct realtime_sem_context;
|
||||
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
void realtime_sem_init();
|
||||
void delete_realtime_sem_context(struct realtime_sem_context* context);
|
||||
struct realtime_sem_context* clone_realtime_sem_context(
|
||||
struct realtime_sem_context* context);
|
||||
|
||||
status_t _user_realtime_sem_open(const char* name, int openFlags,
|
||||
mode_t mode, uint32 semCount, sem_t* userSem,
|
||||
sem_t** _usedUserSem);
|
||||
status_t _user_realtime_sem_close(sem_id semID, sem_t** _deleteUserSem);
|
||||
status_t _user_realtime_sem_unlink(const char* name);
|
||||
|
||||
status_t _user_realtime_sem_get_value(sem_id semID, int* value);
|
||||
status_t _user_realtime_sem_post(sem_id semID);
|
||||
status_t _user_realtime_sem_wait(sem_id semID, bigtime_t timeout);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
||||
#endif // KERNEL_REALTIME_SEM_H
|
||||
@@ -20,7 +20,7 @@ struct select_info;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern status_t sem_init(struct kernel_args *args);
|
||||
extern status_t haiku_sem_init(struct kernel_args *args);
|
||||
extern int sem_delete_owned_sems(team_id owner);
|
||||
extern int32 sem_used_sems(void);
|
||||
extern int32 sem_max_sems(void);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <OS.h>
|
||||
#include <DiskDeviceDefs.h>
|
||||
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
@@ -75,6 +76,18 @@ extern status_t _kern_get_next_sem_info(team_id team, int32 *cookie,
|
||||
struct sem_info *info, size_t size);
|
||||
extern status_t _kern_set_sem_owner(sem_id id, team_id proc);
|
||||
|
||||
/* POSIX realtime sem syscalls */
|
||||
extern status_t _kern_realtime_sem_open(const char* name, int openFlags,
|
||||
mode_t mode, uint32 semCount, sem_t* userSem,
|
||||
sem_t** _usedUserSem);
|
||||
extern status_t _kern_realtime_sem_close(sem_id semID,
|
||||
sem_t** _deleteUserSem);
|
||||
extern status_t _kern_realtime_sem_unlink(const char* name);
|
||||
|
||||
extern status_t _kern_realtime_sem_get_value(sem_id semID, int* value);
|
||||
extern status_t _kern_realtime_sem_post(sem_id semID);
|
||||
extern status_t _kern_realtime_sem_wait(sem_id semID, bigtime_t timeout);
|
||||
|
||||
/* team & thread syscalls */
|
||||
|
||||
extern thread_id _kern_load_image(int32 argCount, const char **args,
|
||||
|
||||
@@ -68,8 +68,8 @@ enum {
|
||||
THREAD_BLOCK_TYPE_USER_BASE = 10000
|
||||
};
|
||||
|
||||
struct image;
|
||||
// defined in image.c
|
||||
struct image; // defined in image.c
|
||||
struct realtime_sem_context; // defined in realtime_sem.cpp
|
||||
struct select_info;
|
||||
|
||||
struct death_entry {
|
||||
@@ -181,6 +181,7 @@ struct team {
|
||||
int state; // current team state, see above
|
||||
int32 flags;
|
||||
void *io_context;
|
||||
struct realtime_sem_context *realtime_sem_context;
|
||||
sem_id death_sem; // semaphore to wait on for dying threads
|
||||
struct list dead_threads;
|
||||
int dead_threads_count;
|
||||
|
||||
Reference in New Issue
Block a user