mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
pipe: fifo polling
This commit is contained in:
@@ -107,6 +107,7 @@ int vfs_poll(vnode_t* node, pollfd* fd){
|
|||||||
case TYPE_BLOCKDEV:
|
case TYPE_BLOCKDEV:
|
||||||
return devman_poll(node->st.st_rdev, fd);
|
return devman_poll(node->st.st_rdev, fd);
|
||||||
case TYPE_FIFO:
|
case TYPE_FIFO:
|
||||||
|
return pipe_poll(node->objdata, fd);
|
||||||
default:
|
default:
|
||||||
_panic("Unsupported poll", NULL);
|
_panic("Unsupported poll", NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <kernel/event.h>
|
#include <kernel/event.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <poll.h>
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
int lock;
|
int lock;
|
||||||
@@ -17,5 +18,6 @@ pipe_t* pipe_create(size_t buffsize);
|
|||||||
void pipe_drestroy(pipe_t* pipe);
|
void pipe_drestroy(pipe_t* pipe);
|
||||||
int pipe_read(pipe_t* pipe, void* buff, size_t count, int* error);
|
int pipe_read(pipe_t* pipe, void* buff, size_t count, int* error);
|
||||||
int pipe_write(pipe_t* pipe, void* buff, size_t count, int* error);
|
int pipe_write(pipe_t* pipe, void* buff, size_t count, int* error);
|
||||||
|
int pipe_poll(pipe_t* pipe, pollfd* fd);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -96,3 +96,31 @@ int pipe_write(pipe_t* pipe, void* buff, size_t count, int* error){
|
|||||||
|
|
||||||
return writec;
|
return writec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int pipe_poll(pipe_t* pipe, pollfd* fd){
|
||||||
|
|
||||||
|
spinlock_acquire(&pipe->lock);
|
||||||
|
|
||||||
|
if(fd->events & POLLIN){ // fd is reading
|
||||||
|
if(pipe->writers == 0)
|
||||||
|
fd->revents |= POLLHUP;
|
||||||
|
|
||||||
|
if(pipe->buff.write != pipe->buff.read)
|
||||||
|
fd->revents |= POLLIN;
|
||||||
|
|
||||||
|
}
|
||||||
|
else { // fd is writing
|
||||||
|
if(pipe->readers == 0)
|
||||||
|
fd->revents |= POLLERR;
|
||||||
|
else if(pipe->buff.write != pipe->buff.read + pipe->buff.size)
|
||||||
|
fd->revents |= POLLOUT;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
spinlock_release(&pipe->lock);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user