Skip to content

Commit

Permalink
[PATCH] pipe.c/fifo.c code cleanups
Browse files Browse the repository at this point in the history
more code cleanups after the macro conversion:

 - standardize on 'struct pipe_inode_info *pipe' variable names
 - introduce 'pipe' temporaries to reduce mass inode->i_pipe dereferencing

Signed-off-by: Ingo Molnar <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Ingo Molnar authored and Jens Axboe committed Apr 11, 2006
1 parent 9aeedfc commit 923f4f2
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 101 deletions.
49 changes: 26 additions & 23 deletions fs/fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ static void wake_up_partner(struct inode* inode)

static int fifo_open(struct inode *inode, struct file *filp)
{
struct pipe_inode_info *pipe;
int ret;

mutex_lock(&inode->i_mutex);
if (!inode->i_pipe) {
pipe = inode->i_pipe;
if (!pipe) {
ret = -ENOMEM;
inode->i_pipe = alloc_pipe_info(inode);
if (!inode->i_pipe)
pipe = alloc_pipe_info(inode);
if (!pipe)
goto err_nocleanup;
inode->i_pipe = pipe;
}
filp->f_version = 0;

Expand All @@ -55,18 +58,18 @@ static int fifo_open(struct inode *inode, struct file *filp)
* opened, even when there is no process writing the FIFO.
*/
filp->f_op = &read_fifo_fops;
inode->i_pipe->r_counter++;
if (inode->i_pipe->readers++ == 0)
pipe->r_counter++;
if (pipe->readers++ == 0)
wake_up_partner(inode);

if (!inode->i_pipe->writers) {
if (!pipe->writers) {
if ((filp->f_flags & O_NONBLOCK)) {
/* suppress POLLHUP until we have
* seen a writer */
filp->f_version = inode->i_pipe->w_counter;
filp->f_version = pipe->w_counter;
} else
{
wait_for_partner(inode, &inode->i_pipe->w_counter);
wait_for_partner(inode, &pipe->w_counter);
if(signal_pending(current))
goto err_rd;
}
Expand All @@ -80,16 +83,16 @@ static int fifo_open(struct inode *inode, struct file *filp)
* errno=ENXIO when there is no process reading the FIFO.
*/
ret = -ENXIO;
if ((filp->f_flags & O_NONBLOCK) && !inode->i_pipe->readers)
if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
goto err;

filp->f_op = &write_fifo_fops;
inode->i_pipe->w_counter++;
if (!inode->i_pipe->writers++)
pipe->w_counter++;
if (!pipe->writers++)
wake_up_partner(inode);

if (!inode->i_pipe->readers) {
wait_for_partner(inode, &inode->i_pipe->r_counter);
if (!pipe->readers) {
wait_for_partner(inode, &pipe->r_counter);
if (signal_pending(current))
goto err_wr;
}
Expand All @@ -104,11 +107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
*/
filp->f_op = &rdwr_fifo_fops;

inode->i_pipe->readers++;
inode->i_pipe->writers++;
inode->i_pipe->r_counter++;
inode->i_pipe->w_counter++;
if (inode->i_pipe->readers == 1 || inode->i_pipe->writers == 1)
pipe->readers++;
pipe->writers++;
pipe->r_counter++;
pipe->w_counter++;
if (pipe->readers == 1 || pipe->writers == 1)
wake_up_partner(inode);
break;

Expand All @@ -122,19 +125,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
return 0;

err_rd:
if (!--inode->i_pipe->readers)
wake_up_interruptible(&inode->i_pipe->wait);
if (!--pipe->readers)
wake_up_interruptible(&pipe->wait);
ret = -ERESTARTSYS;
goto err;

err_wr:
if (!--inode->i_pipe->writers)
wake_up_interruptible(&inode->i_pipe->wait);
if (!--pipe->writers)
wake_up_interruptible(&pipe->wait);
ret = -ERESTARTSYS;
goto err;

err:
if (!inode->i_pipe->readers && !inode->i_pipe->writers)
if (!pipe->readers && !pipe->writers)
free_pipe_info(inode);

err_nocleanup:
Expand Down
Loading

0 comments on commit 923f4f2

Please sign in to comment.