Shared Memory Interface

Summary
Shared Memory Interface
tnt_shmem.h
Includes
“tnt_shmem_barrier.h”Specifies the barrier function prototypes of the shared memory API.
“tnt_shmem_mutex.h”Specifies the mutex function prototypes of the shared memory API.
“tnt_shmem_util.h”Specifies the utility function prototypes of the shared memory API.
Typedefs
tnt_shmem_chunk_tA global shared memory address.
Initialization and Finalization
tnt_shmem_initInitializes a global shared memory, as well as DCMF and all associated global variables.
tnt_shmem_finalizeDestroys the global shared memory, all associated variables, and finalizes DCMF.
Memory Allocation
tnt_shmem_mallocMalloc a block of memory from the global shared memory in bytes specified by size.
tnt_shmem_freeFree a malloc’d block of memory.
Read and Write
tnt_shmem_readRead from a shared memory region.
tnt_shmem_writeWrite to a shared memory region

tnt_shmem.h

Includes

“tnt_shmem_barrier.h”

#include "tnt_shmem_barrier.h"

Description

Specifies the barrier function prototypes of the shared memory API.

“tnt_shmem_mutex.h”

#include "tnt_shmem_mutex.h"

Description

Specifies the mutex function prototypes of the shared memory API.

“tnt_shmem_util.h”

#include "tnt_shmem_util.h"

Description

Specifies the utility function prototypes of the shared memory API.

Typedefs

tnt_shmem_chunk_t

typedef void tnt_shmem_chunk_t

Description

A global shared memory address.

Initialization and Finalization

tnt_shmem_init

tnt_ret_t tnt_shmem_init(size_t size)

Description

Initializes a global shared memory, as well as DCMF and all associated global variables.  Not thread safe.

Parameters

sizethe amount of memory in bytes to allocate for global memory.

Returns

1if success when called the first time.
0for every subsequent call.
< 0on failure when called the first time.

See Also

tnt_shmem_finalize

tnt_shmem_finalize

tnt_ret_t tnt_shmem_finalize()

Description

Destroys the global shared memory, all associated variables, and finalizes DCMF.  Not thread safe.

Returns

1if success when called the first time.
0for every subsequent call.
< 0on failure when called the first time.

See Also

tnt_shmem_init

Memory Allocation

tnt_shmem_malloc

tnt_shmem_chunk_t* tnt_shmem_malloc(size_t size)

Description

Malloc a block of memory from the global shared memory in bytes specified by size.

Parameters

sizeThe size of the requested memory, in bytes.

Returns

A handleto the region on success.
NULLon failure.

See Also

tnt_shmem_free

tnt_shmem_free

void tnt_shmem_free(tnt_shmem_chunk_t *chunk)

Description

Free a malloc’d block of memory.

Parameters

chunkThe handle to memory to free.

See Also

tnt_shmem_malloc

Read and Write

tnt_shmem_read

tnt_ret_t tnt_shmem_read(tnt_shmem_chunk_t *src,
void *buffer,
size_t size)

Description

Read from a shared memory region.

Parameters

srcThe source chunk to read data from.
bufferThe local buffer to store the read data in.
sizeThe amount of data to copy from shared memory.

Return

0on success.
< 0on failure.

See Also

tnt_shmem_write

tnt_shmem_write

tnt_ret_t tnt_shmem_write(tnt_shmem_chunk_t *dst,
void *buffer,
size_t size)

Description

Write to a shared memory region

Parameters

dstThe destination chunk to write data to.
bufferThe local buffer containing the data to write.
sizeThe amount of data to copy to shared memory.

Return

0on success.
< 0on failure.

See Also

tnt_shmem_read

#include "tnt_shmem_barrier.h"
Specifies the barrier function prototypes of the shared memory API.
#include "tnt_shmem_mutex.h"
Specifies the mutex function prototypes of the shared memory API.
#include "tnt_shmem_util.h"
Specifies the utility function prototypes of the shared memory API.
typedef void tnt_shmem_chunk_t
A global shared memory address.
tnt_ret_t tnt_shmem_init(size_t size)
Initializes a global shared memory, as well as DCMF and all associated global variables.
tnt_ret_t tnt_shmem_finalize()
Destroys the global shared memory, all associated variables, and finalizes DCMF.
tnt_shmem_chunk_t* tnt_shmem_malloc(size_t size)
Malloc a block of memory from the global shared memory in bytes specified by size.
void tnt_shmem_free(tnt_shmem_chunk_t *chunk)
Free a malloc’d block of memory.
tnt_ret_t tnt_shmem_read(tnt_shmem_chunk_t *src,
void *buffer,
size_t size)
Read from a shared memory region.
tnt_ret_t tnt_shmem_write(tnt_shmem_chunk_t *dst,
void *buffer,
size_t size)
Write to a shared memory region