void lib_ring_buffer_switch_remote(struct lib_ring_buffer *buf);
extern
void lib_ring_buffer_switch_remote_empty(struct lib_ring_buffer *buf);
+extern
+void lib_ring_buffer_clear(struct lib_ring_buffer *buf);
/* Buffer write helpers */
consumed_new) != consumed_old));
}
+/*
+ * Move consumed position to the beginning of subbuffer in which the
+ * write offset is.
+ */
+static inline
+void lib_ring_buffer_clear_reader(struct lib_ring_buffer *buf,
+ struct channel *chan)
+{
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
+ unsigned long offset, consumed_old, consumed_new;
+
+ do {
+ offset = v_read(config, &buf->offset);
+ consumed_old = atomic_long_read(&buf->consumed);
+ if (unlikely(subbuf_trunc(offset, chan)
+ - subbuf_trunc(consumed_old, chan)
+ > 0))
+ consumed_new = subbuf_trunc(offset, chan);
+ else
+ return;
+ } while (unlikely(atomic_long_cmpxchg(&buf->consumed, consumed_old,
+ consumed_new) != consumed_old));
+}
+
static inline
int lib_ring_buffer_pending_data(const struct lib_ring_buffer_config *config,
struct lib_ring_buffer *buf,
}
EXPORT_SYMBOL_GPL(lib_ring_buffer_switch_remote_empty);
+void lib_ring_buffer_clear(struct lib_ring_buffer *buf)
+{
+ struct lib_ring_buffer_backend *bufb = &buf->backend;
+ struct channel *chan = bufb->chan;
+
+ lib_ring_buffer_switch_remote(buf);
+ lib_ring_buffer_clear_reader(buf, chan);
+}
+EXPORT_SYMBOL_GPL(lib_ring_buffer_clear);
+
/*
* Returns :
* 0 if ok
case RING_BUFFER_FLUSH_EMPTY:
lib_ring_buffer_switch_remote_empty(buf);
return 0;
+ case RING_BUFFER_CLEAR:
+ lib_ring_buffer_clear(buf);
+ return 0;
default:
return -ENOIOCTLCMD;
}
case RING_BUFFER_COMPAT_FLUSH_EMPTY:
lib_ring_buffer_switch_remote_empty(buf);
return 0;
+ case RING_BUFFER_COMPAT_CLEAR:
+ lib_ring_buffer_clear(buf);
+ return 0;
default:
return -ENOIOCTLCMD;
}
* so it can be read again.
*/
#define RING_BUFFER_METADATA_CACHE_DUMP _IO(0xF6, 0x10)
+/* Clear ring buffer content. */
+#define RING_BUFFER_CLEAR _IO(0xF6, 0x11)
#ifdef CONFIG_COMPAT
/* Get a snapshot of the current ring buffer producer and consumer positions */
/* Flush the current sub-buffer, even if empty. */
#define RING_BUFFER_COMPAT_FLUSH_EMPTY \
RING_BUFFER_FLUSH_EMPTY
+/* Clear ring buffer content. */
+#define RING_BUFFER_COMPAT_CLEAR \
+ RING_BUFFER_CLEAR
#endif /* CONFIG_COMPAT */
#endif /* _LIB_RING_BUFFER_VFS_H */