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
68343f26
Commit
68343f26
authored
Jun 20, 2016
by
Patrick Steinhardt
Committed by
Carlos Martín Nieto
Oct 01, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
threads: split up OS-dependent rwlock code
parent
fabd4771
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
43 deletions
+31
-43
src/thread-utils.h
+0
-24
src/unix/pthread.h
+18
-0
src/win32/pthread.c
+6
-10
src/win32/pthread.h
+7
-9
No files found.
src/thread-utils.h
View file @
68343f26
...
...
@@ -46,30 +46,6 @@ typedef git_atomic git_atomic_ssize;
# include "unix/pthread.h"
#endif
/* Pthread (-ish) rwlock
*
* This differs from normal pthreads rwlocks in two ways:
* 1. Separate APIs for releasing read locks and write locks (as
* opposed to the pure POSIX API which only has one unlock fn)
* 2. You should not use recursive read locks (i.e. grabbing a read
* lock in a thread that already holds a read lock) because the
* Windows implementation doesn't support it
*/
#define git_rwlock pthread_rwlock_t
#define git_rwlock_init(a) pthread_rwlock_init(a, NULL)
#define git_rwlock_rdlock(a) pthread_rwlock_rdlock(a)
#define git_rwlock_rdunlock(a) pthread_rwlock_rdunlock(a)
#define git_rwlock_wrlock(a) pthread_rwlock_wrlock(a)
#define git_rwlock_wrunlock(a) pthread_rwlock_wrunlock(a)
#define git_rwlock_free(a) pthread_rwlock_destroy(a)
#define GIT_RWLOCK_STATIC_INIT PTHREAD_RWLOCK_INITIALIZER
#ifndef GIT_WIN32
#define pthread_rwlock_rdunlock pthread_rwlock_unlock
#define pthread_rwlock_wrunlock pthread_rwlock_unlock
#endif
GIT_INLINE
(
void
)
git_atomic_set
(
git_atomic
*
a
,
int
val
)
{
#if defined(GIT_WIN32)
...
...
src/unix/pthread.h
View file @
68343f26
...
...
@@ -32,4 +32,22 @@ typedef struct {
#define git_cond_signal(c) pthread_cond_signal(c)
#define git_cond_broadcast(c) pthread_cond_broadcast(c)
/* Pthread (-ish) rwlock
*
* This differs from normal pthreads rwlocks in two ways:
* 1. Separate APIs for releasing read locks and write locks (as
* opposed to the pure POSIX API which only has one unlock fn)
* 2. You should not use recursive read locks (i.e. grabbing a read
* lock in a thread that already holds a read lock) because the
* Windows implementation doesn't support it
*/
#define git_rwlock pthread_rwlock_t
#define git_rwlock_init(a) pthread_rwlock_init(a, NULL)
#define git_rwlock_rdlock(a) pthread_rwlock_rdlock(a)
#define git_rwlock_rdunlock(a) pthread_rwlock_unlock(a)
#define git_rwlock_wrlock(a) pthread_rwlock_wrlock(a)
#define git_rwlock_wrunlock(a) pthread_rwlock_unlock(a)
#define git_rwlock_free(a) pthread_rwlock_destroy(a)
#define GIT_RWLOCK_STATIC_INIT PTHREAD_RWLOCK_INITIALIZER
#endif
/* INCLUDE_unix_pthread_h__ */
src/win32/pthread.c
View file @
68343f26
...
...
@@ -172,12 +172,8 @@ static win32_srwlock_fn win32_srwlock_release_shared;
static
win32_srwlock_fn
win32_srwlock_acquire_exclusive
;
static
win32_srwlock_fn
win32_srwlock_release_exclusive
;
int
pthread_rwlock_init
(
pthread_rwlock_t
*
GIT_RESTRICT
lock
,
const
pthread_rwlockattr_t
*
GIT_RESTRICT
attr
)
int
git_rwlock_init
(
git_rwlock
*
GIT_RESTRICT
lock
)
{
GIT_UNUSED
(
attr
);
if
(
win32_srwlock_initialize
)
win32_srwlock_initialize
(
&
lock
->
native
.
srwl
);
else
...
...
@@ -186,7 +182,7 @@ int pthread_rwlock_init(
return
0
;
}
int
pthread_rwlock_rdlock
(
pthread_rwlock_t
*
lock
)
int
git_rwlock_rdlock
(
git_rwlock
*
lock
)
{
if
(
win32_srwlock_acquire_shared
)
win32_srwlock_acquire_shared
(
&
lock
->
native
.
srwl
);
...
...
@@ -196,7 +192,7 @@ int pthread_rwlock_rdlock(pthread_rwlock_t *lock)
return
0
;
}
int
pthread_rwlock_rdunlock
(
pthread_rwlock_t
*
lock
)
int
git_rwlock_rdunlock
(
git_rwlock
*
lock
)
{
if
(
win32_srwlock_release_shared
)
win32_srwlock_release_shared
(
&
lock
->
native
.
srwl
);
...
...
@@ -206,7 +202,7 @@ int pthread_rwlock_rdunlock(pthread_rwlock_t *lock)
return
0
;
}
int
pthread_rwlock_wrlock
(
pthread_rwlock_t
*
lock
)
int
git_rwlock_wrlock
(
git_rwlock
*
lock
)
{
if
(
win32_srwlock_acquire_exclusive
)
win32_srwlock_acquire_exclusive
(
&
lock
->
native
.
srwl
);
...
...
@@ -216,7 +212,7 @@ int pthread_rwlock_wrlock(pthread_rwlock_t *lock)
return
0
;
}
int
pthread_rwlock_wrunlock
(
pthread_rwlock_t
*
lock
)
int
git_rwlock_wrunlock
(
git_rwlock
*
lock
)
{
if
(
win32_srwlock_release_exclusive
)
win32_srwlock_release_exclusive
(
&
lock
->
native
.
srwl
);
...
...
@@ -226,7 +222,7 @@ int pthread_rwlock_wrunlock(pthread_rwlock_t *lock)
return
0
;
}
int
pthread_rwlock_destroy
(
pthread_rwlock_t
*
lock
)
int
git_rwlock_free
(
git_rwlock
*
lock
)
{
if
(
!
win32_srwlock_initialize
)
DeleteCriticalSection
(
&
lock
->
native
.
csec
);
...
...
src/win32/pthread.h
View file @
68343f26
...
...
@@ -38,7 +38,7 @@ typedef struct {
GIT_SRWLOCK
srwl
;
CRITICAL_SECTION
csec
;
}
native
;
}
pthread_rwlock_t
;
}
git_rwlock
;
#define PTHREAD_MUTEX_INITIALIZER {(void*)-1}
...
...
@@ -59,14 +59,12 @@ int git_cond_signal(git_cond *);
int
pthread_num_processors_np
(
void
);
int
pthread_rwlock_init
(
pthread_rwlock_t
*
GIT_RESTRICT
lock
,
const
pthread_rwlockattr_t
*
GIT_RESTRICT
attr
);
int
pthread_rwlock_rdlock
(
pthread_rwlock_t
*
);
int
pthread_rwlock_rdunlock
(
pthread_rwlock_t
*
);
int
pthread_rwlock_wrlock
(
pthread_rwlock_t
*
);
int
pthread_rwlock_wrunlock
(
pthread_rwlock_t
*
);
int
pthread_rwlock_destroy
(
pthread_rwlock_t
*
);
int
git_rwlock_init
(
git_rwlock
*
GIT_RESTRICT
lock
);
int
git_rwlock_rdlock
(
git_rwlock
*
);
int
git_rwlock_rdunlock
(
git_rwlock
*
);
int
git_rwlock_wrlock
(
git_rwlock
*
);
int
git_rwlock_wrunlock
(
git_rwlock
*
);
int
git_rwlock_free
(
git_rwlock
*
);
extern
int
win32_pthread_initialize
(
void
);
...
...
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