host/storage: use flex array for host storage

pull/9939/head
Victor Julien 2 years ago committed by Victor Julien
parent d405efd3f6
commit 3d3a62dfe6

@ -74,7 +74,7 @@ HostStorageId HostStorageRegister(const char *name, const unsigned int size,
int HostSetStorageById(Host *h, HostStorageId id, void *ptr) int HostSetStorageById(Host *h, HostStorageId id, void *ptr)
{ {
return StorageSetById((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id.id, ptr); return StorageSetById(h->storage, STORAGE_HOST, id.id, ptr);
} }
/** /**
@ -87,7 +87,7 @@ int HostSetStorageById(Host *h, HostStorageId id, void *ptr)
void *HostGetStorageById(Host *h, HostStorageId id) void *HostGetStorageById(Host *h, HostStorageId id)
{ {
return StorageGetById((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id.id); return StorageGetById(h->storage, STORAGE_HOST, id.id);
} }
/** /**
@ -98,18 +98,18 @@ void *HostGetStorageById(Host *h, HostStorageId id)
void *HostAllocStorageById(Host *h, HostStorageId id) void *HostAllocStorageById(Host *h, HostStorageId id)
{ {
return StorageAllocByIdPrealloc((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id.id); return StorageAllocByIdPrealloc(h->storage, STORAGE_HOST, id.id);
} }
void HostFreeStorageById(Host *h, HostStorageId id) void HostFreeStorageById(Host *h, HostStorageId id)
{ {
StorageFreeById((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id.id); StorageFreeById(h->storage, STORAGE_HOST, id.id);
} }
void HostFreeStorage(Host *h) void HostFreeStorage(Host *h)
{ {
if (HostStorageSize() > 0) if (HostStorageSize() > 0)
StorageFreeAll((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST); StorageFreeAll(h->storage, STORAGE_HOST);
} }

@ -68,9 +68,6 @@ typedef struct Host_ {
/** pointers to iprep storage */ /** pointers to iprep storage */
void *iprep; void *iprep;
/** storage api handle */
Storage *storage;
/** hash pointers, protected by hash row mutex/spin */ /** hash pointers, protected by hash row mutex/spin */
struct Host_ *hnext; struct Host_ *hnext;
struct Host_ *hprev; struct Host_ *hprev;
@ -78,6 +75,9 @@ typedef struct Host_ {
/** list pointers, protected by host-queue mutex/spin */ /** list pointers, protected by host-queue mutex/spin */
struct Host_ *lnext; struct Host_ *lnext;
struct Host_ *lprev; struct Host_ *lprev;
/** storage api handle */
Storage storage[];
} Host; } Host;
typedef struct HostHashRow_ { typedef struct HostHashRow_ {

Loading…
Cancel
Save