Ejemplo n.º 1
0
/**
 * scif_rb_write - Write a message to the RB
 * @rb: ring buffer
 * @msg: buffer to send the message.  Must be at least size bytes long
 * @size: the size (in bytes) to be copied to the RB
 *
 * This API does not block if there isn't enough space in the RB.
 * Returns: 0 on success or -ENOMEM on failure
 */
int scif_rb_write(struct scif_rb *rb, void *msg, u32 size)
{
	void *header;

	if (scif_rb_space(rb) < size)
		return -ENOMEM;
	header = rb->rb_base + rb->current_write_offset;
	memcpy_torb(rb, header, msg, size);
	/*
	 * Wait until scif_rb_commit(). Update the local ring
	 * buffer data, not the shared data until commit.
	 */
	rb->current_write_offset =
		(rb->current_write_offset + size) & (rb->size - 1);
	return 0;
}
Ejemplo n.º 2
0
/**
 * micscif_rb_write - Write one package to the given ring buffer
 * @rb - The RingBuffer context
 * @msg - The package to be put in the ring buffer
 * @size - the size (in bytes) you want to copy
 *
 * This API does not block if there isn't enough space in the RB.
 */
int micscif_rb_write(struct micscif_rb *rb,
			void *msg,
			uint32_t size)
{
	void *header;
	int ret = 0;
	if ((uint32_t)micscif_rb_space(rb) < size)
		return -ENOMEM;
	header = (char*)rb->rb_base + rb->current_write_offset;
	ret = memcpy_torb(rb, header, msg, size);
	if (!ret) {
		/*
		 * XPU_RACE_CONDITION: Don't do anything here!
		 * Wait until micscif_rb_commit()
		 * Update the local ring buffer data, not the shared data until commit.
		 */
		rb->old_current_write_offset = rb->current_write_offset;
		rb->current_write_offset = (rb->current_write_offset + size) & (rb->size - 1);
	}
	return ret;
}