32 memset(mbuf, 0,
sizeof(*mbuf));
35 ret = posix_memalign((
void*)&bptr, getpagesize(), size);
37 dbg_err(
"could not allocate buffer space");
43 dbg_err(
"could not create photon buffer");
47 mbuf->p_size = p_size;
48 mbuf->m_size = p_size - p_offset - p_hsize;
49 mbuf->p_offset = p_offset;
50 mbuf->p_hsize = p_hsize;
51 mbuf->p_count = (int)(size / mbuf->p_size);
56 dbg_err(
"could not allocate buf entries");
60 for (i = 0; i < mbuf->p_count; i++) {
61 mbuf->entries[i].base = (
void*)((mbuf->db)->bint.buf.addr + (i * p_size));
62 mbuf->entries[i].hptr = (
void*)((mbuf->db)->bint.buf.addr + (i * p_size) + p_offset);
63 mbuf->entries[i].mptr = (
void*)((mbuf->db)->bint.buf.addr + (i * p_size) + p_offset + p_hsize);
64 mbuf->entries[i].empty =
true;
70 pthread_mutex_init(&mbuf->buf_lock, NULL);
95 pthread_mutex_lock(&mbuf->buf_lock);
97 while (mbuf->entries[mbuf->s_index].empty ==
false) {
99 if (mbuf->s_index == mbuf->p_count)
102 mbuf->entries[mbuf->s_index].empty =
false;
104 pthread_mutex_unlock(&mbuf->buf_lock);
106 *ind = mbuf->s_index;
107 return &mbuf->entries[mbuf->s_index];
111 if ((ind < 0) || (ind >= mbuf->p_count)) {
112 dbg_err(
"index %d is out of bounds", ind);
116 mbuf->entries[ind].empty =
true;
photonBufferHandle photon_buffer_create(void *addr, uint64_t size, int flags)
int photon_msgbuffer_free(photonMsgBuf mbuf)
int photon_msgbuffer_free_entry(photonMsgBuf mbuf, int ind)
void photon_buffer_free(photonBufferHandle buf)
photon_mbe * photon_msgbuffer_get_entry(photonMsgBuf mbuf, int *ind)
#define PHOTON_ERROR
Error code, general error.
#define PHOTON_OK
Photon success code.
photonMsgBuf photon_msgbuffer_new(uint64_t size, uint64_t p_size, int p_offset, int p_hsize)
Constants and macros for interacting with the library. Only this header is needed to use the Photon A...