]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - include/linux/pipe_fs_i.h
Merge branch 'parisc-5.5-1' of git://git.kernel.org/pub/scm/linux/kernel/git/deller...
[linux.git] / include / linux / pipe_fs_i.h
index 5c626fdc10dbd27d6f87f290cf5dbd50d0244528..44f2245debda4f839e85fdbfdc748dacc74c1c4c 100644 (file)
@@ -30,9 +30,10 @@ struct pipe_buffer {
  *     struct pipe_inode_info - a linux kernel pipe
  *     @mutex: mutex protecting the whole thing
  *     @wait: reader/writer wait point in case of empty/full pipe
- *     @nrbufs: the number of non-empty pipe buffers in this pipe
- *     @buffers: total number of buffers (should be a power of 2)
- *     @curbuf: the current pipe buffer entry
+ *     @head: The point of buffer production
+ *     @tail: The point of buffer consumption
+ *     @max_usage: The maximum number of slots that may be used in the ring
+ *     @ring_size: total number of buffers (should be a power of 2)
  *     @tmp_page: cached released page
  *     @readers: number of current readers of this pipe
  *     @writers: number of current writers of this pipe
@@ -48,7 +49,10 @@ struct pipe_buffer {
 struct pipe_inode_info {
        struct mutex mutex;
        wait_queue_head_t wait;
-       unsigned int nrbufs, curbuf, buffers;
+       unsigned int head;
+       unsigned int tail;
+       unsigned int max_usage;
+       unsigned int ring_size;
        unsigned int readers;
        unsigned int writers;
        unsigned int files;
@@ -104,6 +108,58 @@ struct pipe_buf_operations {
        bool (*get)(struct pipe_inode_info *, struct pipe_buffer *);
 };
 
+/**
+ * pipe_empty - Return true if the pipe is empty
+ * @head: The pipe ring head pointer
+ * @tail: The pipe ring tail pointer
+ */
+static inline bool pipe_empty(unsigned int head, unsigned int tail)
+{
+       return head == tail;
+}
+
+/**
+ * pipe_occupancy - Return number of slots used in the pipe
+ * @head: The pipe ring head pointer
+ * @tail: The pipe ring tail pointer
+ */
+static inline unsigned int pipe_occupancy(unsigned int head, unsigned int tail)
+{
+       return head - tail;
+}
+
+/**
+ * pipe_full - Return true if the pipe is full
+ * @head: The pipe ring head pointer
+ * @tail: The pipe ring tail pointer
+ * @limit: The maximum amount of slots available.
+ */
+static inline bool pipe_full(unsigned int head, unsigned int tail,
+                            unsigned int limit)
+{
+       return pipe_occupancy(head, tail) >= limit;
+}
+
+/**
+ * pipe_space_for_user - Return number of slots available to userspace
+ * @head: The pipe ring head pointer
+ * @tail: The pipe ring tail pointer
+ * @pipe: The pipe info structure
+ */
+static inline unsigned int pipe_space_for_user(unsigned int head, unsigned int tail,
+                                              struct pipe_inode_info *pipe)
+{
+       unsigned int p_occupancy, p_space;
+
+       p_occupancy = pipe_occupancy(head, tail);
+       if (p_occupancy >= pipe->max_usage)
+               return 0;
+       p_space = pipe->ring_size - p_occupancy;
+       if (p_space > pipe->max_usage)
+               p_space = pipe->max_usage;
+       return p_space;
+}
+
 /**
  * pipe_buf_get - get a reference to a pipe_buffer
  * @pipe:      the pipe that the buffer belongs to