kernel: More lock fixes around pipes...
This commit is contained in:
parent
63fbbec928
commit
e07291a0b1
@ -97,13 +97,12 @@ size_t ring_buffer_read(ring_buffer_t * ring_buffer, size_t size, uint8_t * buff
|
||||
}
|
||||
wakeup_queue(ring_buffer->wait_queue_writers);
|
||||
if (collected == 0) {
|
||||
if (sleep_on_unlocking(ring_buffer->wait_queue_readers, &ring_buffer->lock)) {
|
||||
if (ring_buffer->internal_stop) {
|
||||
ring_buffer->internal_stop = 0;
|
||||
} else {
|
||||
if (!collected) return -ERESTARTSYS;
|
||||
spin_unlock(ring_buffer->lock);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
if (sleep_on_unlocking(ring_buffer->wait_queue_readers, &ring_buffer->lock)) {
|
||||
return -ERESTARTSYS;
|
||||
}
|
||||
} else {
|
||||
spin_unlock(ring_buffer->lock);
|
||||
@ -132,11 +131,10 @@ size_t ring_buffer_write(ring_buffer_t * ring_buffer, size_t size, uint8_t * buf
|
||||
break;
|
||||
}
|
||||
if (sleep_on_unlocking(ring_buffer->wait_queue_writers, &ring_buffer->lock)) {
|
||||
if (ring_buffer->internal_stop) {
|
||||
ring_buffer->internal_stop = 0;
|
||||
} else {
|
||||
if (!written) return -ERESTARTSYS;
|
||||
break;
|
||||
}
|
||||
if (ring_buffer->internal_stop) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@ -198,7 +196,7 @@ void ring_buffer_destroy(ring_buffer_t * ring_buffer) {
|
||||
|
||||
void ring_buffer_interrupt(ring_buffer_t * ring_buffer) {
|
||||
ring_buffer->internal_stop = 1;
|
||||
wakeup_queue_interrupted(ring_buffer->wait_queue_readers);
|
||||
wakeup_queue_interrupted(ring_buffer->wait_queue_writers);
|
||||
wakeup_queue(ring_buffer->wait_queue_readers);
|
||||
wakeup_queue(ring_buffer->wait_queue_writers);
|
||||
}
|
||||
|
||||
|
@ -57,15 +57,18 @@ static ssize_t write_unixpipe(fs_node_t * node, off_t offset, size_t size, uint8
|
||||
static void close_read_pipe(fs_node_t * node) {
|
||||
struct unix_pipe * self = node->device;
|
||||
|
||||
spin_lock(self->buffer->lock);
|
||||
self->read_closed = 1;
|
||||
if (!self->write_closed) {
|
||||
ring_buffer_interrupt(self->buffer);
|
||||
}
|
||||
spin_unlock(self->buffer->lock);
|
||||
}
|
||||
|
||||
static void close_write_pipe(fs_node_t * node) {
|
||||
struct unix_pipe * self = node->device;
|
||||
|
||||
spin_lock(self->buffer->lock);
|
||||
self->write_closed = 1;
|
||||
if (!self->read_closed) {
|
||||
ring_buffer_interrupt(self->buffer);
|
||||
@ -73,6 +76,7 @@ static void close_write_pipe(fs_node_t * node) {
|
||||
ring_buffer_alert_waiters(self->buffer);
|
||||
}
|
||||
}
|
||||
spin_unlock(self->buffer->lock);
|
||||
}
|
||||
|
||||
static int check_pipe(fs_node_t * node) {
|
||||
|
Loading…
Reference in New Issue
Block a user