diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2020-05-14 10:36:35 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2020-10-11 20:06:15 +0100 |
commit | 4853d94ca47a6f1ecaa7c24b9034ededcb7e5bff (patch) | |
tree | 8c188e634e95762246ddcb4775aee7efae4fad27 /src/errors.c | |
parent | bc3919abc716088cf7c33bc08d48ee2bc434c398 (diff) | |
download | libgit2-4853d94ca47a6f1ecaa7c24b9034ededcb7e5bff.tar.gz |
global: separate global state from thread-local state
Our "global initialization" has accumulated some debris over the years.
It was previously responsible for both running the various global
initializers (that set up various subsystems) _and_ setting up the
"global state", which is actually the thread-local state for things
like error reporting.
Separate the thread local state out into "threadstate". Use the normal
subsystem initialization functions that we already have to set it up.
This makes both the global initialization system and the threadstate
system simpler to reason about.
Diffstat (limited to 'src/errors.c')
-rw-r--r-- | src/errors.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/errors.c b/src/errors.c index 8570226b4..d4da50da8 100644 --- a/src/errors.c +++ b/src/errors.c @@ -7,7 +7,7 @@ #include "common.h" -#include "global.h" +#include "threadstate.h" #include "posix.h" #include "buffer.h" @@ -22,18 +22,18 @@ static git_error g_git_oom_error = { static void set_error_from_buffer(int error_class) { - git_error *error = &GIT_GLOBAL->error_t; - git_buf *buf = &GIT_GLOBAL->error_buf; + git_error *error = &GIT_THREADSTATE->error_t; + git_buf *buf = &GIT_THREADSTATE->error_buf; error->message = buf->ptr; error->klass = error_class; - GIT_GLOBAL->last_error = error; + GIT_THREADSTATE->last_error = error; } static void set_error(int error_class, char *string) { - git_buf *buf = &GIT_GLOBAL->error_buf; + git_buf *buf = &GIT_THREADSTATE->error_buf; git_buf_clear(buf); if (string) { @@ -46,7 +46,7 @@ static void set_error(int error_class, char *string) void git_error_set_oom(void) { - GIT_GLOBAL->last_error = &g_git_oom_error; + GIT_THREADSTATE->last_error = &g_git_oom_error; } void git_error_set(int error_class, const char *fmt, ...) @@ -64,7 +64,7 @@ void git_error_vset(int error_class, const char *fmt, va_list ap) DWORD win32_error_code = (error_class == GIT_ERROR_OS) ? GetLastError() : 0; #endif int error_code = (error_class == GIT_ERROR_OS) ? errno : 0; - git_buf *buf = &GIT_GLOBAL->error_buf; + git_buf *buf = &GIT_THREADSTATE->error_buf; git_buf_clear(buf); if (fmt) { @@ -97,7 +97,7 @@ void git_error_vset(int error_class, const char *fmt, va_list ap) int git_error_set_str(int error_class, const char *string) { - git_buf *buf = &GIT_GLOBAL->error_buf; + git_buf *buf = &GIT_THREADSTATE->error_buf; assert(string); @@ -118,9 +118,9 @@ int git_error_set_str(int error_class, const char *string) void git_error_clear(void) { - if (GIT_GLOBAL->last_error != NULL) { + if (GIT_THREADSTATE->last_error != NULL) { set_error(0, NULL); - GIT_GLOBAL->last_error = NULL; + GIT_THREADSTATE->last_error = NULL; } errno = 0; @@ -131,13 +131,13 @@ void git_error_clear(void) const git_error *git_error_last(void) { - return GIT_GLOBAL->last_error; + return GIT_THREADSTATE->last_error; } int git_error_state_capture(git_error_state *state, int error_code) { - git_error *error = GIT_GLOBAL->last_error; - git_buf *error_buf = &GIT_GLOBAL->error_buf; + git_error *error = GIT_THREADSTATE->last_error; + git_buf *error_buf = &GIT_THREADSTATE->error_buf; memset(state, 0, sizeof(git_error_state)); |