shm: Add ability to add uint64 tags on buffers

This commit is contained in:
Sjoerd Simons 2011-08-07 16:36:32 +02:00
parent acdd2c20f7
commit 52a7d015cd
2 changed files with 29 additions and 3 deletions

View file

@ -78,7 +78,6 @@ enum
};
typedef struct _ShmArea ShmArea;
typedef struct _ShmBuffer ShmBuffer;
struct _ShmArea
{
@ -112,6 +111,8 @@ struct _ShmBuffer
int num_clients;
int clients[0];
uint64_t tag;
};
@ -542,7 +543,7 @@ sp_writer_free_block (ShmBlock * block)
/* Returns the number of client this has successfully been sent to */
int
sp_writer_send_buf (ShmPipe * self, char *buf, size_t size)
sp_writer_send_buf (ShmPipe * self, char *buf, size_t size, uint64_t tag)
{
ShmArea *area = NULL;
unsigned long offset = 0;
@ -577,6 +578,7 @@ sp_writer_send_buf (ShmPipe * self, char *buf, size_t size)
sb->size = size;
sb->num_clients = self->num_clients;
sb->ablock = ablock;
sb->tag = tag;
for (client = self->clients; client; client = client->next) {
struct CommandBuffer cb = { 0 };
@ -892,3 +894,21 @@ sp_writer_get_path (ShmPipe * pipe)
{
return pipe->socket_path;
}
ShmBuffer *
sp_writer_get_pending_buffers (ShmPipe * self)
{
return self->buffers;
}
ShmBuffer *
sp_writer_get_next_buffer (ShmBuffer * buffer)
{
return buffer->next;
}
uint64_t
sp_writer_buf_get_tag (ShmBuffer * buffer)
{
return buffer->tag;
}

View file

@ -63,6 +63,7 @@
#define __SHMPIPE_H__
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@ -75,6 +76,7 @@ extern "C" {
typedef struct _ShmClient ShmClient;
typedef struct _ShmPipe ShmPipe;
typedef struct _ShmBlock ShmBlock;
typedef struct _ShmBuffer ShmBuffer;
ShmPipe *sp_writer_create (const char *path, size_t size, mode_t perms);
const char *sp_writer_get_path (ShmPipe *pipe);
@ -90,7 +92,7 @@ int sp_writer_get_client_fd (ShmClient * client);
ShmBlock *sp_writer_alloc_block (ShmPipe * self, size_t size);
void sp_writer_free_block (ShmBlock *block);
int sp_writer_send_buf (ShmPipe * self, char *buf, size_t size);
int sp_writer_send_buf (ShmPipe * self, char *buf, size_t size, uint64_t tag);
char *sp_writer_block_get_buf (ShmBlock *block);
ShmPipe *sp_writer_block_get_pipe (ShmBlock *block);
@ -104,6 +106,10 @@ ShmPipe *sp_client_open (const char *path);
long int sp_client_recv (ShmPipe * self, char **buf);
int sp_client_recv_finish (ShmPipe * self, char *buf);
ShmBuffer *sp_writer_get_pending_buffers (ShmPipe * self);
ShmBuffer *sp_writer_get_next_buffer (ShmBuffer * buffer);
uint64_t sp_writer_buf_get_tag (ShmBuffer * buffer);
#ifdef __cplusplus
}
#endif