17 #include <core/dependencies.h>
19 #ifdef POK_NEEDS_MIDDLEWARE
20 #ifdef POK_NEEDS_BUFFERS
24 #include <core/time.h>
25 #include <core/event.h>
26 #include <libc/string.h>
27 #include <middleware/buffer.h>
30 extern char pok_buffers_data[1024];
32 pok_ret_t pok_buffer_receive (
const pok_buffer_id_t
id,
33 const uint64_t timeout,
39 if (
id > POK_CONFIG_NB_BUFFERS)
41 return POK_ERRNO_EINVAL;
44 if (pok_buffers[
id].ready == FALSE)
46 return POK_ERRNO_EINVAL;
51 return POK_ERRNO_EINVAL;
54 pok_event_lock (pok_buffers[
id].lock);
56 while (pok_buffers[
id].empty == TRUE)
60 pok_event_unlock (pok_buffers[
id].lock);
64 ret = pok_event_wait (pok_buffers[
id].lock, timeout);
65 if (ret != POK_ERRNO_OK)
67 pok_event_unlock (pok_buffers[
id].lock);
73 memcpy (data, &pok_buffers_data[pok_buffers[
id].index + pok_buffers[
id].off_b], pok_buffers[
id].msgsize);
74 pok_buffers[id].off_b = (pok_buffers[id].off_b + pok_buffers[id].msgsize) % pok_buffers[
id].size;
75 if (pok_buffers[
id].off_b == pok_buffers[
id].off_e)
77 pok_buffers[id].empty = TRUE;
80 pok_buffers[id].full = FALSE;
82 *len = pok_buffers[id].msgsize;
84 pok_event_unlock (pok_buffers[
id].lock);
86 pok_event_broadcast (pok_buffers[
id].lock);