Skip to content

Implement pthread_cond_t with Win32 CONDITION_VARIABLE #1214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 15, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions compat/win32/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pthread_t pthread_self(void)
return t;
}

#ifdef GIT_WIN_XP_SUPPORT

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.


int pthread_cond_init(pthread_cond_t *cond, const void *unused)
{
cond->waiters = 0;
Expand Down Expand Up @@ -194,3 +196,47 @@ int pthread_cond_broadcast(pthread_cond_t *cond)
}
return 0;
}

#else // GIT_WIN_XP_SUPPORT

WINBASEAPI VOID WINAPI
InitializeConditionVariable(PCONDITION_VARIABLE ConditionVariable);
WINBASEAPI VOID WINAPI
WakeConditionVariable(PCONDITION_VARIABLE ConditionVariable);
WINBASEAPI VOID WINAPI
WakeAllConditionVariable(PCONDITION_VARIABLE ConditionVariable);
WINBASEAPI WINBOOL WINAPI
SleepConditionVariableCS(PCONDITION_VARIABLE ConditionVariable,
PCRITICAL_SECTION CriticalSection,
DWORD dwMilliseconds);

int pthread_cond_init(pthread_cond_t *cond, const void *unused)
{
InitializeConditionVariable(cond);
return 0;
}

int pthread_cond_destroy(pthread_cond_t *cond)
{
return 0;
}

int pthread_cond_wait(pthread_cond_t *cond, CRITICAL_SECTION *mutex)
{
SleepConditionVariableCS(cond, mutex, INFINITE);
return 0;
}

int pthread_cond_signal(pthread_cond_t *cond)
{
WakeConditionVariable(cond);
return 0;
}

int pthread_cond_broadcast(pthread_cond_t *cond)
{
WakeAllConditionVariable(cond);
return 0;
}

#endif // GIT_WIN_XP_SUPPORT
4 changes: 4 additions & 0 deletions compat/win32/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef int pthread_mutexattr_t;
#define pthread_mutexattr_settype(a, t) 0
#define PTHREAD_MUTEX_RECURSIVE 0

#ifdef GIT_WIN_XP_SUPPORT
/*
* Implement simple condition variable for Windows threads, based on ACE
* implementation.
Expand All @@ -47,6 +48,9 @@ typedef struct {
HANDLE sema;
HANDLE continue_broadcast;
} pthread_cond_t;
#else
typedef CONDITION_VARIABLE pthread_cond_t;
#endif

extern int pthread_cond_init(pthread_cond_t *cond, const void *unused);
extern int pthread_cond_destroy(pthread_cond_t *cond);
Expand Down