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
972bb689
Commit
972bb689
authored
Aug 22, 2013
by
Russell Belfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SRWLock implementation of rwlocks for Win32
parent
2b6e1908
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
5 deletions
+62
-5
src/thread-utils.h
+7
-2
src/win32/pthread.c
+38
-0
src/win32/pthread.h
+13
-1
tests-clar/core/sortedcache.c
+4
-2
No files found.
src/thread-utils.h
View file @
972bb689
...
...
@@ -66,12 +66,17 @@ typedef git_atomic git_atomic_ssize;
#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_rdunlock(a) pthread_rwlock_
rd
unlock(a)
#define git_rwlock_wrlock(a) pthread_rwlock_wrlock(a)
#define git_rwlock_wrunlock(a) pthread_rwlock_unlock(a)
#define git_rwlock_wrunlock(a) pthread_rwlock_
wr
unlock(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
)
{
...
...
src/win32/pthread.c
View file @
972bb689
...
...
@@ -142,3 +142,41 @@ int pthread_num_processors_np(void)
return
n
?
n
:
1
;
}
int
pthread_rwlock_init
(
pthread_rwlock_t
*
GIT_RESTRICT
lock
,
const
pthread_rwlockattr_t
*
GIT_RESTRICT
attr
)
{
(
void
)
attr
;
InitializeSRWLock
(
lock
);
return
0
;
}
int
pthread_rwlock_rdlock
(
pthread_rwlock_t
*
lock
)
{
AcquireSRWLockShared
(
lock
);
return
0
;
}
int
pthread_rwlock_rdunlock
(
pthread_rwlock_t
*
lock
)
{
ReleaseSRWLockShared
(
lock
);
return
0
;
}
int
pthread_rwlock_wrlock
(
pthread_rwlock_t
*
lock
)
{
AcquireSRWLockExclusive
(
lock
);
return
0
;
}
int
pthread_rwlock_wrunlock
(
pthread_rwlock_t
*
lock
)
{
ReleaseSRWLockExclusive
(
lock
);
return
0
;
}
int
pthread_rwlock_destroy
(
pthread_rwlock_t
*
lock
)
{
(
void
)
lock
;
return
0
;
}
src/win32/pthread.h
View file @
972bb689
...
...
@@ -19,11 +19,15 @@
typedef
int
pthread_mutexattr_t
;
typedef
int
pthread_condattr_t
;
typedef
int
pthread_attr_t
;
typedef
int
pthread_rwlockattr_t
;
typedef
CRITICAL_SECTION
pthread_mutex_t
;
typedef
HANDLE
pthread_t
;
typedef
HANDLE
pthread_cond_t
;
typedef
SRWLOCK
pthread_rwlock_t
;
#define PTHREAD_MUTEX_INITIALIZER {(void*)-1};
#define PTHREAD_MUTEX_INITIALIZER {(void*)-1}
#define PTHREAD_RWLOCK_INITIALIZER SRWLOCK_INIT
int
pthread_create
(
pthread_t
*
GIT_RESTRICT
,
...
...
@@ -47,4 +51,12 @@ int pthread_cond_signal(pthread_cond_t *);
int
pthread_num_processors_np
(
void
);
int
pthread_rwlock_init
(
pthread_rwlock_t
*
GIT_RESTRICT
,
const
pthread_rwlockattr_t
*
GIT_RESTRICT
);
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
*
);
#endif
tests-clar/core/sortedcache.c
View file @
972bb689
...
...
@@ -128,7 +128,9 @@ void test_core_sortedcache__in_memory(void)
cl_assert_equal_i
(
30
,
item
->
value
);
cl_assert
(
git_sortedcache_lookup
(
sc
,
"abc"
)
==
NULL
);
cl_git_pass
(
git_sortedcache_rlock
(
sc
));
/* grab more than one */
/* not on Windows:
* cl_git_pass(git_sortedcache_rlock(sc)); -- grab more than one
*/
cl_assert
((
item
=
git_sortedcache_entry
(
sc
,
0
))
!=
NULL
);
cl_assert_equal_s
(
"aaa"
,
item
->
path
);
...
...
@@ -148,7 +150,7 @@ void test_core_sortedcache__in_memory(void)
cl_assert
(
git_sortedcache_entry
(
sc
,
5
)
==
NULL
);
git_sortedcache_runlock
(
sc
);
git_sortedcache_runlock
(
sc
);
/* git_sortedcache_runlock(sc); */
cl_assert_equal_i
(
0
,
free_count
);
...
...
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