Move to kernel style SPDX license identifiers
[lttng-ust.git] / liblttng-ust / lttng-getcpu.c
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 */
6
7 #define _LGPL_SOURCE
8 #include <error.h>
9 #include <dlfcn.h>
10 #include <stdlib.h>
11 #include <usterr-signal-safe.h>
12 #include <lttng/ust-getcpu.h>
13 #include <urcu/system.h>
14 #include <urcu/arch.h>
15
16 #include "getenv.h"
17 #include "../libringbuffer/getcpu.h"
18
19 int (*lttng_get_cpu)(void);
20
21 static
22 void *getcpu_handle;
23
24 int lttng_ust_getcpu_override(int (*getcpu)(void))
25 {
26 CMM_STORE_SHARED(lttng_get_cpu, getcpu);
27 return 0;
28 }
29
30 void lttng_ust_getcpu_init(void)
31 {
32 const char *libname;
33 void (*libinit)(void);
34
35 if (getcpu_handle)
36 return;
37 libname = lttng_getenv("LTTNG_UST_GETCPU_PLUGIN");
38 if (!libname)
39 return;
40 getcpu_handle = dlopen(libname, RTLD_NOW);
41 if (!getcpu_handle) {
42 PERROR("Cannot load LTTng UST getcpu override library %s",
43 libname);
44 return;
45 }
46 dlerror();
47 libinit = (void (*)(void)) dlsym(getcpu_handle,
48 "lttng_ust_getcpu_plugin_init");
49 if (!libinit) {
50 PERROR("Cannot find LTTng UST getcpu override library %s initialization function lttng_ust_getcpu_plugin_init()",
51 libname);
52 return;
53 }
54 libinit();
55 }
This page took 0.029927 seconds and 4 git commands to generate.