* Renamed fs/vfs_select.cpp to wait_for_objects.cpp and got rid of

vfs_select.h, respectively moved most of it into the new kernel
  private header wait_for_objects.h.
* Added new experimental API functions wait_for_objects[_etc](). They
  work pretty much like poll(), but also for semaphores, ports, and
  threads.
* Removed the "ref" parameter from notify_select_events() and the
  select_sync_pool functions as well as from fd_ops::fd_[de]select(). It
  is no longer needed. The FS interface select() hook still has it,
  though -- the VFS will always pass 0.
* de]select_fd() take a select_info* instead of a select_sync* + ref
  pair, now. Added respective functions for semaphores, ports, and
  threads.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22416 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2007-10-02 19:47:31 +00:00
parent a82d70c719
commit 636bfc08ae
37 changed files with 717 additions and 160 deletions
+1 -5
View File
@@ -31,11 +31,7 @@ enum select_events {
extern "C" {
#endif
#ifdef COMPILE_FOR_R5
extern void notify_select_event(struct selectsync *sync, uint32 ref);
#else
extern status_t notify_select_event(struct selectsync *sync, uint32 ref, uint8 event);
#endif
extern status_t notify_select_event(struct selectsync *sync, uint8 event);
#ifdef __cplusplus
}
+46
View File
@@ -658,6 +658,52 @@ extern status_t _get_system_info(system_info *info, size_t size);
extern int32 is_computer_on(void);
extern double is_computer_on_fire(void);
// WARNING: Experimental API!
enum {
B_OBJECT_TYPE_FD = 0,
B_OBJECT_TYPE_SEMAPHORE = 1,
B_OBJECT_TYPE_PORT = 2,
B_OBJECT_TYPE_THREAD = 3
};
enum {
B_EVENT_READ = 0x0001, // FD/port readable
B_EVENT_WRITE = 0x0002, // FD/port writable
B_EVENT_ERROR = 0x0004, // FD error
B_EVENT_PRIORITY_READ = 0x0008, // FD priority readable
B_EVENT_PRIORITY_WRITE = 0x0010, // FD priority writable
B_EVENT_HIGH_PRIORITY_READ = 0x0020, // FD high priority readable
B_EVENT_HIGH_PRIORITY_WRITE = 0x0040, // FD high priority writable
B_EVENT_DISCONNECTED = 0x0080, // FD disconnected
B_EVENT_ACQUIRE_SEMAPHORE = 0x0001, // semaphore can be acquired
B_EVENT_INVALID = 0x1000 // FD/port/sem/thread ID not or
// no longer valid (e.g. has been
// close/deleted)
};
typedef struct object_wait_info {
int32 object; // ID of the object
uint16 type; // type of the object
uint16 events; // events mask
} object_wait_info;
// wait_for_objects[_etc]() waits until at least one of the specified events or,
// if given, the timeout occurred. When entering the function the
// object_wait_info::events field specifies the events for each object the
// caller is interested in. When the function returns the fields reflect the
// events that actually occurred. The events B_EVENT_INVALID, B_EVENT_ERROR,
// and B_EVENT_DISCONNECTED don't need to be specified. They will always be
// reported, when they occur.
extern ssize_t wait_for_objects(object_wait_info* infos, int numInfos);
extern ssize_t wait_for_objects_etc(object_wait_info* infos, int numInfos,
uint32 flags, bigtime_t timeout);
#ifdef __cplusplus
}
#endif
+4 -6
View File
@@ -17,14 +17,14 @@ extern "C" {
struct file_descriptor;
struct selectsync;
struct select_sync;
struct select_info;
struct fd_ops {
status_t (*fd_read)(struct file_descriptor *, off_t pos, void *buffer, size_t *length);
status_t (*fd_write)(struct file_descriptor *, off_t pos, const void *buffer, size_t *length);
off_t (*fd_seek)(struct file_descriptor *, off_t pos, int seekType);
status_t (*fd_ioctl)(struct file_descriptor *, ulong op, void *buffer, size_t length);
status_t (*fd_select)(struct file_descriptor *, uint8 event, uint32 ref,
status_t (*fd_select)(struct file_descriptor *, uint8 event,
struct selectsync *sync);
status_t (*fd_deselect)(struct file_descriptor *, uint8 event,
struct selectsync *sync);
@@ -77,10 +77,8 @@ extern void close_fd(struct file_descriptor *descriptor);
extern void put_fd(struct file_descriptor *descriptor);
extern void disconnect_fd(struct file_descriptor *descriptor);
extern void inc_fd_ref_count(struct file_descriptor *descriptor);
extern status_t select_fd(int fd, struct select_sync *sync, uint32 ref,
bool kernel);
extern status_t deselect_fd(int fd, struct select_sync *sync, uint32 ref,
bool kernel);
extern status_t select_fd(int32 fd, struct select_info *info, bool kernel);
extern status_t deselect_fd(int32 fd, struct select_info *info, bool kernel);
extern bool fd_is_valid(int fd, bool kernel);
extern struct vnode *fd_vnode(struct file_descriptor *descriptor);
+1 -1
View File
@@ -17,7 +17,7 @@ extern "C" {
status_t add_select_sync_pool_entry(select_sync_pool **pool, selectsync *sync,
uint32 ref, uint8 event);
uint8 event);
status_t remove_select_sync_pool_entry(select_sync_pool **pool,
selectsync *sync, uint8 event);
void delete_select_sync_pool(select_sync_pool *pool);
+4
View File
@@ -10,6 +10,7 @@
#include <iovec.h>
struct kernel_args;
struct select_info;
#define PORT_FLAG_USE_USER_MEMCPY 0x80000000
@@ -23,6 +24,9 @@ int delete_owned_ports(team_id owner);
int32 port_max_ports(void);
int32 port_used_ports(void);
status_t select_port(int32 object, struct select_info *info, bool kernel);
status_t deselect_port(int32 object, struct select_info *info, bool kernel);
// currently private API
status_t writev_port_etc(port_id id, int32 msgCode, const iovec *msgVecs,
size_t vecCount, size_t bufferSize, uint32 flags, bigtime_t timeout);
+5
View File
@@ -13,6 +13,7 @@
#include <thread.h>
struct kernel_args;
struct select_info;
#ifdef __cplusplus
@@ -25,6 +26,10 @@ extern status_t sem_interrupt_thread(struct thread *t);
extern int32 sem_used_sems(void);
extern int32 sem_max_sems(void);
extern status_t select_sem(int32 object, struct select_info *info, bool kernel);
extern status_t deselect_sem(int32 object, struct select_info *info,
bool kernel);
extern sem_id create_sem_etc(int32 count, const char *name, team_id owner);
/* user calls */
+4
View File
@@ -53,6 +53,10 @@ extern int _kern_setrlimit(int resource, const struct rlimit * rlp);
extern status_t _kern_shutdown(bool reboot);
extern status_t _kern_get_safemode_option(const char *parameter, char *buffer, size_t *_bufferSize);
extern ssize_t _kern_wait_for_objects(object_wait_info* infos, int numInfos,
uint32 flags, bigtime_t timeout);
/* sem functions */
extern sem_id _kern_create_sem(int count, const char *name);
extern status_t _kern_delete_sem(sem_id id);
+4
View File
@@ -14,6 +14,7 @@
#include <arch/thread.h>
struct kernel_args;
struct select_info;
#ifdef __cplusplus
@@ -65,6 +66,9 @@ thread_id spawn_kernel_thread_etc(thread_func, const char *name, int32 priority,
status_t wait_for_thread_etc(thread_id id, uint32 flags, bigtime_t timeout,
status_t *_returnCode);
status_t select_thread(int32 object, struct select_info *info, bool kernel);
status_t deselect_thread(int32 object, struct select_info *info, bool kernel);
// used in syscalls.c
status_t _user_set_thread_priority(thread_id thread, int32 newPriority);
status_t _user_rename_thread(thread_id thread, const char *name);
+3
View File
@@ -54,6 +54,7 @@ typedef enum job_control_state {
struct image;
// defined in image.c
struct select_info;
struct death_entry {
struct list_link link;
@@ -234,6 +235,8 @@ struct thread {
struct list waiters;
} exit;
struct select_info *select_infos;
struct thread_debug_info debug_info;
// stack
+52
View File
@@ -0,0 +1,52 @@
/*
* Copyright 2007, Ingo Weinhold, [email protected]. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _KERNEL_WAIT_FOR_OBJECTS_H
#define _KERNEL_WAIT_FOR_OBJECTS_H
#include <OS.h>
#include <lock.h>
struct select_sync;
typedef struct select_info {
struct select_info* next; // next in the object's list
struct select_sync* sync;
uint16 selected_events;
uint16 events;
} select_info;
typedef struct select_sync {
vint32 ref_count;
benaphore lock;
sem_id sem;
uint32 count;
struct select_info* set;
} select_sync;
#define SELECT_FLAG(type) (1L << (type - 1))
#ifdef __cplusplus
extern "C" {
#endif
extern void put_select_sync(select_sync* sync);
extern status_t notify_select_events(select_info* info, uint16 events);
extern void notify_select_events_list(select_info* list, uint16 events);
extern ssize_t _user_wait_for_objects(object_wait_info* userInfos,
int numInfos, uint32 flags, bigtime_t timeout);
#ifdef __cplusplus
}
#endif
#endif // _KERNEL_WAIT_FOR_OBJECTS_H
@@ -547,7 +547,6 @@ public:
SelectRequest() : FileRequest(SELECT_REQUEST) {}
uint8 event;
uint32 ref;
selectsync* sync;
};
@@ -1394,7 +1393,6 @@ public:
NotifySelectEventRequest() : Request(NOTIFY_SELECT_EVENT_REQUEST) {}
selectsync* sync;
uint32 ref;
uint8 event;
bool unspecifiedEvent;
};