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
faebc1c6
Commit
faebc1c6
authored
Jun 20, 2016
by
Patrick Steinhardt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
threads: split up OS-dependent thread code
parent
69c71f29
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
37 additions
and
45 deletions
+37
-45
src/pack-objects.c
+1
-1
src/thread-utils.h
+2
-11
src/unix/pthread.h
+20
-0
src/win32/pthread.c
+5
-8
src/win32/pthread.h
+3
-19
tests/object/cache.c
+2
-2
tests/threads/refdb.c
+3
-3
tests/threads/thread_helpers.c
+1
-1
No files found.
src/pack-objects.c
View file @
faebc1c6
...
...
@@ -1186,7 +1186,7 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
git_mutex_init
(
&
p
[
i
].
mutex
);
git_cond_init
(
&
p
[
i
].
cond
);
ret
=
git_thread_create
(
&
p
[
i
].
thread
,
NULL
,
ret
=
git_thread_create
(
&
p
[
i
].
thread
,
threaded_find_deltas
,
&
p
[
i
]);
if
(
ret
)
{
giterr_set
(
GITERR_THREAD
,
"unable to create thread"
);
...
...
src/thread-utils.h
View file @
faebc1c6
...
...
@@ -41,16 +41,7 @@ typedef git_atomic git_atomic_ssize;
#ifdef GIT_THREADS
#if !defined(GIT_WIN32)
typedef
struct
{
pthread_t
thread
;
}
git_thread
;
#define git_thread_create(git_thread_ptr, attr, start_routine, arg) \
pthread_create(&(git_thread_ptr)->thread, attr, start_routine, arg)
#define git_thread_join(git_thread_ptr, status) \
pthread_join((git_thread_ptr)->thread, status)
# include "unix/pthread.h"
#endif
/* Pthreads Mutex */
...
...
@@ -178,7 +169,7 @@ GIT_INLINE(int64_t) git_atomic64_add(git_atomic64 *a, int64_t addend)
#else
#define git_thread unsigned int
#define git_thread_create(thread,
attr,
start_routine, arg) 0
#define git_thread_create(thread, start_routine, arg) 0
#define git_thread_join(id, status) (void)0
/* Pthreads Mutex */
...
...
src/unix/pthread.h
0 → 100644
View file @
faebc1c6
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_unix_pthread_h__
#define INCLUDE_unix_pthread_h__
typedef
struct
{
pthread_t
thread
;
}
git_thread
;
#define git_thread_create(git_thread_ptr, start_routine, arg) \
pthread_create(&(git_thread_ptr)->thread, NULL, start_routine, arg)
#define git_thread_join(git_thread_ptr, status) \
pthread_join((git_thread_ptr)->thread, status)
#endif
/* INCLUDE_unix_pthread_h__ */
src/win32/pthread.c
View file @
faebc1c6
...
...
@@ -16,7 +16,7 @@
* void pointer. This requires the indirection. */
static
DWORD
WINAPI
git_win32__threadproc
(
LPVOID
lpParameter
)
{
git_
win32_
thread
*
thread
=
lpParameter
;
git_thread
*
thread
=
lpParameter
;
thread
->
result
=
thread
->
proc
(
thread
->
param
);
...
...
@@ -25,14 +25,11 @@ static DWORD WINAPI git_win32__threadproc(LPVOID lpParameter)
return
CLEAN_THREAD_EXIT
;
}
int
git_win32__thread_create
(
git_win32_thread
*
GIT_RESTRICT
thread
,
const
pthread_attr_t
*
GIT_RESTRICT
attr
,
int
git_thread_create
(
git_thread
*
GIT_RESTRICT
thread
,
void
*
(
*
start_routine
)(
void
*
),
void
*
GIT_RESTRICT
arg
)
{
GIT_UNUSED
(
attr
);
thread
->
result
=
NULL
;
thread
->
param
=
arg
;
thread
->
proc
=
start_routine
;
...
...
@@ -42,8 +39,8 @@ int git_win32__thread_create(
return
thread
->
thread
?
0
:
-
1
;
}
int
git_
win32__
thread_join
(
git_
win32_
thread
*
thread
,
int
git_thread_join
(
git_thread
*
thread
,
void
**
value_ptr
)
{
DWORD
exit
;
...
...
src/win32/pthread.h
View file @
faebc1c6
...
...
@@ -21,7 +21,7 @@ typedef struct {
void
*
(
*
proc
)(
void
*
);
void
*
param
;
void
*
result
;
}
git_
win32_
thread
;
}
git_thread
;
typedef
int
pthread_mutexattr_t
;
typedef
int
pthread_condattr_t
;
...
...
@@ -42,26 +42,10 @@ typedef struct {
#define PTHREAD_MUTEX_INITIALIZER {(void*)-1}
int
git_win32__thread_create
(
git_win32_thread
*
GIT_RESTRICT
,
const
pthread_attr_t
*
GIT_RESTRICT
,
int
git_thread_create
(
git_thread
*
GIT_RESTRICT
,
void
*
(
*
)
(
void
*
),
void
*
GIT_RESTRICT
);
int
git_win32__thread_join
(
git_win32_thread
*
,
void
**
);
#ifdef GIT_THREADS
typedef
git_win32_thread
git_thread
;
#define git_thread_create(git_thread_ptr, attr, start_routine, arg) \
git_win32__thread_create(git_thread_ptr, attr, start_routine, arg)
#define git_thread_join(git_thread_ptr, status) \
git_win32__thread_join(git_thread_ptr, status)
#endif
int
git_thread_join
(
git_thread
*
,
void
**
);
int
pthread_mutex_init
(
pthread_mutex_t
*
GIT_RESTRICT
mutex
,
...
...
tests/object/cache.c
View file @
faebc1c6
...
...
@@ -220,7 +220,7 @@ void test_object_cache__threadmania(void)
fn
=
(
th
&
1
)
?
cache_parsed
:
cache_raw
;
#ifdef GIT_THREADS
cl_git_pass
(
git_thread_create
(
&
t
[
th
],
NULL
,
fn
,
data
));
cl_git_pass
(
git_thread_create
(
&
t
[
th
],
fn
,
data
));
#else
cl_assert
(
fn
(
data
)
==
data
);
git__free
(
data
);
...
...
@@ -267,7 +267,7 @@ void test_object_cache__fast_thread_rush(void)
data
[
th
]
=
th
;
#ifdef GIT_THREADS
cl_git_pass
(
git_thread_create
(
&
t
[
th
],
NULL
,
cache_quick
,
&
data
[
th
]));
git_thread_create
(
&
t
[
th
],
cache_quick
,
&
data
[
th
]));
#else
cl_assert
(
cache_quick
(
&
data
[
th
])
==
&
data
[
th
]);
#endif
...
...
tests/threads/refdb.c
View file @
faebc1c6
...
...
@@ -75,7 +75,7 @@ void test_threads_refdb__iterator(void)
for
(
t
=
0
;
t
<
THREADS
;
++
t
)
{
id
[
t
]
=
t
;
#ifdef GIT_THREADS
cl_git_pass
(
git_thread_create
(
&
th
[
t
],
NULL
,
iterate_refs
,
&
id
[
t
]));
cl_git_pass
(
git_thread_create
(
&
th
[
t
],
iterate_refs
,
&
id
[
t
]));
#else
th
[
t
]
=
t
;
iterate_refs
(
&
id
[
t
]);
...
...
@@ -196,7 +196,7 @@ void test_threads_refdb__edit_while_iterate(void)
* for now by just running on a single thread...
*/
/* #ifdef GIT_THREADS */
/* cl_git_pass(git_thread_create(&th[t],
NULL,
fn, &id[t])); */
/* cl_git_pass(git_thread_create(&th[t], fn, &id[t])); */
/* #else */
fn
(
&
id
[
t
]);
/* #endif */
...
...
@@ -211,7 +211,7 @@ void test_threads_refdb__edit_while_iterate(void)
for
(
t
=
0
;
t
<
THREADS
;
++
t
)
{
id
[
t
]
=
t
;
cl_git_pass
(
git_thread_create
(
&
th
[
t
],
NULL
,
iterate_refs
,
&
id
[
t
]));
cl_git_pass
(
git_thread_create
(
&
th
[
t
],
iterate_refs
,
&
id
[
t
]));
}
for
(
t
=
0
;
t
<
THREADS
;
++
t
)
{
...
...
tests/threads/thread_helpers.c
View file @
faebc1c6
...
...
@@ -24,7 +24,7 @@ void run_in_parallel(
for
(
t
=
0
;
t
<
threads
;
++
t
)
{
id
[
t
]
=
t
;
#ifdef GIT_THREADS
cl_git_pass
(
git_thread_create
(
&
th
[
t
],
NULL
,
func
,
&
id
[
t
]));
cl_git_pass
(
git_thread_create
(
&
th
[
t
],
func
,
&
id
[
t
]));
#else
cl_assert
(
func
(
&
id
[
t
])
==
&
id
[
t
]);
#endif
...
...
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