<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/libgit2.git/src/global.c, branch ethomson/callback_names</title>
<subtitle>github.com: libgit2/libgit2.git
</subtitle>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/libgit2.git/'/>
<entry>
<title>global: move init callbacks into an array</title>
<updated>2019-01-02T08:33:55+00:00</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2019-01-02T08:33:55+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/libgit2.git/commit/?id=b46c35943a201a6e9be606215327c7da9d4f53c9'/>
<id>b46c35943a201a6e9be606215327c7da9d4f53c9</id>
<content type='text'>
We currently have an explicit callchain of all the initialization
callbacks in our `init_common` function. This is perfectly fine, but
requires us to manually keep track of how many shutdown callbacks there
may be installed: to avoid allocations before libgit2 is fully
initialized, we assume that every initializer may register at most one
shutdown function. These shutdown functions are stored in a static array
of size `MAX_SHUTDOWN_CB`, which then needs to be updated manually
whenever a new initializer function is being added.

The situation can be easily fixed: convert the callchain of init
functions into an array and iterate over it to initialize all
subsystems. This allows us to define the `git__shutdown_callbacks` array
with the same size as the initializer array and rids us of the need to
always update `MAX_SHUTDOWN_CB`.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We currently have an explicit callchain of all the initialization
callbacks in our `init_common` function. This is perfectly fine, but
requires us to manually keep track of how many shutdown callbacks there
may be installed: to avoid allocations before libgit2 is fully
initialized, we assume that every initializer may register at most one
shutdown function. These shutdown functions are stored in a static array
of size `MAX_SHUTDOWN_CB`, which then needs to be updated manually
whenever a new initializer function is being added.

The situation can be easily fixed: convert the callchain of init
functions into an array and iterate over it to initialize all
subsystems. This allows us to define the `git__shutdown_callbacks` array
with the same size as the initializer array and rids us of the need to
always update `MAX_SHUTDOWN_CB`.
</pre>
</div>
</content>
</entry>
<entry>
<title>stream: provide generic registration API</title>
<updated>2018-11-28T15:46:57+00:00</updated>
<author>
<name>Edward Thomson</name>
<email>ethomson@edwardthomson.com</email>
</author>
<published>2018-11-18T10:29:07+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/libgit2.git/commit/?id=df2cc1087f6de8718319e5bcc65ca8e0e07b717e'/>
<id>df2cc1087f6de8718319e5bcc65ca8e0e07b717e</id>
<content type='text'>
Update the new stream registration API to be `git_stream_register`
which takes a registration structure and a TLS boolean.  This allows
callers to register non-TLS streams as well as TLS streams.

Provide `git_stream_register_tls` that takes just the init callback for
backward compatibliity.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Update the new stream registration API to be `git_stream_register`
which takes a registration structure and a TLS boolean.  This allows
callers to register non-TLS streams as well as TLS streams.

Provide `git_stream_register_tls` that takes just the init callback for
backward compatibliity.
</pre>
</div>
</content>
</entry>
<entry>
<title>http: remove cURL</title>
<updated>2018-11-28T15:46:57+00:00</updated>
<author>
<name>Edward Thomson</name>
<email>ethomson@edwardthomson.com</email>
</author>
<published>2018-10-29T10:04:48+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/libgit2.git/commit/?id=21142c5a61fca0d44cbf51824dbe28f6324229e8'/>
<id>21142c5a61fca0d44cbf51824dbe28f6324229e8</id>
<content type='text'>
We previously used cURL to support HTTP proxies.  Now that we've added
this support natively, we can remove the curl dependency.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We previously used cURL to support HTTP proxies.  Now that we've added
this support natively, we can remove the curl dependency.
</pre>
</div>
</content>
</entry>
<entry>
<title>tls: introduce a wrap function</title>
<updated>2018-11-28T15:46:57+00:00</updated>
<author>
<name>Edward Thomson</name>
<email>ethomson@edwardthomson.com</email>
</author>
<published>2018-10-25T07:49:01+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/libgit2.git/commit/?id=43b592ac84dbd3d649022ff9503f00ecc83d5278'/>
<id>43b592ac84dbd3d649022ff9503f00ecc83d5278</id>
<content type='text'>
Introduce `git_tls_stream_wrap` which will take an existing `stream`
with an already connected socket and begin speaking TLS on top of it.
This is useful if you've built a connection to a proxy server and you
wish to begin CONNECT over it to tunnel a TLS connection.

Also update the pluggable TLS stream layer so that it can accept a
registration structure that provides an `init` and `wrap` function,
instead of a single initialization function.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Introduce `git_tls_stream_wrap` which will take an existing `stream`
with an already connected socket and begin speaking TLS on top of it.
This is useful if you've built a connection to a proxy server and you
wish to begin CONNECT over it to tunnel a TLS connection.

Also update the pluggable TLS stream layer so that it can accept a
registration structure that provides an `init` and `wrap` function,
instead of a single initialization function.
</pre>
</div>
</content>
</entry>
<entry>
<title>alloc: make memory allocators use function pointers</title>
<updated>2018-06-07T10:57:39+00:00</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2018-03-20T14:23:49+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/libgit2.git/commit/?id=9865cd1696ac4a3f47991a9a1d79b17cef5edc89'/>
<id>9865cd1696ac4a3f47991a9a1d79b17cef5edc89</id>
<content type='text'>
Currently, our memory allocators are being redirected to the correct
implementation at compile time by simply using macros. In order to make
them swappable at runtime, this commit reshuffles that by instead making
use of a global "git_allocator" structure, whose pointers are set up to
reference the allocator functions. Like this, it becomes easy to swap
out allocators by simply setting these function pointers.

In order to initialize a "git_allocator", our provided allocators
"stdalloc" and "crtdbg" both provide an init function. This is being
called to initialize a passed in allocator struct and set up its members
correctly.

No support is yet included to enable users of libgit2 to switch out the
memory allocator at a global level.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Currently, our memory allocators are being redirected to the correct
implementation at compile time by simply using macros. In order to make
them swappable at runtime, this commit reshuffles that by instead making
use of a global "git_allocator" structure, whose pointers are set up to
reference the allocator functions. Like this, it becomes easy to swap
out allocators by simply setting these function pointers.

In order to initialize a "git_allocator", our provided allocators
"stdalloc" and "crtdbg" both provide an init function. This is being
called to initialize a passed in allocator struct and set up its members
correctly.

No support is yet included to enable users of libgit2 to switch out the
memory allocator at a global level.
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge pull request #4645 from pks-t/pks/racy-init-deinit</title>
<updated>2018-05-09T12:06:57+00:00</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2018-05-09T12:06:57+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/libgit2.git/commit/?id=81c9894f3f80a58c6b078549105ecd571c16b567'/>
<id>81c9894f3f80a58c6b078549105ecd571c16b567</id>
<content type='text'>
global: adjust init count under lock</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
global: adjust init count under lock</pre>
</div>
</content>
</entry>
<entry>
<title>global: adjust init count under lock</title>
<updated>2018-05-04T12:40:54+00:00</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2018-05-04T12:40:54+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/libgit2.git/commit/?id=0933fdc5f5db346ff0fe9e1614bf2a54e96acba9'/>
<id>0933fdc5f5db346ff0fe9e1614bf2a54e96acba9</id>
<content type='text'>
Our global initialization functions `git_libgit2_init()` and
`git_libgit2_shutdown()` both adjust a global init counter to determine
whether we are the first respectively last user of libgit2. On
Unix-systems do not do so under lock, though, which opens the
possibility of a race between these two functions:

    Thread 1                            Thread 2
                            git__n_inits = 0;
    git_libgit2_init();
    git_atomic_inc(&amp;git__n_inits);
    /* git__n_inits == 1 */
                                        git_libgit2_shutdown();
                                        if (git_atomic_dec(&amp;git__n_inits) != 0)
                                            /* git__n_inits == 0, no early exit here */
                                        pthread_mutex_lock(&amp;_init_mutex);
                                        shutdown_common();
                                        pthread_mutex_unlock(&amp;_init_mutex);
    pthread_mutex_lock(&amp;_init_mutex);
    init_once();
    pthread_mutex_unlock(&amp;_init_mutex);

So we can end up in a situation where we try to shutdown shared data
structures before they have been initialized.

Fix the race by always locking `_init_mutex` before incrementing or
decrementing `git__n_inits`.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Our global initialization functions `git_libgit2_init()` and
`git_libgit2_shutdown()` both adjust a global init counter to determine
whether we are the first respectively last user of libgit2. On
Unix-systems do not do so under lock, though, which opens the
possibility of a race between these two functions:

    Thread 1                            Thread 2
                            git__n_inits = 0;
    git_libgit2_init();
    git_atomic_inc(&amp;git__n_inits);
    /* git__n_inits == 1 */
                                        git_libgit2_shutdown();
                                        if (git_atomic_dec(&amp;git__n_inits) != 0)
                                            /* git__n_inits == 0, no early exit here */
                                        pthread_mutex_lock(&amp;_init_mutex);
                                        shutdown_common();
                                        pthread_mutex_unlock(&amp;_init_mutex);
    pthread_mutex_lock(&amp;_init_mutex);
    init_once();
    pthread_mutex_unlock(&amp;_init_mutex);

So we can end up in a situation where we try to shutdown shared data
structures before they have been initialized.

Fix the race by always locking `_init_mutex` before incrementing or
decrementing `git__n_inits`.
</pre>
</div>
</content>
</entry>
<entry>
<title>mbedtls: add global initialization</title>
<updated>2018-04-11T19:02:43+00:00</updated>
<author>
<name>Etienne Samson</name>
<email>samson.etienne@gmail.com</email>
</author>
<published>2018-03-29T20:14:01+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/libgit2.git/commit/?id=60e1ad927b7f64ad33681fc162b512e2cf12b5b8'/>
<id>60e1ad927b7f64ad33681fc162b512e2cf12b5b8</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>curl: explicitly initialize and cleanup global curl state</title>
<updated>2018-02-28T13:27:07+00:00</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2018-02-28T12:06:59+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/libgit2.git/commit/?id=2022b00447a9edaa7caa712431c4888bbb1e0f67'/>
<id>2022b00447a9edaa7caa712431c4888bbb1e0f67</id>
<content type='text'>
Our curl-based streams make use of the easy curl interface. This
interface automatically initializes and de-initializes the global curl
state by calling out to `curl_global_init` and `curl_global_cleanup`.
Thus, all global state will be repeatedly re-initialized when creating
multiple curl streams in succession. Despite being inefficient, this is
not thread-safe due to `curl_global_init` being not thread-safe itself.
Thus a multi-threaded programing handling multiple curl streams at the
same time is inherently racy.

Fix the issue by globally initializing and cleaning up curl's state.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Our curl-based streams make use of the easy curl interface. This
interface automatically initializes and de-initializes the global curl
state by calling out to `curl_global_init` and `curl_global_cleanup`.
Thus, all global state will be repeatedly re-initialized when creating
multiple curl streams in succession. Despite being inefficient, this is
not thread-safe due to `curl_global_init` being not thread-safe itself.
Thus a multi-threaded programing handling multiple curl streams at the
same time is inherently racy.

Fix the issue by globally initializing and cleaning up curl's state.
</pre>
</div>
</content>
</entry>
<entry>
<title>stream: Gather streams to src/streams</title>
<updated>2017-10-23T18:02:35+00:00</updated>
<author>
<name>Etienne Samson</name>
<email>samson.etienne@gmail.com</email>
</author>
<published>2017-03-20T23:25:15+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/libgit2.git/commit/?id=e93698561145c5d1f66d9f3c8d3b84775a9e5556'/>
<id>e93698561145c5d1f66d9f3c8d3b84775a9e5556</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
</feed>
