-
Notifications
You must be signed in to change notification settings - Fork 318
/
library.c
55 lines (48 loc) · 1.25 KB
/
library.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
* libiio - Library for interfacing industrial I/O (IIO) devices
*
* Copyright (C) 2023 Analog Devices, Inc.
* Author: Paul Cercueil <[email protected]>
*/
#include "iio-private.h"
#include <iio-config.h>
uint64_t library_startup_time_us;
static void libiio_init(void)
{
library_startup_time_us = iio_read_counter_us();
}
static void libiio_exit(void)
{
if (WITH_XML_BACKEND)
libiio_cleanup_xml_backend();
}
#if defined(_MSC_BUILD)
#pragma section(".CRT$XCU", read)
#define __CONSTRUCTOR(f, p) \
static void f(void); \
__declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \
__pragma(comment(linker,"/include:" p #f "_")) \
static void f(void)
#ifdef _WIN64
#define _CONSTRUCTOR(f) __CONSTRUCTOR(f, "")
#else
#define _CONSTRUCTOR(f) __CONSTRUCTOR(f, "_")
#endif
#elif defined(__GNUC__)
#define _CONSTRUCTOR(f) static void __attribute__((constructor)) f(void)
#else
#define _CONSTRUCTOR(f) static void f(void)
#endif
_CONSTRUCTOR(initialize)
{
libiio_init();
/*
* When the library loads, register our destructor.
* Do it here and not in the context creation function,
* as it could otherwise end up registering the destructor
* many times.
*/
atexit(libiio_exit);
}
#undef _CONSTRUCTOR