haproxy/include/common
Willy Tarreau d13a9281bd MINOR: initcall: introduce a way to register init functions to call at boot
We currently have to deal with multiple initialization stages in a way
that can be confusing, because certain parts rely on others having been
properly initialized. Most calls consist in adding lists to existing
lists, whose heads are initialized in the declaration so this is easy.
But some calls create new pools and require pools to be properly
initialized. Pools currently are thread-local and as such cannot be
pre-initialized, requiring run-time checks.

All this could be simplified by using multiple boot stages and allowing
functions to be registered at various stages.

One approach might be to use gcc's constructor priorities, but this
requires gcc >= 4.3 which eliminates a wide spectrum of working compilers,
and some versions of certain compilers (like clang 3.0) are known for
silently ignore these priorities.

Instead we can use our own init function registration mechanism. A first
attempt was made using register_function() calls in all constructors but
this made the code more painful.

This patch's approach is different. It creates sections containing
arrays of pointers to "initcall" descriptors. An initcall contains a
pointer to a function and an argument. Each section corresponds to a
specific initialization stage. Each module creates such descriptors
for various calls it requires. The main() function starts by scanning
each of these sections in turn to process these initcalls.

This will make it possible to remove many constructors from various
modules, by simply placing initcalls for the requested functions next
to the keyword lists that need to be called.

A first attempt was made by placing the initcalls directly into the
sections instead of creating an array of pointers, but it becomes
sensitive to the array's alignment which depends on the compiler and
the linker, so it seems too fragile.

For now we support 6 init stages :
  - STG_PREPARE  : preset variables, tables and list heads
  - STG_LOCK     : initialize spinlocks and rwlocks
  - STG_ALLOC    : allocate the required structures
  - STG_POOL     : create pools
  - STG_REGISTER : register static lists (keywords etc)
  - STG_INIT     : subsystems normal initialization

These ones are declared directly in the files where they are needed
using one of the INITCALL* macros, passing 0 to 3 pointers as
arguments.

The API should possibly be extended to support a return value to give
a status to the caller, and to support a unified API, possibly a bit
more flexibility in the arguments. In this case it might make sense to
support a set of macros to register functions having a different API
and to pass the function type in the initcall itself.

Special thanks to Olivier for showing how to scan sections as this is
not something particularly well documented and exactly what I've been
missing to achieve this.
2018-11-26 19:50:32 +01:00
..
accept4.h
base64.h
buf.h BUILD: buffers: buf.h requires unistd to get ssize_t on libmusl 2018-11-26 19:49:21 +01:00
buffer.h MEDIUM: pools: implement a thread-local cache for pool entries 2018-10-16 13:46:08 +02:00
cfgparse.h REORG: config: extract the proxy parser into cfgparse-listen.c 2018-11-19 06:47:09 +01:00
chunk.h MINOR: chunk: add chunk_cpy() and chunk_cat() 2018-10-12 16:58:01 +02:00
compat.h MINOR: compat: automatically detect support for crypt_r() 2018-10-29 19:14:14 +01:00
compiler.h BUILD: compiler: rename __unreachable() to my_unreachable() 2018-10-20 17:45:48 +02:00
config.h MINOR: fd: centralize poll timeout computation in compute_poll_timeout() 2018-10-17 19:59:43 +02:00
debug.h
defaults.h MEDIUM: ssl: add support for ciphersuites option for TLSv1.3 2018-10-08 19:20:13 +02:00
epoll.h
errors.h
h2.h MINOR: h2: detect presence of CONNECT and/or content-length 2018-04-26 10:15:14 +02:00
hash.h MINOR: hash: add new function hash_crc32c 2018-03-21 05:04:01 +01:00
hathreads.h BUG/MEDIUM: auth/threads: use of crypt() is not thread-safe 2018-10-29 18:06:02 +01:00
hpack-dec.h MAJOR: chunks: replace struct chunk with struct buffer 2018-07-19 16:23:43 +02:00
hpack-enc.h MAJOR: chunks: replace struct chunk with struct buffer 2018-07-19 16:23:43 +02:00
hpack-huff.h MINOR: hpack: implement the HPACK Huffman table decoder 2017-10-31 18:03:24 +01:00
hpack-tbl.h BUG/CRITICAL: hpack: fix improper sign check on the header index value 2018-09-20 11:45:56 +02:00
http-hdr.h MINOR: http: add http_hdr_del() to remove a header from a list 2018-09-14 17:40:35 +02:00
http.h MINOR: http: Add standalone functions to parse a start-line or a header 2018-11-18 21:45:49 +01:00
initcall.h MINOR: initcall: introduce a way to register init functions to call at boot 2018-11-26 19:50:32 +01:00
ist.h BUILD: buffers: buf.h requires unistd to get ssize_t on libmusl 2018-11-26 19:49:21 +01:00
istbuf.h MINOR: buffer: rename the data length member to '->data' 2018-07-19 16:23:43 +02:00
memory.h BUILD: buffers: buf.h requires unistd to get ssize_t on libmusl 2018-11-26 19:49:21 +01:00
mini-clist.h MEDIUM: lists: list_for_each_entry{_safe}_from functions 2017-10-31 03:44:11 +01:00
namespace.h MINOR: namespaces: don't build namespace.c if disabled 2018-11-12 19:15:15 +01:00
net_helper.h
regex.h MINOR: threads/regex: Change Regex trash buffer into a thread local variable 2017-10-31 13:58:31 +01:00
splice.h
standard.h CLEANUP: Fix typos in the standard subsystem 2018-11-18 22:26:42 +01:00
syscall.h
template.h
ticks.h
time.h MINOR: poller: move the call of tv_update_date() back to the pollers 2018-11-22 18:57:37 +01:00
tools.h
uri_auth.h
version.h [RELEASE] Released version 1.9-dev0 2017-11-26 19:50:17 +01:00
xref.h MEDIUM: threads/xref: Convert xref function to a thread safe model 2017-10-31 13:58:32 +01:00