Skip to content

Commit 4853d94

Browse files
committed
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.
1 parent bc3919a commit 4853d94

File tree

7 files changed

+258
-239
lines changed

7 files changed

+258
-239
lines changed

src/errors.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "common.h"
99

10-
#include "global.h"
10+
#include "threadstate.h"
1111
#include "posix.h"
1212
#include "buffer.h"
1313

@@ -22,18 +22,18 @@ static git_error g_git_oom_error = {
2222

2323
static void set_error_from_buffer(int error_class)
2424
{
25-
git_error *error = &GIT_GLOBAL->error_t;
26-
git_buf *buf = &GIT_GLOBAL->error_buf;
25+
git_error *error = &GIT_THREADSTATE->error_t;
26+
git_buf *buf = &GIT_THREADSTATE->error_buf;
2727

2828
error->message = buf->ptr;
2929
error->klass = error_class;
3030

31-
GIT_GLOBAL->last_error = error;
31+
GIT_THREADSTATE->last_error = error;
3232
}
3333

3434
static void set_error(int error_class, char *string)
3535
{
36-
git_buf *buf = &GIT_GLOBAL->error_buf;
36+
git_buf *buf = &GIT_THREADSTATE->error_buf;
3737

3838
git_buf_clear(buf);
3939
if (string) {
@@ -46,7 +46,7 @@ static void set_error(int error_class, char *string)
4646

4747
void git_error_set_oom(void)
4848
{
49-
GIT_GLOBAL->last_error = &g_git_oom_error;
49+
GIT_THREADSTATE->last_error = &g_git_oom_error;
5050
}
5151

5252
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)
6464
DWORD win32_error_code = (error_class == GIT_ERROR_OS) ? GetLastError() : 0;
6565
#endif
6666
int error_code = (error_class == GIT_ERROR_OS) ? errno : 0;
67-
git_buf *buf = &GIT_GLOBAL->error_buf;
67+
git_buf *buf = &GIT_THREADSTATE->error_buf;
6868

6969
git_buf_clear(buf);
7070
if (fmt) {
@@ -97,7 +97,7 @@ void git_error_vset(int error_class, const char *fmt, va_list ap)
9797

9898
int git_error_set_str(int error_class, const char *string)
9999
{
100-
git_buf *buf = &GIT_GLOBAL->error_buf;
100+
git_buf *buf = &GIT_THREADSTATE->error_buf;
101101

102102
assert(string);
103103

@@ -118,9 +118,9 @@ int git_error_set_str(int error_class, const char *string)
118118

119119
void git_error_clear(void)
120120
{
121-
if (GIT_GLOBAL->last_error != NULL) {
121+
if (GIT_THREADSTATE->last_error != NULL) {
122122
set_error(0, NULL);
123-
GIT_GLOBAL->last_error = NULL;
123+
GIT_THREADSTATE->last_error = NULL;
124124
}
125125

126126
errno = 0;
@@ -131,13 +131,13 @@ void git_error_clear(void)
131131

132132
const git_error *git_error_last(void)
133133
{
134-
return GIT_GLOBAL->last_error;
134+
return GIT_THREADSTATE->last_error;
135135
}
136136

137137
int git_error_state_capture(git_error_state *state, int error_code)
138138
{
139-
git_error *error = GIT_GLOBAL->last_error;
140-
git_buf *error_buf = &GIT_GLOBAL->error_buf;
139+
git_error *error = GIT_THREADSTATE->last_error;
140+
git_buf *error_buf = &GIT_THREADSTATE->error_buf;
141141

142142
memset(state, 0, sizeof(git_error_state));
143143

0 commit comments

Comments
 (0)