Skip to content

Commit 8aa69f8

Browse files
committed
mwindow: localize mutex
Move the mwindow mutex into the mwindow code itself, initializing it in the mwindow global initialization function instead of in the global initializer.
1 parent 6554b40 commit 8aa69f8

File tree

5 files changed

+15
-18
lines changed

5 files changed

+15
-18
lines changed

src/futils.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "global.h"
1111
#include "strmap.h"
12+
#include "hash.h"
1213
#include <ctype.h>
1314
#if GIT_WIN32
1415
#include "win32/findfile.h"

src/global.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "sysdir.h"
1313
#include "filter.h"
1414
#include "settings.h"
15+
#include "mwindow.h"
1516
#include "merge_driver.h"
1617
#include "pool.h"
1718
#include "streams/registry.h"
@@ -22,8 +23,6 @@
2223
#include "transports/ssh.h"
2324
#include "win32/w32_stack.h"
2425

25-
git_mutex git__mwindow_mutex;
26-
2726
typedef int (*git_global_init_fn)(void);
2827

2928
static git_global_init_fn git__init_callbacks[] = {
@@ -147,9 +146,6 @@ static int synchronized_threads_init(void)
147146
if ((_fls_index = FlsAlloc(fls_free)) == FLS_OUT_OF_INDEXES)
148147
return -1;
149148

150-
if (git_mutex_init(&git__mwindow_mutex))
151-
return -1;
152-
153149
error = init_common();
154150

155151
return error;
@@ -186,7 +182,6 @@ int git_libgit2_shutdown(void)
186182
shutdown_common();
187183

188184
FlsFree(_fls_index);
189-
git_mutex_free(&git__mwindow_mutex);
190185
}
191186

192187
/* Exit the lock */
@@ -229,11 +224,7 @@ static void cb__free_status(void *st)
229224

230225
static void init_once(void)
231226
{
232-
if ((init_error = git_mutex_init(&git__mwindow_mutex)) != 0)
233-
return;
234-
235227
pthread_key_create(&_tls_key, &cb__free_status);
236-
237228
init_error = init_common();
238229
}
239230

@@ -276,7 +267,6 @@ int git_libgit2_shutdown(void)
276267
git__free(ptr);
277268

278269
pthread_key_delete(_tls_key);
279-
git_mutex_free(&git__mwindow_mutex);
280270
_once_init = new_once;
281271

282272
out:

src/global.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
#include "common.h"
1111

12-
#include "mwindow.h"
13-
#include "hash.h"
14-
1512
typedef struct {
1613
git_error *last_error;
1714
git_error error_t;
@@ -27,8 +24,6 @@ typedef struct {
2724

2825
git_global_st *git__global_state(void);
2926

30-
extern git_mutex git__mwindow_mutex;
31-
3227
#define GIT_GLOBAL (git__global_state())
3328

3429
typedef void (*git_global_shutdown_fn)(void);

src/mwindow.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,21 @@ size_t git_mwindow__window_size = DEFAULT_WINDOW_SIZE;
2929
size_t git_mwindow__mapped_limit = DEFAULT_MAPPED_LIMIT;
3030
size_t git_mwindow__file_limit = DEFAULT_FILE_LIMIT;
3131

32+
/* Mutex to control access */
33+
git_mutex git__mwindow_mutex;
34+
3235
/* Whenever you want to read or modify this, grab git__mwindow_mutex */
3336
git_mwindow_ctl git_mwindow__mem_ctl;
3437

3538
/* Global list of mwindow files, to open packs once across repos */
3639
git_strmap *git__pack_cache = NULL;
3740

38-
static void git_mwindow_files_free(void)
41+
static void git_mwindow_global_shutdown(void)
3942
{
4043
git_strmap *tmp = git__pack_cache;
4144

45+
git_mutex_free(&git__mwindow_mutex);
46+
4247
git__pack_cache = NULL;
4348
git_strmap_free(tmp);
4449
}
@@ -47,7 +52,11 @@ int git_mwindow_global_init(void)
4752
{
4853
assert(!git__pack_cache);
4954

50-
git__on_shutdown(git_mwindow_files_free);
55+
git__on_shutdown(git_mwindow_global_shutdown);
56+
57+
if (git_mutex_init(&git__mwindow_mutex) != 0)
58+
return -1;
59+
5160
return git_strmap_new(&git__pack_cache);
5261
}
5362

src/mwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "map.h"
1414
#include "vector.h"
1515

16+
extern git_mutex git__mwindow_mutex;
17+
1618
typedef struct git_mwindow {
1719
struct git_mwindow *next;
1820
git_map window_map;

0 commit comments

Comments
 (0)