Skip to content

Commit 5bda9c8

Browse files
committed
CDRIVER-1909 improve init / cleanup docs
1 parent c70bc16 commit 5bda9c8

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

doc/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ EXTRA_DIST += \
88
doc/mongoc-theme/static/mongoc.css_t \
99
doc/mongoc-theme/static/pygments.css \
1010
doc/mongoc-theme/theme.conf \
11-
doc/taglist.py
11+
doc/taglist.py \
12+
$(wildcard doc/includes/*.txt)
1213

1314
dist-hook: man html
1415

doc/includes/init_cleanup.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Initialize the MongoDB C Driver by calling :symbol:`mongoc_init` exactly once at the beginning of your program. It is responsible for initializing global state such as process counters, SSL, and threading primitives.
2+
3+
Call :symbol:`mongoc_cleanup` exactly once at the end of your program to release all memory and other resources allocated by the driver. You must not call any other MongoDB C Driver functions after :symbol:`mongoc_cleanup`. Note that :symbol:`mongoc_init` does **not** reinitialize the driver after :symbol:`mongoc_cleanup`.

doc/init-cleanup.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,30 @@ Initialization and cleanup
66
Synopsis
77
--------
88

9-
The MongoDB C driver must be initialized using :symbol:`mongoc_init <mongoc_init>` before use, and cleaned up with :symbol:`mongoc_cleanup <mongoc_cleanup>` before exiting. Failing to call these functions is a programming error.
9+
.. include:: includes/init_cleanup.txt
1010

1111
.. only:: html
1212

1313
.. toctree::
1414
:titlesonly:
1515
:maxdepth: 1
1616

17-
mongoc_cleanup
1817
mongoc_init
18+
mongoc_cleanup
19+
20+
Deprecated feature: automatic initialization and cleanup
21+
--------------------------------------------------------
22+
23+
On some platforms the driver can automatically call :symbol:`mongoc_init` before ``main``, and call :symbol:`mongoc_cleanup` as the process exits. This is problematic in situations where related libraries also execute cleanup code on shutdown, and it creates inconsistent rules across platforms. Therefore the automatic initialization and cleanup feature is deprecated, and will be dropped in version 2.0. Meanwhile, for backward compatibility, the feature is *enabled* by default on platforms where it is available.
24+
25+
For portable, future-proof code, always call :symbol:`mongoc_init` and :symbol:`mongoc_cleanup` yourself, and configure the driver like:
26+
27+
.. code-block:: none
28+
29+
./configure --disable-automatic-init-and-cleanup
30+
31+
Or with CMake:
32+
33+
.. code-block:: none
1934
35+
cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=NO

doc/installing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ The most recent release of libmongoc is |release| and can be `downloaded here <h
8383
$ cd mongo-c-driver-|release|
8484
$ ./configure --disable-automatic-init-and-cleanup
8585
86-
For a list of all configure options, run ``./configure --help``.
86+
The ``--disable-automatic-init-and-cleanup`` option is recommended, see :doc:`init-cleanup`. For a list of all configure options, run ``./configure --help``.
8787

8888
If ``configure`` completed successfully, you'll see something like the following describing your build configuration.
8989

doc/mongoc_cleanup.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ Synopsis
1414
Description
1515
-----------
1616

17-
This function is responsible for cleaning up after use of the MongoDB C driver. It will release any lingering allocated memory which can be useful when running under valgrind.
18-
17+
.. include:: includes/init_cleanup.txt

doc/mongoc_init.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,4 @@ Synopsis
1414
Description
1515
-----------
1616

17-
This function should be called at the beginning of every program using the MongoDB C driver. It is responsible for initializing global state such as process counters, SSL, and threading primitives.
18-
19-
When your process has completed, you should also call :symbol:`mongoc_cleanup <mongoc_cleanup>`.
20-
17+
.. include:: includes/init_cleanup.txt

0 commit comments

Comments
 (0)