Skip to content

Commit

Permalink
cgmemmgr,macos: add missing shared_map_lock initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Nov 1, 2022
1 parent de7b6d5 commit 3661a08
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/cgmemmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,12 @@ static _Atomic(size_t) map_offset{0};
// Hopefully no one will set a ulimit for this to be a problem...
static constexpr size_t map_size_inc_default = 128 * 1024 * 1024;
static size_t map_size = 0;
static uv_mutex_t shared_map_lock;
static struct _make_shared_map_lock {
uv_mutex_t mtx;
_make_shared_map_lock() {
uv_mutex_init(&mtx);
};
} shared_map_lock;

static size_t get_map_size_inc()
{
Expand Down Expand Up @@ -264,7 +269,7 @@ static void *alloc_shared_page(size_t size, size_t *id, bool exec)
*id = off;
size_t map_size_inc = get_map_size_inc();
if (__unlikely(off + size > map_size)) {
uv_mutex_lock(&shared_map_lock);
uv_mutex_lock(&shared_map_lock.mtx);
size_t old_size = map_size;
while (off + size > map_size)
map_size += map_size_inc;
Expand All @@ -275,7 +280,7 @@ static void *alloc_shared_page(size_t size, size_t *id, bool exec)
abort();
}
}
uv_mutex_unlock(&shared_map_lock);
uv_mutex_unlock(&shared_map_lock.mtx);
}
return create_shared_map(size, off);
}
Expand Down Expand Up @@ -313,7 +318,6 @@ ssize_t pwrite_addr(int fd, const void *buf, size_t nbyte, uintptr_t addr)
// Use `get_self_mem_fd` which has a guard to call this only once.
static int _init_self_mem()
{
uv_mutex_init(&shared_map_lock);
struct utsname kernel;
uname(&kernel);
int major, minor;
Expand Down

0 comments on commit 3661a08

Please sign in to comment.