Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 354024
b: refs/heads/master
c: f8f76e9
h: refs/heads/master
v: v3
  • Loading branch information
H Hartley Sweeten authored and Greg Kroah-Hartman committed Jan 18, 2013
1 parent d14434e commit 1d35039
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 33 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 61c9fb0eb08bc9b7164a6181b0062d9959406a34
refs/heads/master: f8f76e909b8cc6696071e69cf4be07714c95bcb4
52 changes: 21 additions & 31 deletions trunk/drivers/staging/comedi/comedi_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,56 +159,46 @@ void comedi_buf_reset(struct comedi_async *async)
async->events = 0;
}

unsigned int comedi_buf_write_n_available(struct comedi_async *async)
static unsigned int comedi_buf_write_n_available(struct comedi_async *async)
{
unsigned int free_end;
unsigned int nbytes;
unsigned int free_end = async->buf_read_count + async->prealloc_bufsz;

if (async == NULL)
return 0;
return free_end - async->buf_write_alloc_count;
}

free_end = async->buf_read_count + async->prealloc_bufsz;
nbytes = free_end - async->buf_write_alloc_count;
nbytes -= nbytes % bytes_per_sample(async->subdevice);
/* barrier insures the read of buf_read_count in this
query occurs before any following writes to the buffer which
might be based on the return value from this query.
static unsigned int __comedi_buf_write_alloc(struct comedi_async *async,
unsigned int nbytes,
int strict)
{
unsigned int available = comedi_buf_write_n_available(async);

if (nbytes > available)
nbytes = strict ? 0 : available;

async->buf_write_alloc_count += nbytes;

/*
* ensure the async buffer 'counts' are read and updated
* before we write data to the write-alloc'ed buffer space
*/
smp_mb();

return nbytes;
}

/* allocates chunk for the writer from free buffer space */
unsigned int comedi_buf_write_alloc(struct comedi_async *async,
unsigned int nbytes)
{
unsigned int free_end = async->buf_read_count + async->prealloc_bufsz;

if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0)
nbytes = free_end - async->buf_write_alloc_count;

async->buf_write_alloc_count += nbytes;
/* barrier insures the read of buf_read_count above occurs before
we write data to the write-alloc'ed buffer space */
smp_mb();
return nbytes;
return __comedi_buf_write_alloc(async, nbytes, 0);
}
EXPORT_SYMBOL(comedi_buf_write_alloc);

/* allocates nothing unless it can completely fulfill the request */
unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async,
unsigned int nbytes)
{
unsigned int free_end = async->buf_read_count + async->prealloc_bufsz;

if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0)
nbytes = 0;

async->buf_write_alloc_count += nbytes;
/* barrier insures the read of buf_read_count above occurs before
we write data to the write-alloc'ed buffer space */
smp_mb();
return nbytes;
return __comedi_buf_write_alloc(async, nbytes, 1);
}

/* munging is applied to data by core as it passes between user
Expand Down
1 change: 0 additions & 1 deletion trunk/drivers/staging/comedi/comedidev.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@ comedi_to_usb_interface(struct comedi_device *dev)
int comedi_buf_put(struct comedi_async *async, short x);
int comedi_buf_get(struct comedi_async *async, short *x);

unsigned int comedi_buf_write_n_available(struct comedi_async *async);
unsigned int comedi_buf_write_alloc(struct comedi_async *async,
unsigned int nbytes);
unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async,
Expand Down

0 comments on commit 1d35039

Please sign in to comment.