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
1c135405
Commit
1c135405
authored
Jun 20, 2016
by
Patrick Steinhardt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
threads: split up OS-dependent mutex code
parent
faebc1c6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
26 deletions
+23
-26
src/thread-utils.h
+3
-8
src/unix/pthread.h
+7
-0
src/win32/pthread.c
+7
-10
src/win32/pthread.h
+6
-8
No files found.
src/thread-utils.h
View file @
1c135405
...
...
@@ -40,17 +40,12 @@ typedef git_atomic git_atomic_ssize;
#ifdef GIT_THREADS
#if !defined(GIT_WIN32)
#ifdef GIT_WIN32
# include "win32/pthread.h"
#else
# include "unix/pthread.h"
#endif
/* Pthreads Mutex */
#define git_mutex pthread_mutex_t
#define git_mutex_init(a) pthread_mutex_init(a, NULL)
#define git_mutex_lock(a) pthread_mutex_lock(a)
#define git_mutex_unlock(a) pthread_mutex_unlock(a)
#define git_mutex_free(a) pthread_mutex_destroy(a)
/* Pthreads condition vars */
#define git_cond pthread_cond_t
#define git_cond_init(c) pthread_cond_init(c, NULL)
...
...
src/unix/pthread.h
View file @
1c135405
...
...
@@ -17,4 +17,11 @@ typedef struct {
#define git_thread_join(git_thread_ptr, status) \
pthread_join((git_thread_ptr)->thread, status)
/* Git Mutex */
#define git_mutex pthread_mutex_t
#define git_mutex_init(a) pthread_mutex_init(a, NULL)
#define git_mutex_lock(a) pthread_mutex_lock(a)
#define git_mutex_unlock(a) pthread_mutex_unlock(a)
#define git_mutex_free(a) pthread_mutex_destroy(a)
#endif
/* INCLUDE_unix_pthread_h__ */
src/win32/pthread.c
View file @
1c135405
...
...
@@ -67,28 +67,25 @@ int git_thread_join(
return
0
;
}
int
pthread_mutex_init
(
pthread_mutex_t
*
GIT_RESTRICT
mutex
,
const
pthread_mutexattr_t
*
GIT_RESTRICT
mutexattr
)
int
git_mutex_init
(
git_mutex
*
GIT_RESTRICT
mutex
)
{
GIT_UNUSED
(
mutexattr
);
InitializeCriticalSection
(
mutex
);
return
0
;
}
int
pthread_mutex_destroy
(
pthread_mutex_t
*
mutex
)
int
git_mutex_free
(
git_mutex
*
mutex
)
{
DeleteCriticalSection
(
mutex
);
return
0
;
}
int
pthread_mutex_lock
(
pthread_mutex_t
*
mutex
)
int
git_mutex_lock
(
git_mutex
*
mutex
)
{
EnterCriticalSection
(
mutex
);
return
0
;
}
int
pthread_mutex_unlock
(
pthread_mutex_t
*
mutex
)
int
git_mutex_unlock
(
git_mutex
*
mutex
)
{
LeaveCriticalSection
(
mutex
);
return
0
;
...
...
@@ -124,7 +121,7 @@ int pthread_cond_destroy(pthread_cond_t *cond)
return
0
;
}
int
pthread_cond_wait
(
pthread_cond_t
*
cond
,
pthread_mutex_t
*
mutex
)
int
pthread_cond_wait
(
pthread_cond_t
*
cond
,
git_mutex
*
mutex
)
{
int
error
;
DWORD
wait_result
;
...
...
@@ -133,7 +130,7 @@ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
return
EINVAL
;
/* The caller must be holding the mutex. */
error
=
pthread
_mutex_unlock
(
mutex
);
error
=
git
_mutex_unlock
(
mutex
);
if
(
error
)
return
error
;
...
...
@@ -142,7 +139,7 @@ int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
assert
(
WAIT_OBJECT_0
==
wait_result
);
GIT_UNUSED
(
wait_result
);
return
pthread
_mutex_lock
(
mutex
);
return
git
_mutex_lock
(
mutex
);
}
int
pthread_cond_signal
(
pthread_cond_t
*
cond
)
...
...
src/win32/pthread.h
View file @
1c135405
...
...
@@ -28,7 +28,7 @@ typedef int pthread_condattr_t;
typedef
int
pthread_attr_t
;
typedef
int
pthread_rwlockattr_t
;
typedef
CRITICAL_SECTION
pthread_mutex_t
;
typedef
CRITICAL_SECTION
git_mutex
;
typedef
HANDLE
pthread_cond_t
;
typedef
struct
{
void
*
Ptr
;
}
GIT_SRWLOCK
;
...
...
@@ -47,16 +47,14 @@ int git_thread_create(git_thread *GIT_RESTRICT,
void
*
GIT_RESTRICT
);
int
git_thread_join
(
git_thread
*
,
void
**
);
int
pthread_mutex_init
(
pthread_mutex_t
*
GIT_RESTRICT
mutex
,
const
pthread_mutexattr_t
*
GIT_RESTRICT
mutexattr
);
int
pthread_mutex_destroy
(
pthread_mutex_t
*
);
int
pthread_mutex_lock
(
pthread_mutex_t
*
);
int
pthread_mutex_unlock
(
pthread_mutex_t
*
);
int
git_mutex_init
(
git_mutex
*
GIT_RESTRICT
mutex
);
int
git_mutex_free
(
git_mutex
*
);
int
git_mutex_lock
(
git_mutex
*
);
int
git_mutex_unlock
(
git_mutex
*
);
int
pthread_cond_init
(
pthread_cond_t
*
,
const
pthread_condattr_t
*
);
int
pthread_cond_destroy
(
pthread_cond_t
*
);
int
pthread_cond_wait
(
pthread_cond_t
*
,
pthread_mutex_t
*
);
int
pthread_cond_wait
(
pthread_cond_t
*
,
git_mutex
*
);
int
pthread_cond_signal
(
pthread_cond_t
*
);
/* pthread_cond_broadcast is not supported on Win32 yet. */
...
...
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