Commit 1265986b by Edward Thomson

oid: move thread local storage into oid.c

Now that thread-local error data is handled in error, move the thread
local data out of the `threadstate` object, since it has now become
useless indirection.
parent 36b52506
......@@ -76,6 +76,7 @@ int git_libgit2_init(void)
git_error_global_init,
git_threadstate_global_init,
git_threads_global_init,
git_oid_global_init,
git_rand_global_init,
git_hash_global_init,
git_sysdir_global_init,
......
......@@ -9,7 +9,7 @@
#include "git2/oid.h"
#include "repository.h"
#include "threadstate.h"
#include "runtime.h"
#include <string.h>
#include <limits.h>
......@@ -153,15 +153,42 @@ int git_oid_pathfmt(char *str, const git_oid *oid)
return 0;
}
static git_tlsdata_key thread_str_key;
static void GIT_SYSTEM_CALL thread_str_free(void *s)
{
char *str = (char *)s;
git__free(str);
}
static void thread_str_global_shutdown(void)
{
char *str = git_tlsdata_get(thread_str_key);
git_tlsdata_set(thread_str_key, NULL);
git__free(str);
git_tlsdata_dispose(thread_str_key);
}
int git_oid_global_init(void)
{
if (git_tlsdata_init(&thread_str_key, thread_str_free) != 0)
return -1;
return git_runtime_shutdown_register(thread_str_global_shutdown);
}
char *git_oid_tostr_s(const git_oid *oid)
{
git_threadstate *threadstate = git_threadstate_get();
char *str;
if (!threadstate)
if ((str = git_tlsdata_get(thread_str_key)) == NULL) {
if ((str = git__malloc(GIT_OID_MAX_HEXSIZE + 1)) == NULL)
return NULL;
str = threadstate->oid_fmt;
git_tlsdata_set(thread_str_key, str);
}
git_oid_nfmt(str, git_oid_hexsize(git_oid_type(oid)) + 1, oid);
return str;
}
......
......@@ -270,4 +270,6 @@ int git_oid__fromstrn(
int git_oid__fromraw(git_oid *out, const unsigned char *raw, git_oid_t type);
int git_oid_global_init(void);
#endif
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