xref: /freebsd/contrib/xz/src/liblzma/api/lzma/hardware.h (revision 5b56413d04e608379c9a306373554a8e4d321bc0)
1 /* SPDX-License-Identifier: 0BSD */
2 
3 /**
4  * \file        lzma/hardware.h
5  * \brief       Hardware information
6  * \note        Never include this file directly. Use <lzma.h> instead.
7  *
8  * Since liblzma can consume a lot of system resources, it also provides
9  * ways to limit the resource usage. Applications linking against liblzma
10  * need to do the actual decisions how much resources to let liblzma to use.
11  * To ease making these decisions, liblzma provides functions to find out
12  * the relevant capabilities of the underlying hardware. Currently there
13  * is only a function to find out the amount of RAM, but in the future there
14  * will be also a function to detect how many concurrent threads the system
15  * can run.
16  *
17  * \note        On some operating systems, these function may temporarily
18  *              load a shared library or open file descriptor(s) to find out
19  *              the requested hardware information. Unless the application
20  *              assumes that specific file descriptors are not touched by
21  *              other threads, this should have no effect on thread safety.
22  *              Possible operations involving file descriptors will restart
23  *              the syscalls if they return EINTR.
24  */
25 
26 /*
27  * Author: Lasse Collin
28  */
29 
30 #ifndef LZMA_H_INTERNAL
31 #	error Never include this file directly. Use <lzma.h> instead.
32 #endif
33 
34 
35 /**
36  * \brief       Get the total amount of physical memory (RAM) in bytes
37  *
38  * This function may be useful when determining a reasonable memory
39  * usage limit for decompressing or how much memory it is OK to use
40  * for compressing.
41  *
42  * \return      On success, the total amount of physical memory in bytes
43  *              is returned. If the amount of RAM cannot be determined,
44  *              zero is returned. This can happen if an error occurs
45  *              or if there is no code in liblzma to detect the amount
46  *              of RAM on the specific operating system.
47  */
48 extern LZMA_API(uint64_t) lzma_physmem(void) lzma_nothrow;
49 
50 
51 /**
52  * \brief       Get the number of processor cores or threads
53  *
54  * This function may be useful when determining how many threads to use.
55  * If the hardware supports more than one thread per CPU core, the number
56  * of hardware threads is returned if that information is available.
57  *
58  * \return      On success, the number of available CPU threads or cores is
59  *              returned. If this information isn't available or an error
60  *              occurs, zero is returned.
61  */
62 extern LZMA_API(uint32_t) lzma_cputhreads(void) lzma_nothrow;
63