Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
36bfc27a
Unverified
Commit
36bfc27a
authored
Dec 01, 2019
by
Edward Thomson
Committed by
GitHub
Dec 01, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5314 from pks-t/pks/dll-main-removal
global: convert to fiber-local storage to fix exit races
parents
d298f9b2
5c6180b5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
47 deletions
+12
-47
src/global.c
+12
-40
src/global.h
+0
-2
src/win32/thread.c
+0
-5
No files found.
src/global.c
View file @
36bfc27a
...
...
@@ -141,14 +141,21 @@ static void shutdown_common(void)
*/
#if defined(GIT_THREADS) && defined(GIT_WIN32)
static
DWORD
_
t
ls_index
;
static
DWORD
_
f
ls_index
;
static
volatile
LONG
_mutex
=
0
;
static
void
WINAPI
fls_free
(
void
*
st
)
{
git__global_state_cleanup
(
st
);
git__free
(
st
);
}
static
int
synchronized_threads_init
(
void
)
{
int
error
;
_tls_index
=
TlsAlloc
();
if
((
_fls_index
=
FlsAlloc
(
fls_free
))
==
FLS_OUT_OF_INDEXES
)
return
-
1
;
git_threads_init
();
...
...
@@ -190,9 +197,7 @@ int git_libgit2_shutdown(void)
if
((
ret
=
git_atomic_dec
(
&
git__n_inits
))
==
0
)
{
shutdown_common
();
git__free_tls_data
();
TlsFree
(
_tls_index
);
FlsFree
(
_fls_index
);
git_mutex_free
(
&
git__mwindow_mutex
);
#if defined(GIT_MSVC_CRTDBG)
...
...
@@ -213,7 +218,7 @@ git_global_st *git__global_state(void)
assert
(
git_atomic_get
(
&
git__n_inits
)
>
0
);
if
((
ptr
=
TlsGetValue
(
_t
ls_index
))
!=
NULL
)
if
((
ptr
=
FlsGetValue
(
_f
ls_index
))
!=
NULL
)
return
ptr
;
ptr
=
git__calloc
(
1
,
sizeof
(
git_global_st
));
...
...
@@ -222,43 +227,10 @@ git_global_st *git__global_state(void)
git_buf_init
(
&
ptr
->
error_buf
,
0
);
TlsSetValue
(
_t
ls_index
,
ptr
);
FlsSetValue
(
_f
ls_index
,
ptr
);
return
ptr
;
}
/**
* Free the TLS data associated with this thread.
* This should only be used by the thread as it
* is exiting.
*/
void
git__free_tls_data
(
void
)
{
void
*
ptr
=
TlsGetValue
(
_tls_index
);
if
(
!
ptr
)
return
;
git__global_state_cleanup
(
ptr
);
git__free
(
ptr
);
TlsSetValue
(
_tls_index
,
NULL
);
}
BOOL
WINAPI
DllMain
(
HINSTANCE
hInstDll
,
DWORD
fdwReason
,
LPVOID
lpvReserved
)
{
GIT_UNUSED
(
hInstDll
);
GIT_UNUSED
(
lpvReserved
);
/* This is how Windows lets us know our thread is being shut down */
if
(
fdwReason
==
DLL_THREAD_DETACH
)
{
git__free_tls_data
();
}
/*
* Windows pays attention to this during library loading. We don't do anything
* so we trivially succeed.
*/
return
TRUE
;
}
#elif defined(GIT_THREADS) && defined(_POSIX_THREADS)
static
pthread_key_t
_tls_key
;
...
...
src/global.h
View file @
36bfc27a
...
...
@@ -35,8 +35,6 @@ typedef void (*git_global_shutdown_fn)(void);
extern
void
git__on_shutdown
(
git_global_shutdown_fn
callback
);
extern
void
git__free_tls_data
(
void
);
extern
const
char
*
git_libgit2__user_agent
(
void
);
extern
const
char
*
git_libgit2__ssl_ciphers
(
void
);
...
...
src/win32/thread.c
View file @
36bfc27a
...
...
@@ -32,8 +32,6 @@ static DWORD WINAPI git_win32__threadproc(LPVOID lpParameter)
thread
->
result
=
thread
->
proc
(
thread
->
param
);
git__free_tls_data
();
return
CLEAN_THREAD_EXIT
;
}
...
...
@@ -103,9 +101,6 @@ void git_thread_exit(void *value)
{
assert
(
GIT_GLOBAL
->
current_thread
);
GIT_GLOBAL
->
current_thread
->
result
=
value
;
git__free_tls_data
();
ExitThread
(
CLEAN_THREAD_EXIT
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment