Commit 8aa69f88 by Edward Thomson

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.
parent 6554b40e
......@@ -9,6 +9,7 @@
#include "global.h"
#include "strmap.h"
#include "hash.h"
#include <ctype.h>
#if GIT_WIN32
#include "win32/findfile.h"
......
......@@ -12,6 +12,7 @@
#include "sysdir.h"
#include "filter.h"
#include "settings.h"
#include "mwindow.h"
#include "merge_driver.h"
#include "pool.h"
#include "streams/registry.h"
......@@ -22,8 +23,6 @@
#include "transports/ssh.h"
#include "win32/w32_stack.h"
git_mutex git__mwindow_mutex;
typedef int (*git_global_init_fn)(void);
static git_global_init_fn git__init_callbacks[] = {
......@@ -147,9 +146,6 @@ static int synchronized_threads_init(void)
if ((_fls_index = FlsAlloc(fls_free)) == FLS_OUT_OF_INDEXES)
return -1;
if (git_mutex_init(&git__mwindow_mutex))
return -1;
error = init_common();
return error;
......@@ -186,7 +182,6 @@ int git_libgit2_shutdown(void)
shutdown_common();
FlsFree(_fls_index);
git_mutex_free(&git__mwindow_mutex);
}
/* Exit the lock */
......@@ -229,11 +224,7 @@ static void cb__free_status(void *st)
static void init_once(void)
{
if ((init_error = git_mutex_init(&git__mwindow_mutex)) != 0)
return;
pthread_key_create(&_tls_key, &cb__free_status);
init_error = init_common();
}
......@@ -276,7 +267,6 @@ int git_libgit2_shutdown(void)
git__free(ptr);
pthread_key_delete(_tls_key);
git_mutex_free(&git__mwindow_mutex);
_once_init = new_once;
out:
......
......@@ -9,9 +9,6 @@
#include "common.h"
#include "mwindow.h"
#include "hash.h"
typedef struct {
git_error *last_error;
git_error error_t;
......@@ -27,8 +24,6 @@ typedef struct {
git_global_st *git__global_state(void);
extern git_mutex git__mwindow_mutex;
#define GIT_GLOBAL (git__global_state())
typedef void (*git_global_shutdown_fn)(void);
......
......@@ -29,16 +29,21 @@ size_t git_mwindow__window_size = DEFAULT_WINDOW_SIZE;
size_t git_mwindow__mapped_limit = DEFAULT_MAPPED_LIMIT;
size_t git_mwindow__file_limit = DEFAULT_FILE_LIMIT;
/* Mutex to control access */
git_mutex git__mwindow_mutex;
/* Whenever you want to read or modify this, grab git__mwindow_mutex */
git_mwindow_ctl git_mwindow__mem_ctl;
/* Global list of mwindow files, to open packs once across repos */
git_strmap *git__pack_cache = NULL;
static void git_mwindow_files_free(void)
static void git_mwindow_global_shutdown(void)
{
git_strmap *tmp = git__pack_cache;
git_mutex_free(&git__mwindow_mutex);
git__pack_cache = NULL;
git_strmap_free(tmp);
}
......@@ -47,7 +52,11 @@ int git_mwindow_global_init(void)
{
assert(!git__pack_cache);
git__on_shutdown(git_mwindow_files_free);
git__on_shutdown(git_mwindow_global_shutdown);
if (git_mutex_init(&git__mwindow_mutex) != 0)
return -1;
return git_strmap_new(&git__pack_cache);
}
......
......@@ -13,6 +13,8 @@
#include "map.h"
#include "vector.h"
extern git_mutex git__mwindow_mutex;
typedef struct git_mwindow {
struct git_mwindow *next;
git_map window_map;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment