nxt_malloc.c (0:a63ceefd6ab0) nxt_malloc.c (564:762f8c976ead)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8

--- 24 unchanged lines hidden (view full) ---

33 void *p;
34
35 p = malloc(size);
36
37 if (nxt_fast_path(p != NULL)) {
38 nxt_log_debug(nxt_malloc_log(), "malloc(%uz): %p", size, p);
39
40 } else {
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8

--- 24 unchanged lines hidden (view full) ---

33 void *p;
34
35 p = malloc(size);
36
37 if (nxt_fast_path(p != NULL)) {
38 nxt_log_debug(nxt_malloc_log(), "malloc(%uz): %p", size, p);
39
40 } else {
41 nxt_log_moderate(&nxt_malloc_log_moderation,
42 NXT_LOG_ALERT, nxt_malloc_log(),
43 "malloc(%uz) failed %E", size, nxt_errno);
41 nxt_log_alert_moderate(&nxt_malloc_log_moderation, nxt_malloc_log(),
42 "malloc(%uz) failed %E", size, nxt_errno);
44 }
45
46 return p;
47}
48
49
50void *
51nxt_zalloc(size_t size)

--- 16 unchanged lines hidden (view full) ---

68 void *n;
69
70 n = realloc(p, size);
71
72 if (nxt_fast_path(n != NULL)) {
73 nxt_log_debug(nxt_malloc_log(), "realloc(%p, %uz): %p", p, size, n);
74
75 } else {
43 }
44
45 return p;
46}
47
48
49void *
50nxt_zalloc(size_t size)

--- 16 unchanged lines hidden (view full) ---

67 void *n;
68
69 n = realloc(p, size);
70
71 if (nxt_fast_path(n != NULL)) {
72 nxt_log_debug(nxt_malloc_log(), "realloc(%p, %uz): %p", p, size, n);
73
74 } else {
76 nxt_log_moderate(&nxt_malloc_log_moderation,
77 NXT_LOG_ALERT, nxt_malloc_log(),
78 "realloc(%p, %uz) failed %E", p, size, nxt_errno);
75 nxt_log_alert_moderate(&nxt_malloc_log_moderation, nxt_malloc_log(),
76 "realloc(%p, %uz) failed %E",
77 p, size, nxt_errno);
79 }
80
81 return n;
82}
83
84
85#if (NXT_DEBUG)
86

--- 25 unchanged lines hidden (view full) ---

112 err = posix_memalign(&p, alignment, size);
113
114 if (nxt_fast_path(err == 0)) {
115 nxt_thread_log_debug("posix_memalign(%uz, %uz): %p",
116 alignment, size, p);
117 return p;
118 }
119
78 }
79
80 return n;
81}
82
83
84#if (NXT_DEBUG)
85

--- 25 unchanged lines hidden (view full) ---

111 err = posix_memalign(&p, alignment, size);
112
113 if (nxt_fast_path(err == 0)) {
114 nxt_thread_log_debug("posix_memalign(%uz, %uz): %p",
115 alignment, size, p);
116 return p;
117 }
118
120 nxt_log_moderate(&nxt_malloc_log_moderation,
121 NXT_LOG_ALERT, nxt_malloc_log(),
122 "posix_memalign(%uz, %uz) failed %E",
123 alignment, size, err);
119 nxt_log_alert_moderate(&nxt_malloc_log_moderation, nxt_malloc_log(),
120 "posix_memalign(%uz, %uz) failed %E",
121 alignment, size, err);
124 return NULL;
125}
126
127#elif (NXT_HAVE_MEMALIGN)
128
129/* memalign() presents in Solaris, HP-UX. */
130
131void *

--- 4 unchanged lines hidden (view full) ---

136 p = memalign(alignment, size);
137
138 if (nxt_fast_path(p != NULL)) {
139 nxt_thread_log_debug("memalign(%uz, %uz): %p",
140 alignment, size, p);
141 return p;
142 }
143
122 return NULL;
123}
124
125#elif (NXT_HAVE_MEMALIGN)
126
127/* memalign() presents in Solaris, HP-UX. */
128
129void *

--- 4 unchanged lines hidden (view full) ---

134 p = memalign(alignment, size);
135
136 if (nxt_fast_path(p != NULL)) {
137 nxt_thread_log_debug("memalign(%uz, %uz): %p",
138 alignment, size, p);
139 return p;
140 }
141
144 nxt_log_moderate(&nxt_malloc_log_moderation,
145 NXT_LOG_ALERT, nxt_malloc_log(),
146 "memalign(%uz, %uz) failed %E",
147 alignment, size, nxt_errno);
142 nxt_log_alert_moderate(&nxt_malloc_log_moderation, nxt_malloc_log(),
143 "memalign(%uz, %uz) failed %E",
144 alignment, size, nxt_errno);
148 return NULL;
149}
150
151#elif (NXT_FREEBSD)
152
153/*
154 * FreeBSD prior to 7.0 lacks posix_memalign(), but if a requested size
155 * is lesser than or equal to 4K, then phkmalloc aligns the size to the

--- 28 unchanged lines hidden (view full) ---

184 }
185
186 p = malloc(aligned_size);
187
188 if (nxt_fast_path(p != NULL)) {
189 nxt_thread_log_debug("nxt_memalign(%uz, %uz): %p", alignment, size, p);
190
191 } else {
145 return NULL;
146}
147
148#elif (NXT_FREEBSD)
149
150/*
151 * FreeBSD prior to 7.0 lacks posix_memalign(), but if a requested size
152 * is lesser than or equal to 4K, then phkmalloc aligns the size to the

--- 28 unchanged lines hidden (view full) ---

181 }
182
183 p = malloc(aligned_size);
184
185 if (nxt_fast_path(p != NULL)) {
186 nxt_thread_log_debug("nxt_memalign(%uz, %uz): %p", alignment, size, p);
187
188 } else {
192 nxt_log_moderate(&nxt_malloc_log_moderation,
193 NXT_LOG_ALERT, nxt_malloc_log(),
194 "malloc(%uz) failed %E", size, nxt_errno);
189 nxt_log_alert_moderate(&nxt_malloc_log_moderation, nxt_malloc_log(),
190 "malloc(%uz) failed %E", size, nxt_errno);
195 }
196
197 return p;
198
199fail:
200
201 nxt_thread_log_alert("nxt_memalign(%uz, %uz) failed %E",
202 alignment, size, err);
203 return NULL;
204}
205
206#else
207
208#error no memalign() implementation.
209
210#endif
191 }
192
193 return p;
194
195fail:
196
197 nxt_thread_log_alert("nxt_memalign(%uz, %uz) failed %E",
198 alignment, size, err);
199 return NULL;
200}
201
202#else
203
204#error no memalign() implementation.
205
206#endif