mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-04-18 06:00:35 +02:00
mapi: Use util_call_once to init exec_mem and mutex instead _MTX_INITIALIZER_NP
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19154>
This commit is contained in:
parent
cf36399459
commit
1411d79e24
3 changed files with 19 additions and 10 deletions
|
|
@ -81,7 +81,7 @@ libglapi_bridge = static_library(
|
|||
bridge_glapi_files,
|
||||
include_directories : [inc_mesa, inc_include, inc_src, inc_mapi],
|
||||
c_args : [c_msvc_compat_args, bridge_glapi_args],
|
||||
dependencies : [dep_thread, dep_selinux, idep_mesautilc11],
|
||||
dependencies : [dep_thread, dep_selinux, idep_mesautilc11, idep_mesautil],
|
||||
build_by_default : false,
|
||||
)
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ else
|
|||
static_glapi_files,
|
||||
include_directories : [inc_mesa, inc_include, inc_src, inc_mapi],
|
||||
c_args : [c_msvc_compat_args, static_glapi_args],
|
||||
dependencies : [dep_thread, dep_selinux, idep_mesautilc11],
|
||||
dependencies : [dep_thread, dep_selinux, idep_mesautilc11, idep_mesautil],
|
||||
build_by_default : false,
|
||||
)
|
||||
endif
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ libglapi = shared_library(
|
|||
gnu_symbol_visibility : 'hidden',
|
||||
link_args : [ld_args_gc_sections],
|
||||
include_directories : [inc_src, inc_include, inc_mapi],
|
||||
dependencies : [dep_thread, dep_selinux, idep_mesautilc11],
|
||||
dependencies : [dep_thread, dep_selinux, idep_mesautilc11, idep_mesautil],
|
||||
soversion : host_machine.system() == 'windows' ? '' : '0',
|
||||
version : '0.0.0',
|
||||
name_prefix : 'lib',
|
||||
|
|
|
|||
|
|
@ -33,12 +33,13 @@
|
|||
|
||||
|
||||
#include "c11/threads.h"
|
||||
#include "util/u_call_once.h"
|
||||
#include "u_execmem.h"
|
||||
|
||||
|
||||
#define EXEC_MAP_SIZE (4*1024)
|
||||
|
||||
static mtx_t exec_mutex = _MTX_INITIALIZER_NP;
|
||||
static mtx_t exec_mutex;
|
||||
|
||||
static unsigned int head = 0;
|
||||
|
||||
|
|
@ -76,9 +77,8 @@ init_map(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
if (!exec_mem)
|
||||
exec_mem = mmap(NULL, EXEC_MAP_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
exec_mem = mmap(NULL, EXEC_MAP_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
|
||||
return (exec_mem != MAP_FAILED);
|
||||
}
|
||||
|
|
@ -117,6 +117,14 @@ init_map(void)
|
|||
|
||||
#endif
|
||||
|
||||
static void
|
||||
u_execmem_init_once(void)
|
||||
{
|
||||
if (!init_map())
|
||||
exec_mem = NULL;
|
||||
mtx_init(&exec_mutex, mtx_plain);
|
||||
}
|
||||
|
||||
void *
|
||||
u_execmem_alloc(unsigned int size)
|
||||
{
|
||||
|
|
@ -125,12 +133,13 @@ u_execmem_alloc(unsigned int size)
|
|||
return NULL;
|
||||
#else
|
||||
void *addr = NULL;
|
||||
static util_once_flag once = UTIL_ONCE_FLAG_INIT;
|
||||
util_call_once(&once, u_execmem_init_once);
|
||||
if (exec_mem == NULL)
|
||||
return NULL;
|
||||
|
||||
mtx_lock(&exec_mutex);
|
||||
|
||||
if (!init_map())
|
||||
goto bail;
|
||||
|
||||
/* free space check, assumes no integer overflow */
|
||||
if (head + size > EXEC_MAP_SIZE)
|
||||
goto bail;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue