Skip to content

Commit 3661a08

Browse files
committed
cgmemmgr,macos: add missing shared_map_lock initialization
1 parent de7b6d5 commit 3661a08

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/cgmemmgr.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,12 @@ static _Atomic(size_t) map_offset{0};
218218
// Hopefully no one will set a ulimit for this to be a problem...
219219
static constexpr size_t map_size_inc_default = 128 * 1024 * 1024;
220220
static size_t map_size = 0;
221-
static uv_mutex_t shared_map_lock;
221+
static struct _make_shared_map_lock {
222+
uv_mutex_t mtx;
223+
_make_shared_map_lock() {
224+
uv_mutex_init(&mtx);
225+
};
226+
} shared_map_lock;
222227

223228
static size_t get_map_size_inc()
224229
{
@@ -264,7 +269,7 @@ static void *alloc_shared_page(size_t size, size_t *id, bool exec)
264269
*id = off;
265270
size_t map_size_inc = get_map_size_inc();
266271
if (__unlikely(off + size > map_size)) {
267-
uv_mutex_lock(&shared_map_lock);
272+
uv_mutex_lock(&shared_map_lock.mtx);
268273
size_t old_size = map_size;
269274
while (off + size > map_size)
270275
map_size += map_size_inc;
@@ -275,7 +280,7 @@ static void *alloc_shared_page(size_t size, size_t *id, bool exec)
275280
abort();
276281
}
277282
}
278-
uv_mutex_unlock(&shared_map_lock);
283+
uv_mutex_unlock(&shared_map_lock.mtx);
279284
}
280285
return create_shared_map(size, off);
281286
}
@@ -313,7 +318,6 @@ ssize_t pwrite_addr(int fd, const void *buf, size_t nbyte, uintptr_t addr)
313318
// Use `get_self_mem_fd` which has a guard to call this only once.
314319
static int _init_self_mem()
315320
{
316-
uv_mutex_init(&shared_map_lock);
317321
struct utsname kernel;
318322
uname(&kernel);
319323
int major, minor;

0 commit comments

Comments
 (0)