|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/* vim: set ft=c.mpich : */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2016 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* This file contains "pre" definitions and declarations for the OS wrappers.
|
|
Packit Service |
c5cf8c |
* That is, things that shouldn't depend on much more than the mpichconf.h
|
|
Packit Service |
c5cf8c |
* values. */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifndef MPL_SHM_H_INCLUDED
|
|
Packit Service |
c5cf8c |
#define MPL_SHM_H_INCLUDED
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#include "mplconfig.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define MPL_SHM_SUCCESS 0
|
|
Packit Service |
c5cf8c |
#define MPL_SHM_EINTERN -1
|
|
Packit Service |
c5cf8c |
#define MPL_SHM_EINVAL -2
|
|
Packit Service |
c5cf8c |
#define MPL_SHM_ENOMEM -3
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#ifdef MPL_USE_SYSV_SHM
|
|
Packit Service |
c5cf8c |
#include "mpl_shm_sysv.h"
|
|
Packit Service |
c5cf8c |
#elif defined MPL_USE_MMAP_SHM
|
|
Packit Service |
c5cf8c |
#include "mpl_shm_mmap.h"
|
|
Packit Service |
c5cf8c |
#elif defined MPL_USE_NT_SHM
|
|
Packit Service |
c5cf8c |
#include "mpl_shm_win.h"
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define MPLI_SHM_FLAG_CLR 0x0
|
|
Packit Service |
c5cf8c |
#define MPLI_SHM_FLAG_SHM_CREATE 0x1
|
|
Packit Service |
c5cf8c |
#define MPLI_SHM_FLAG_SHM_ATTACH 0x10
|
|
Packit Service |
c5cf8c |
#define MPLI_SHM_FLAG_GHND_STATIC 0x100
|
|
Packit Service |
c5cf8c |
#define MPLI_SHM_FLAG_FIXED_ADDR 0x1000
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define MPL_SHM_HND_INVALID NULL
|
|
Packit Service |
c5cf8c |
#define MPLI_SHM_GHND_INVALID NULL
|
|
Packit Service |
c5cf8c |
#define MPLI_SHM_GHND_INIT_VAL '\0'
|
|
Packit Service |
c5cf8c |
#define MPL_SHM_HND_SZ (sizeof(MPLI_shm_lghnd_t))
|
|
Packit Service |
c5cf8c |
#define MPL_SHM_GHND_SZ MPLI_SHM_GHND_SZ
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* A Handle is valid if it is initialized/init and has a value
|
|
Packit Service |
c5cf8c |
* different from the default/invalid value assigned during init
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#define MPLI_shm_hnd_is_valid(hnd) (\
|
|
Packit Service |
c5cf8c |
((hnd) && \
|
|
Packit Service |
c5cf8c |
MPLI_shm_lhnd_is_valid(hnd) && \
|
|
Packit Service |
c5cf8c |
MPLI_shm_ghnd_is_valid(hnd)) \
|
|
Packit Service |
c5cf8c |
)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* With MMAP_SHM, NT_SHM & SYSV_SHM local handle is always init'ed */
|
|
Packit Service |
c5cf8c |
#define MPLI_shm_hnd_is_init(hnd) (\
|
|
Packit Service |
c5cf8c |
((hnd) && /* MPL_shm_lhnd_is_init(hnd) && */ \
|
|
Packit Service |
c5cf8c |
MPLI_shm_ghnd_is_init(hnd)) \
|
|
Packit Service |
c5cf8c |
)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* These macros are the setters/getters for the shm handle */
|
|
Packit Service |
c5cf8c |
#define MPLI_shm_lhnd_get(hnd) ((hnd)->lhnd)
|
|
Packit Service |
c5cf8c |
#define MPLI_shm_lhnd_set(hnd, val) ((hnd)->lhnd=val)
|
|
Packit Service |
c5cf8c |
#define MPLI_shm_lhnd_is_valid(hnd) (((hnd)->lhnd != MPLI_SHM_LHND_INVALID))
|
|
Packit Service |
c5cf8c |
#define MPLI_shm_lhnd_is_init(hnd) 1
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Allocate mem for references within the handle */
|
|
Packit Service |
c5cf8c |
/* Returns MPL_SHM_SUCCESS on success, MPL_SHM_ENOMEM on error */
|
|
Packit Service |
c5cf8c |
#define MPL_shm_hnd_ref_alloc(hnd)(\
|
|
Packit Service |
c5cf8c |
((hnd)->ghnd = (MPLI_shm_ghnd_t) \
|
|
Packit Service |
c5cf8c |
MPL_malloc(MPLI_SHM_GHND_SZ, MPL_MEM_SHM)) ? MPL_SHM_SUCCESS : MPL_SHM_ENOMEM \
|
|
Packit Service |
c5cf8c |
)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* These macros are the setters/getters for the shm handle */
|
|
Packit Service |
c5cf8c |
#define MPLI_shm_ghnd_get_by_ref(hnd) ((hnd)->ghnd)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Returns -1 on error, 0 on success */
|
|
Packit Service |
c5cf8c |
#define MPLI_shm_ghnd_get_by_val(hnd, str, strlen) (\
|
|
Packit Service |
c5cf8c |
(MPL_snprintf(str, strlen, "%s", \
|
|
Packit Service |
c5cf8c |
MPLI_shm_ghnd_get_by_ref(hnd))) ? MPL_SHM_SUCCESS : MPL_SHM_EINTERN \
|
|
Packit Service |
c5cf8c |
)
|
|
Packit Service |
c5cf8c |
#define MPLI_shm_ghnd_set_by_ref(hnd, val) ((hnd)->ghnd = val)
|
|
Packit Service |
c5cf8c |
/* Returns -1 on error, 0 on success */
|
|
Packit Service |
c5cf8c |
/* FIXME: What if val is a non-null terminated string ? */
|
|
Packit Service |
c5cf8c |
#define MPLI_shm_ghnd_set_by_val(hnd, fmt, val) (\
|
|
Packit Service |
c5cf8c |
(MPL_snprintf(MPLI_shm_ghnd_get_by_ref(hnd), \
|
|
Packit Service |
c5cf8c |
MPLI_SHM_GHND_SZ, fmt, val)) ? MPL_SHM_SUCCESS : MPL_SHM_EINTERN \
|
|
Packit Service |
c5cf8c |
)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define MPLI_shm_ghnd_is_valid(hnd) (\
|
|
Packit Service |
c5cf8c |
(((hnd)->ghnd == MPLI_SHM_GHND_INVALID) || \
|
|
Packit Service |
c5cf8c |
(strlen((hnd)->ghnd) == 0)) ? 0 : 1 \
|
|
Packit Service |
c5cf8c |
)
|
|
Packit Service |
c5cf8c |
#define MPLI_shm_ghnd_is_init(hnd) (\
|
|
Packit Service |
c5cf8c |
((hnd)->flag & MPLI_SHM_FLAG_GHND_STATIC) ? \
|
|
Packit Service |
c5cf8c |
1 : \
|
|
Packit Service |
c5cf8c |
(((hnd)->ghnd != MPLI_SHM_GHND_INVALID) ? 1 : 0) \
|
|
Packit Service |
c5cf8c |
)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Allocate mem for global handle.
|
|
Packit Service |
c5cf8c |
* Returns 0 on success, -1 on failure
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
static inline int MPLI_shm_ghnd_alloc(MPL_shm_hnd_t hnd, MPL_memory_class class)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
if (!(hnd->ghnd)) {
|
|
Packit Service |
c5cf8c |
hnd->ghnd = (MPLI_shm_ghnd_t) MPL_malloc(MPLI_SHM_GHND_SZ, class);
|
|
Packit Service |
c5cf8c |
if (!(hnd->ghnd)) {
|
|
Packit Service |
c5cf8c |
return MPL_SHM_ENOMEM;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
/* Global handle is no longer static */
|
|
Packit Service |
c5cf8c |
hnd->flag &= ~MPLI_SHM_FLAG_GHND_STATIC;
|
|
Packit Service |
c5cf8c |
return MPL_SHM_SUCCESS;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Allocate mem for handle. Lazy allocation for global handle */
|
|
Packit Service |
c5cf8c |
/* Returns 0 on success, -1 on error */
|
|
Packit Service |
c5cf8c |
static inline int MPLI_shm_hnd_alloc(MPL_shm_hnd_t * hnd_ptr, MPL_memory_class class)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
*hnd_ptr = (MPL_shm_hnd_t) MPL_malloc(MPL_SHM_HND_SZ, class);
|
|
Packit Service |
c5cf8c |
if (*hnd_ptr) {
|
|
Packit Service |
c5cf8c |
(*hnd_ptr)->flag = MPLI_SHM_FLAG_GHND_STATIC;
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
return MPL_SHM_ENOMEM;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
return MPL_SHM_SUCCESS;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Close Handle */
|
|
Packit Service |
c5cf8c |
#define MPLI_shm_hnd_close(hnd) MPLI_shm_lhnd_close(hnd)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
static inline void MPLI_shm_hnd_reset_val(MPL_shm_hnd_t hnd)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
MPLI_shm_lhnd_set(hnd, MPLI_SHM_LHND_INIT_VAL);
|
|
Packit Service |
c5cf8c |
if (hnd->flag & MPLI_SHM_FLAG_GHND_STATIC) {
|
|
Packit Service |
c5cf8c |
hnd->ghnd = MPLI_SHM_GHND_INVALID;
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
(hnd->ghnd)[0] = MPLI_SHM_GHND_INIT_VAL;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
static inline void MPLI_shm_hnd_free(MPL_shm_hnd_t hnd)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
if (MPLI_shm_hnd_is_init(hnd)) {
|
|
Packit Service |
c5cf8c |
if (!(hnd->flag & MPLI_SHM_FLAG_GHND_STATIC)) {
|
|
Packit Service |
c5cf8c |
MPL_free(hnd->ghnd);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPL_free(hnd);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* interfaces */
|
|
Packit Service |
c5cf8c |
int MPL_shm_hnd_serialize(char *str, MPL_shm_hnd_t hnd, int str_len);
|
|
Packit Service |
c5cf8c |
int MPL_shm_hnd_deserialize(MPL_shm_hnd_t hnd, const char *str_hnd, size_t str_hnd_len);
|
|
Packit Service |
c5cf8c |
int MPL_shm_hnd_get_serialized_by_ref(MPL_shm_hnd_t hnd, char **str_ptr);
|
|
Packit Service |
c5cf8c |
int MPL_shm_hnd_deserialize_by_ref(MPL_shm_hnd_t hnd, char **ser_hnd_ptr);
|
|
Packit Service |
c5cf8c |
int MPL_shm_hnd_init(MPL_shm_hnd_t * hnd_ptr);
|
|
Packit Service |
c5cf8c |
int MPL_shm_hnd_finalize(MPL_shm_hnd_t * hnd_ptr);
|
|
Packit Service |
c5cf8c |
int MPL_shm_seg_create(MPL_shm_hnd_t hnd, intptr_t seg_sz);
|
|
Packit Service |
c5cf8c |
int MPL_shm_seg_open(MPL_shm_hnd_t hnd, intptr_t seg_sz);
|
|
Packit Service |
c5cf8c |
int MPL_shm_seg_create_and_attach(MPL_shm_hnd_t hnd, intptr_t seg_sz,
|
|
Packit Service |
c5cf8c |
void **shm_addr_ptr, int offset);
|
|
Packit Service |
c5cf8c |
int MPL_shm_seg_attach(MPL_shm_hnd_t hnd, intptr_t seg_sz, void **shm_addr_ptr, int offset);
|
|
Packit Service |
c5cf8c |
int MPL_shm_fixed_seg_create_and_attach(MPL_shm_hnd_t hnd, intptr_t seg_sz,
|
|
Packit Service |
c5cf8c |
void **shm_addr_ptr, int offset);
|
|
Packit Service |
c5cf8c |
int MPL_shm_fixed_seg_attach(MPL_shm_hnd_t hnd, intptr_t seg_sz, void **shm_addr_ptr, int offset);
|
|
Packit Service |
c5cf8c |
int MPL_shm_seg_detach(MPL_shm_hnd_t hnd, void **shm_addr_ptr, intptr_t seg_sz);
|
|
Packit Service |
c5cf8c |
int MPL_shm_seg_remove(MPL_shm_hnd_t hnd);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#endif /* MPL_SHM_H_INCLUDED */
|