static const struct ipc_class *fifo_get_ipc_class(struct file *file __attribute__((__unused__)))
{
static const struct ipc_class fifo_ipc_class = {
+ .size = sizeof(struct fifo_ipc),
.get_hash = fifo_get_hash,
.is_suitable_ipc = fifo_is_suitable_ipc,
.free = NULL,
if (ipc)
goto link;
- ipc = xmalloc(sizeof(struct fifo_ipc));
- ipc->class = fifo_get_ipc_class(file);
- INIT_LIST_HEAD(&ipc->endpoints);
- INIT_LIST_HEAD(&ipc->ipcs);
+ ipc = new_ipc(fifo_get_ipc_class(file));
((struct fifo_ipc *)ipc)->ino = file->stat.st_ino;
hash = fifo_get_hash(file);
list_free(&ipc_table.tables[i], struct ipc, ipcs, free_ipc);
}
+struct ipc *new_ipc(const struct ipc_class *class)
+{
+ struct ipc *ipc = xcalloc(1, class->size);
+ ipc->class = class;
+ INIT_LIST_HEAD(&ipc->endpoints);
+ INIT_LIST_HEAD(&ipc->ipcs);
+ return ipc;
+}
+
struct ipc *get_ipc(struct file *file)
{
int slot;
};
struct ipc_class {
+ size_t size;
unsigned int (*get_hash)(struct file *file);
bool (*is_suitable_ipc)(struct ipc *ipc, struct file *file);
void (*free)(struct ipc *ipc);
};
+struct ipc *new_ipc(const struct ipc_class *class);
struct ipc *get_ipc(struct file *file);
void add_ipc(struct ipc *ipc, unsigned int hash);