#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <sys/types.h>
#include "shmalloc.h"
#include "sharedmem_private.h"
Include dependency graph for shmalloc.c:
Go to the source code of this file.
Defines | |
#define | _XOPEN_SOURCE 600 |
#define | _POSIX_C_SOURCE 200112L |
#define | BL_SZ(b) ((b)->size & ~SHAREDMEM_FLAGS_MASK) |
Functions | |
int | sharedmem_alloc_create (sharedmem_alloc_t *inst, sharedmem_t *shminst) |
long | sharedmem_alloc (sharedmem_alloc_t *inst, size_t size) |
long | sharedmem_realloc (sharedmem_alloc_t *inst, long old_offset, size_t size) |
int | sharedmem_free (sharedmem_alloc_t *inst, long offset) |
void * | sharedmem_alloc_get_ptr (sharedmem_alloc_t *inst, long offset) |
int | sharedmem_alloc_grow (sharedmem_alloc_t *inst, size_t new_size) |
void | sharedmem_alloc_list_allocs (sharedmem_alloc_t *inst) |
void | sharedmem_alloc_list_frees (sharedmem_alloc_t *inst) |
#define _POSIX_C_SOURCE 200112L |
Definition at line 30 of file shmalloc.c.
#define _XOPEN_SOURCE 600 |
Definition at line 29 of file shmalloc.c.
#define BL_SZ | ( | b | ) | ((b)->size & ~SHAREDMEM_FLAGS_MASK) |
Size also contains flags, so we need a macro to mask the flags out.
Definition at line 46 of file shmalloc.c.
Referenced by sharedmem_alloc_list_allocs(), sharedmem_alloc_list_frees(), and sharedmem_realloc().
long sharedmem_alloc | ( | sharedmem_alloc_t * | inst, | |
size_t | size | |||
) |
Allocate arbitrary sized block from shared memory.
inst | Instance of shared memory allocator object | |
size | Size of block to allocate |
Definition at line 379 of file shmalloc.c.
References sharedmem_lock(), sharedmem_unlock(), and SHMALLOC_SHAREDMEM.
Here is the call graph for this function:
int sharedmem_alloc_create | ( | sharedmem_alloc_t * | inst, | |
sharedmem_t * | shminst | |||
) |
Initialize allocator on shared memory.
inst | Instance of shared memory allocator object | |
shminst | Instance of shared memory object |
Definition at line 350 of file shmalloc.c.
References _sharedmem_block_t::next, sharedmem_lock(), SHAREDMEM_PTR, SHAREDMEM_SIZE, sharedmem_unlock(), SHMALLOC_SHAREDMEM, and _sharedmem_block_t::size.
Here is the call graph for this function:
void* sharedmem_alloc_get_ptr | ( | sharedmem_alloc_t * | inst, | |
long | offset | |||
) |
Get mapped pointer for offset.
inst | Instance of shared memory allocator object. | |
offset | Offset to get pointer for |
Definition at line 492 of file shmalloc.c.
References SHAREDMEM_PTR, and SHMALLOC_SHAREDMEM.
int sharedmem_alloc_grow | ( | sharedmem_alloc_t * | inst, | |
size_t | new_size | |||
) |
Grow the parent shared memory block and reflect the change in allocator.
inst | Instance of sharedmemory allocator object. | |
new_size | New size of the block |
Definition at line 501 of file shmalloc.c.
References sharedmem_lock(), sharedmem_resize(), SHAREDMEM_SIZE, sharedmem_unlock(), SHMALLOC_SHAREDMEM, and _sharedmem_block_t::size.
Here is the call graph for this function:
void sharedmem_alloc_list_allocs | ( | sharedmem_alloc_t * | inst | ) |
Print list of allocations to stderr.
inst | Instance of shared memory allocator object. |
Definition at line 538 of file shmalloc.c.
References BL_SZ, and _sharedmem_block_t::next.
void sharedmem_alloc_list_frees | ( | sharedmem_alloc_t * | inst | ) |
Print list of free areas to stderr.
inst | Instance of shared memory allocator object. |
Definition at line 562 of file shmalloc.c.
References BL_SZ, and _sharedmem_block_t::next.
int sharedmem_free | ( | sharedmem_alloc_t * | inst, | |
long | offset | |||
) |
Free previously allocated shared memory block.
inst | Instance of shared memory allocator object. | |
offset | Offset to free |
Definition at line 474 of file shmalloc.c.
References sharedmem_lock(), sharedmem_unlock(), and SHMALLOC_SHAREDMEM.
Here is the call graph for this function:
long sharedmem_realloc | ( | sharedmem_alloc_t * | inst, | |
long | old_offset, | |||
size_t | size | |||
) |
Reallocate block from shared memory.
inst | Instance of shared memory allocator object | |
old_offset | Offset to reallocate | |
size | New size for the block |
Definition at line 399 of file shmalloc.c.
References BL_SZ, sharedmem_alloc_get_ptr(), sharedmem_free(), sharedmem_lock(), sharedmem_unlock(), and SHMALLOC_SHAREDMEM.
Here is the call graph for this function: