This source file includes following definitions.
- shmem_realloc
- shrealloc
- _shrealloc
1
2
3
4
5
6
7
8
9
10 #include "oshmem_config.h"
11 #include <stdio.h>
12 #include <stdlib.h>
13
14 #include "oshmem/constants.h"
15 #include "oshmem/include/shmem.h"
16
17 #include "oshmem/runtime/runtime.h"
18
19 #include "oshmem/shmem/shmem_api_logger.h"
20 #include "oshmem/mca/memheap/memheap.h"
21 #include "oshmem/mca/memheap/base/base.h"
22
23 #if OSHMEM_PROFILING
24 #include "oshmem/include/pshmem.h"
25 #pragma weak shmem_realloc = pshmem_realloc
26 #pragma weak shrealloc = pshrealloc
27 #include "oshmem/shmem/c/profile/defines.h"
28 #endif
29
30 static inline void* _shrealloc(void *ptr, size_t size);
31
32 void* shmem_realloc(void *ptr, size_t size)
33 {
34 return _shrealloc(ptr, size);
35 }
36
37 void* shrealloc(void *ptr, size_t size)
38 {
39 return _shrealloc(ptr, size);
40 }
41
42 static inline void* _shrealloc(void *ptr, size_t size)
43 {
44 int rc;
45 void* pBuff = NULL;
46 map_segment_t *s;
47
48 RUNTIME_CHECK_INIT();
49
50 SHMEM_MUTEX_LOCK(shmem_internal_mutex_alloc);
51
52 if (ptr) {
53 s = memheap_find_va(ptr);
54 } else {
55 s = NULL;
56 }
57
58 if (s && s->allocator) {
59 rc = s->allocator->realloc(s, size, ptr, &pBuff);
60 } else {
61 rc = MCA_MEMHEAP_CALL(realloc(size, ptr, &pBuff));
62 }
63
64 SHMEM_MUTEX_UNLOCK(shmem_internal_mutex_alloc);
65
66 if (OSHMEM_SUCCESS != rc) {
67 SHMEM_API_VERBOSE(1,
68 "Allocation with shrealloc(ptr=%p, size=%lu) failed.",
69 ptr, (unsigned long)size);
70 return NULL ;
71 }
72
73 #if OSHMEM_SPEC_COMPAT == 1
74 shmem_barrier_all();
75 #endif
76
77 return pBuff;
78 }