* Added a small private API (<fs/select_sync_pool.h>) to support FSs
and drivers that need to provide special select() support with managing select notification information. * Renamed vfs_select.c to *.cpp and fixed the resulting C++ compiler errors. Added tracing macros. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@11886 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2005, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _KERNEL_SELECT_SYNC_POOL_H
|
||||||
|
#define _KERNEL_SELECT_SYNC_POOL_H
|
||||||
|
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
struct selectsync;
|
||||||
|
typedef struct select_sync_pool select_sync_pool;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
status_t add_select_sync_pool_entry(select_sync_pool **pool, selectsync *sync,
|
||||||
|
uint32 ref, uint8 event);
|
||||||
|
status_t remove_select_sync_pool_entry(select_sync_pool **pool,
|
||||||
|
selectsync *sync, uint8 event);
|
||||||
|
void notify_select_event_pool(select_sync_pool *pool, uint8 event);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _KERNEL_SELECT_SYNC_POOL_H
|
||||||
@@ -12,7 +12,7 @@ KernelMergeObject kernel_fs.o :
|
|||||||
pipefs.cpp
|
pipefs.cpp
|
||||||
fd.c
|
fd.c
|
||||||
vfs.cpp
|
vfs.cpp
|
||||||
vfs_select.c
|
vfs_select.cpp
|
||||||
message.c
|
message.c
|
||||||
node_monitor.cpp
|
node_monitor.cpp
|
||||||
IOScheduler.cpp
|
IOScheduler.cpp
|
||||||
|
|||||||
@@ -7,13 +7,23 @@
|
|||||||
#include <vfs.h>
|
#include <vfs.h>
|
||||||
#include <fd.h>
|
#include <fd.h>
|
||||||
#include <syscalls.h>
|
#include <syscalls.h>
|
||||||
|
#include <fs/select_sync_pool.h>
|
||||||
#include "vfs_select.h"
|
#include "vfs_select.h"
|
||||||
|
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <malloc.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
//#define TRACE_VFS_SELECT
|
||||||
|
#ifdef TRACE_VFS_SELECT
|
||||||
|
# define PRINT(x) dprintf x
|
||||||
|
# define FUNCTION(x) dprintf x
|
||||||
|
#else
|
||||||
|
# define PRINT(x) ;
|
||||||
|
# define FUNCTION(x) ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/** Selects all events in the mask on the specified file descriptor */
|
/** Selects all events in the mask on the specified file descriptor */
|
||||||
|
|
||||||
@@ -71,6 +81,9 @@ common_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet,
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
FUNCTION(("common_select(%d, %p, %p, %p, %lld, %p, %d)\n", numfds, readSet,
|
||||||
|
writeSet, errorSet, timeout, sigMask, kernel));
|
||||||
|
|
||||||
// ToDo: set sigMask to make pselect() functional different from select()
|
// ToDo: set sigMask to make pselect() functional different from select()
|
||||||
|
|
||||||
// check if fds are valid before doing anything
|
// check if fds are valid before doing anything
|
||||||
@@ -93,7 +106,7 @@ common_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet,
|
|||||||
|
|
||||||
set_sem_owner(sync.sem, B_SYSTEM_TEAM);
|
set_sem_owner(sync.sem, B_SYSTEM_TEAM);
|
||||||
|
|
||||||
sync.set = malloc(sizeof(select_info) * numfds);
|
sync.set = (select_info*)malloc(sizeof(select_info) * numfds);
|
||||||
if (sync.set == NULL) {
|
if (sync.set == NULL) {
|
||||||
delete_sem(sync.sem);
|
delete_sem(sync.sem);
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
@@ -190,7 +203,7 @@ common_poll(struct pollfd *fds, nfds_t numfds, bigtime_t timeout, bool kernel)
|
|||||||
|
|
||||||
set_sem_owner(sync.sem, B_SYSTEM_TEAM);
|
set_sem_owner(sync.sem, B_SYSTEM_TEAM);
|
||||||
|
|
||||||
sync.set = malloc(numfds * sizeof(select_info));
|
sync.set = (select_info*)malloc(numfds * sizeof(select_info));
|
||||||
if (sync.set == NULL) {
|
if (sync.set == NULL) {
|
||||||
delete_sem(sync.sem);
|
delete_sem(sync.sem);
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
@@ -269,6 +282,8 @@ notify_select_event(struct selectsync *_sync, uint32 ref, uint8 event)
|
|||||||
{
|
{
|
||||||
select_sync *sync = (select_sync *)_sync;
|
select_sync *sync = (select_sync *)_sync;
|
||||||
|
|
||||||
|
FUNCTION(("notify_select_event(%p, %lu, %u)\n", _sync, ref, event));
|
||||||
|
|
||||||
if (sync == NULL
|
if (sync == NULL
|
||||||
|| sync->sem < B_OK
|
|| sync->sem < B_OK
|
||||||
|| ref > sync->count)
|
|| ref > sync->count)
|
||||||
@@ -285,6 +300,128 @@ notify_select_event(struct selectsync *_sync, uint32 ref, uint8 event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
// currently private select sync pool functions exported to the kernel
|
||||||
|
|
||||||
|
|
||||||
|
static select_sync_pool_entry *
|
||||||
|
find_select_sync_pool_entry(select_sync_pool *pool, selectsync *sync,
|
||||||
|
uint32 ref)
|
||||||
|
{
|
||||||
|
for (SelectSyncPoolEntryList::Iterator it = pool->entries.GetIterator();
|
||||||
|
it.HasNext();) {
|
||||||
|
select_sync_pool_entry *entry = it.Next();
|
||||||
|
if (entry->sync == sync && entry->ref == ref)
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static status_t
|
||||||
|
add_select_sync_pool_entry(select_sync_pool *pool, selectsync *sync,
|
||||||
|
uint32 ref, uint8 event)
|
||||||
|
{
|
||||||
|
// check, whether the entry does already exist
|
||||||
|
select_sync_pool_entry *entry = find_select_sync_pool_entry(pool, sync,
|
||||||
|
ref);
|
||||||
|
if (!entry) {
|
||||||
|
entry = new(nothrow) select_sync_pool_entry;
|
||||||
|
if (!entry)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
entry->sync = sync;
|
||||||
|
entry->ref = ref;
|
||||||
|
entry->events = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry->events |= SELECT_FLAG(event);
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
add_select_sync_pool_entry(select_sync_pool **_pool, selectsync *sync,
|
||||||
|
uint32 ref, uint8 event)
|
||||||
|
{
|
||||||
|
// create the pool, if necessary
|
||||||
|
select_sync_pool *pool = *_pool;
|
||||||
|
if (!pool) {
|
||||||
|
pool = new(nothrow) select_sync_pool;
|
||||||
|
if (!pool)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
*_pool = pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the entry
|
||||||
|
status_t error = add_select_sync_pool_entry(pool, sync, ref, event);
|
||||||
|
|
||||||
|
// cleanup
|
||||||
|
if (pool->entries.IsEmpty()) {
|
||||||
|
delete pool;
|
||||||
|
*_pool = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
remove_select_sync_pool_entry(select_sync_pool **_pool, selectsync *sync,
|
||||||
|
uint8 event)
|
||||||
|
{
|
||||||
|
select_sync_pool *pool = *_pool;
|
||||||
|
if (!pool)
|
||||||
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
|
// clear the event flag of the concerned entries
|
||||||
|
bool found = false;
|
||||||
|
for (SelectSyncPoolEntryList::Iterator it = pool->entries.GetIterator();
|
||||||
|
it.HasNext();) {
|
||||||
|
select_sync_pool_entry *entry = it.Next();
|
||||||
|
if (entry->sync == sync) {
|
||||||
|
found = true;
|
||||||
|
entry->events &= ~SELECT_FLAG(event);
|
||||||
|
|
||||||
|
// remove the entry, if no longer needed
|
||||||
|
if (entry->events == 0) {
|
||||||
|
it.Remove();
|
||||||
|
delete entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
return B_ENTRY_NOT_FOUND;
|
||||||
|
|
||||||
|
// delete the pool, if no longer needed
|
||||||
|
if (pool->entries.IsEmpty()) {
|
||||||
|
delete pool;
|
||||||
|
*_pool = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
notify_select_event_pool(select_sync_pool *pool, uint8 event)
|
||||||
|
{
|
||||||
|
if (!pool)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (SelectSyncPoolEntryList::Iterator it = pool->entries.GetIterator();
|
||||||
|
it.HasNext();) {
|
||||||
|
select_sync_pool_entry *entry = it.Next();
|
||||||
|
if (entry->events & SELECT_FLAG(event))
|
||||||
|
notify_select_event(entry->sync, entry->ref, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
// Functions called from the POSIX layer
|
// Functions called from the POSIX layer
|
||||||
|
|
||||||
@@ -325,7 +462,7 @@ _user_select(int numfds, fd_set *userReadSet, fd_set *userWriteSet, fd_set *user
|
|||||||
// copy parameters
|
// copy parameters
|
||||||
|
|
||||||
if (userReadSet != NULL) {
|
if (userReadSet != NULL) {
|
||||||
readSet = malloc(bytes);
|
readSet = (fd_set *)malloc(bytes);
|
||||||
if (readSet == NULL)
|
if (readSet == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
@@ -336,7 +473,7 @@ _user_select(int numfds, fd_set *userReadSet, fd_set *userWriteSet, fd_set *user
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (userWriteSet != NULL) {
|
if (userWriteSet != NULL) {
|
||||||
writeSet = malloc(bytes);
|
writeSet = (fd_set *)malloc(bytes);
|
||||||
if (writeSet == NULL) {
|
if (writeSet == NULL) {
|
||||||
result = B_NO_MEMORY;
|
result = B_NO_MEMORY;
|
||||||
goto err;
|
goto err;
|
||||||
@@ -348,7 +485,7 @@ _user_select(int numfds, fd_set *userReadSet, fd_set *userWriteSet, fd_set *user
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (userErrorSet != NULL) {
|
if (userErrorSet != NULL) {
|
||||||
errorSet = malloc(bytes);
|
errorSet = (fd_set *)malloc(bytes);
|
||||||
if (errorSet == NULL) {
|
if (errorSet == NULL) {
|
||||||
result = B_NO_MEMORY;
|
result = B_NO_MEMORY;
|
||||||
goto err;
|
goto err;
|
||||||
@@ -396,7 +533,7 @@ _user_poll(struct pollfd *userfds, int numfds, bigtime_t timeout)
|
|||||||
|
|
||||||
// copy parameters
|
// copy parameters
|
||||||
|
|
||||||
fds = malloc(bytes = numfds * sizeof(struct pollfd));
|
fds = (struct pollfd *)malloc(bytes = numfds * sizeof(struct pollfd));
|
||||||
if (fds == NULL)
|
if (fds == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
@@ -5,8 +5,8 @@
|
|||||||
#ifndef VFS_SELECT_H
|
#ifndef VFS_SELECT_H
|
||||||
#define VFS_SELECT_H
|
#define VFS_SELECT_H
|
||||||
|
|
||||||
|
|
||||||
#include <Select.h>
|
#include <Select.h>
|
||||||
|
#include <util/DoublyLinkedList.h>
|
||||||
|
|
||||||
|
|
||||||
typedef struct select_info {
|
typedef struct select_info {
|
||||||
@@ -22,4 +22,17 @@ typedef struct select_sync {
|
|||||||
|
|
||||||
#define SELECT_FLAG(type) (1L << (type - 1))
|
#define SELECT_FLAG(type) (1L << (type - 1))
|
||||||
|
|
||||||
|
struct select_sync_pool_entry
|
||||||
|
: DoublyLinkedListLinkImpl<select_sync_pool_entry> {
|
||||||
|
selectsync *sync;
|
||||||
|
uint32 ref;
|
||||||
|
uint16 events;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef DoublyLinkedList<select_sync_pool_entry> SelectSyncPoolEntryList;
|
||||||
|
|
||||||
|
struct select_sync_pool {
|
||||||
|
SelectSyncPoolEntryList entries;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* VFS_SELECT_H */
|
#endif /* VFS_SELECT_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user