diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2020-07-11 14:24:17 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2020-10-25 16:49:41 +0000 |
commit | e3f8928982c044274453111a64d4231c0eb464c4 (patch) | |
tree | c358498634dc2303305f525905b05bd5f35531a7 | |
parent | 52294c413100ed4930764addc69beadd82382a4c (diff) | |
download | libgit2-e3f8928982c044274453111a64d4231c0eb464c4.tar.gz |
libgit2: provide init_count of the library
A function to provide the initialization count of the library; this is
subject to race conditions but is useful for a naive determination as to
whether the library has been initialized or not.
-rw-r--r-- | src/libgit2.c | 5 | ||||
-rw-r--r-- | src/libgit2.h | 2 | ||||
-rw-r--r-- | src/runtime.c | 5 | ||||
-rw-r--r-- | src/runtime.h | 9 |
4 files changed, 21 insertions, 0 deletions
diff --git a/src/libgit2.c b/src/libgit2.c index 316d89365..7bc578666 100644 --- a/src/libgit2.c +++ b/src/libgit2.c @@ -84,6 +84,11 @@ int git_libgit2_init(void) return git_runtime_init(init_fns, ARRAY_SIZE(init_fns)); } +int git_libgit2_init_count(void) +{ + return git_runtime_init_count(); +} + int git_libgit2_shutdown(void) { return git_runtime_shutdown(); diff --git a/src/libgit2.h b/src/libgit2.h index 6f92a8318..a898367ae 100644 --- a/src/libgit2.h +++ b/src/libgit2.h @@ -7,6 +7,8 @@ #ifndef INCLUDE_libgit2_h__ #define INCLUDE_libgit2_h__ +extern int git_libgit2_init_count(void); + extern const char *git_libgit2__user_agent(void); extern const char *git_libgit2__ssl_ciphers(void); diff --git a/src/runtime.c b/src/runtime.c index 56110c49a..b496a52f2 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -127,6 +127,11 @@ int git_runtime_init(git_runtime_init_fn init_fns[], size_t cnt) return ret; } +int git_runtime_init_count(void) +{ + return git_atomic_get(&init_count); +} + int git_runtime_shutdown(void) { int ret; diff --git a/src/runtime.h b/src/runtime.h index be2e37a60..2cbcafe52 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -28,6 +28,15 @@ typedef void (*git_runtime_shutdown_fn)(void); */ int git_runtime_init(git_runtime_init_fn init_fns[], size_t cnt); +/* + * Returns the number of initializations active (the number of calls to + * `git_runtime_init` minus the number of calls sto `git_runtime_shutdown`). + * If 0, the runtime is not currently initialized. + * + * @return The number of initializations performed or an error + */ +int git_runtime_init_count(void); + /** * Shut down the runtime. If this is the last shutdown call, * such that there are no remaining `init` calls, then any |