Properly implemented select/deselect. Got it a bit wrong last time, of course only one event at the time is selected/deselected. Also uses the select_sync_pool now, thanks for the hint Ingo.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12279 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz
2005-04-09 18:41:53 +00:00
parent 52e1c3c044
commit bd15cefa12
+14 -38
View File
@@ -12,6 +12,7 @@
#include <cbuf.h> #include <cbuf.h>
#include <vfs.h> #include <vfs.h>
#include <vfs_select.h> #include <vfs_select.h>
#include <select_sync_pool.h>
#include <debug.h> #include <debug.h>
#include <khash.h> #include <khash.h>
#include <lock.h> #include <lock.h>
@@ -161,7 +162,7 @@ class Inode {
int32 ReaderCount() const { return fReaderCount; } int32 ReaderCount() const { return fReaderCount; }
int32 WriterCount() const { return fWriterCount; } int32 WriterCount() const { return fWriterCount; }
status_t Select(uint16 events, uint32 ref, selectsync *sync); status_t Select(uint8 event, uint32 ref, selectsync *sync);
status_t Deselect(uint8 event, selectsync *sync); status_t Deselect(uint8 event, selectsync *sync);
static int32 HashNextOffset(); static int32 HashNextOffset();
@@ -189,9 +190,7 @@ class Inode {
int32 fReaderCount; int32 fReaderCount;
int32 fWriterCount; int32 fWriterCount;
select_sync *fSelectSync; select_sync_pool *fSelectSyncPool;
uint16 fSelectEvents;
uint32 fSelectRef;
}; };
@@ -463,9 +462,7 @@ Inode::Inode(Volume *volume, Inode *parent, const char *name, int32 type)
fBufferChain(NULL), fBufferChain(NULL),
fReaderCount(0), fReaderCount(0),
fWriterCount(0), fWriterCount(0),
fSelectSync(NULL), fSelectSyncPool(NULL)
fSelectEvents(0),
fSelectRef(0)
{ {
fName = strdup(name); fName = strdup(name);
if (fName == NULL) if (fName == NULL)
@@ -578,10 +575,8 @@ void
Inode::MayReleaseWriter() Inode::MayReleaseWriter()
{ {
if (BytesInChain() < PIPEFS_MAX_BUFFER_SIZE) { if (BytesInChain() < PIPEFS_MAX_BUFFER_SIZE) {
if (fSelectSync && fSelectEvents & SELECT_FLAG(B_SELECT_WRITE)) { if (fSelectSyncPool)
fSelectSync->set[fSelectRef].events |= SELECT_FLAG(B_SELECT_WRITE); notify_select_event_pool(fSelectSyncPool, B_SELECT_WRITE);
notify_select_event((selectsync *)fSelectSync, fSelectRef, B_SELECT_WRITE);
}
release_sem(fWriteLock); release_sem(fWriteLock);
} }
@@ -618,10 +613,8 @@ Inode::FillPendingRequests()
MayReleaseWriter(); MayReleaseWriter();
} }
if (fSelectSync && fSelectEvents & SELECT_FLAG(B_SELECT_READ)) { if (fSelectSyncPool)
fSelectSync->set[fSelectRef].events |= SELECT_FLAG(B_SELECT_READ); notify_select_event_pool(fSelectSyncPool, B_SELECT_READ);
notify_select_event((selectsync *)fSelectSync, fSelectRef, B_SELECT_READ);
}
} }
@@ -784,28 +777,14 @@ Inode::compare_func(void *_node, const void *_key)
status_t status_t
Inode::Select(uint16 events, uint32 ref, selectsync *_sync) Inode::Select(uint8 event, uint32 ref, selectsync *sync)
{ {
// TODO: What about multiple selects? if (add_select_sync_pool_entry(&fSelectSyncPool, sync, ref, event) != B_OK)
fSelectSync = (select_sync *)_sync;
if (!fSelectSync)
return B_ERROR; return B_ERROR;
fSelectEvents = events; if ((event == B_SELECT_READ && BytesInChain() > 0)
fSelectRef = ref; || (event == B_SELECT_WRITE && BytesInChain() < PIPEFS_MAX_BUFFER_SIZE))
return notify_select_event(sync, ref, event);
uint8 event = 0;
if (events & SELECT_FLAG(B_SELECT_READ) && BytesInChain() > 0) {
fSelectSync->set[fSelectRef].events |= SELECT_FLAG(B_SELECT_READ);
event = B_SELECT_READ;
}
if (events & SELECT_FLAG(B_SELECT_WRITE) && BytesInChain() < PIPEFS_MAX_BUFFER_SIZE) {
fSelectSync->set[fSelectRef].events |= SELECT_FLAG(B_SELECT_WRITE);
event = B_SELECT_WRITE;
}
if (event != 0)
return notify_select_event((selectsync *)fSelectSync, fSelectRef, event);
return B_OK; return B_OK;
} }
@@ -814,10 +793,7 @@ Inode::Select(uint16 events, uint32 ref, selectsync *_sync)
status_t status_t
Inode::Deselect(uint8 event, selectsync *sync) Inode::Deselect(uint8 event, selectsync *sync)
{ {
// TODO: What about multiple selects? remove_select_sync_pool_entry(&fSelectSyncPool, sync, event);
fSelectSync = NULL;
fSelectEvents = 0;
fSelectRef = 0;
return B_OK; return B_OK;
} }