]> git.proxmox.com Git - libgit2.git/blame - src/runtime.h
New upstream version 1.4.3+dfsg.1
[libgit2.git] / src / runtime.h
CommitLineData
c25aa7cd
PP
1/*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7#ifndef INCLUDE_runtime_h__
8#define INCLUDE_runtime_h__
9
10#include "common.h"
11
12typedef int (*git_runtime_init_fn)(void);
13typedef void (*git_runtime_shutdown_fn)(void);
14
15/**
16 * Start up a new runtime. If this is the first time that this
17 * function is called within the context of the current library
18 * or executable, then the given `init_fns` will be invoked. If
19 * it is not the first time, they will be ignored.
20 *
21 * The given initialization functions _may_ register shutdown
22 * handlers using `git_runtime_shutdown_register` to be notified
23 * when the runtime is shutdown.
24 *
25 * @param init_fns The list of initialization functions to call
26 * @param cnt The number of init_fns
27 * @return The number of initializations performed (including this one) or an error
28 */
29int git_runtime_init(git_runtime_init_fn init_fns[], size_t cnt);
30
31/*
32 * Returns the number of initializations active (the number of calls to
33 * `git_runtime_init` minus the number of calls sto `git_runtime_shutdown`).
34 * If 0, the runtime is not currently initialized.
35 *
36 * @return The number of initializations performed or an error
37 */
38int git_runtime_init_count(void);
39
40/**
41 * Shut down the runtime. If this is the last shutdown call,
42 * such that there are no remaining `init` calls, then any
43 * shutdown hooks that have been registered will be invoked.
44 *
45 * The number of outstanding initializations will be returned.
46 * If this number is 0, then the runtime is shutdown.
47 *
48 * @return The number of outstanding initializations (after this one) or an error
49 */
50int git_runtime_shutdown(void);
51
52/**
53 * Register a shutdown handler for this runtime. This should be done
54 * by a function invoked by `git_runtime_init` to ensure that the
55 * appropriate locks are taken.
56 *
57 * @param callback The shutdown handler callback
58 * @return 0 or an error code
59 */
60int git_runtime_shutdown_register(git_runtime_shutdown_fn callback);
61
62#endif