summaryrefslogtreecommitdiffstats
path: root/src/mercury/mercury_mem.h
blob: c1ff53dfd5985d25c61cd4293f07ea59dbad1061 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * Copyright (C) 2013-2019 Argonne National Laboratory, Department of Energy,
 *                    UChicago Argonne, LLC and The HDF Group.
 * All rights reserved.
 *
 * The full copyright notice, including terms governing use, modification,
 * and redistribution, is contained in the COPYING file that can be
 * found at the root of the source code distribution tree.
 */

#ifndef MERCURY_MEM_H
#define MERCURY_MEM_H

#include "mercury_util_config.h"

/*************************************/
/* Public Type and Struct Definition */
/*************************************/

/*****************/
/* Public Macros */
/*****************/

#define HG_MEM_CACHE_LINE_SIZE 64
#define HG_MEM_PAGE_SIZE       4096

/*********************/
/* Public Prototypes */
/*********************/

#ifdef __cplusplus
extern "C" {
#endif

/**
 * Get system default page size.
 *
 * \return page size on success or negative on failure
 */
HG_UTIL_PUBLIC long
hg_mem_get_page_size(void);

/**
 * Allocate size bytes and return a pointer to the allocated memory.
 * The memory address will be a multiple of alignment, which must be a power of
 * two, and size should be a multiple of alignment.
 *
 * \param alignment [IN]        alignment size
 * \param size [IN]             total requested size
 *
 * \return a pointer to the allocated memory, or NULL in case of failure
 */
HG_UTIL_PUBLIC void *
hg_mem_aligned_alloc(size_t alignment, size_t size);

/**
 * Free memory allocated from hg_aligned_alloc().
 *
 * \param mem_ptr [IN]          pointer to allocated memory
 */
HG_UTIL_PUBLIC void
hg_mem_aligned_free(void *mem_ptr);

/**
 * Create/open a shared-memory mapped file of size \size with name \name.
 *
 * \param name [IN]             name of mapped file
 * \param size [IN]             total requested size
 * \param create [IN]           create file if not existing
 *
 * \return a pointer to the mapped memory region, or NULL in case of failure
 */
HG_UTIL_PUBLIC void *
hg_mem_shm_map(const char *name, size_t size, hg_util_bool_t create);

/**
 * Unmap a previously mapped region and close the file.
 *
 * \param name [IN]             name of mapped file
 * \param mem_ptr [IN]          pointer to mapped memory region
 * \param size [IN]             size range of the mapped region
 *
 * \return non-negative on success, or negative in case of failure
 */
HG_UTIL_PUBLIC int
hg_mem_shm_unmap(const char *name, void *mem_ptr, size_t size);

#ifdef __cplusplus
}
#endif

#endif /* MERCURY_MEM_H */