forked from tpruvot/ccminer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve project build compatibility (mac/vs2015)
This is incomplete, but is a first step...
- Loading branch information
Showing
9 changed files
with
141 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Meant to improve clang 4 / macos compatibility (untested) | ||
*/ | ||
|
||
#ifndef PTHREAD_BARRIER_H_ | ||
#define PTHREAD_BARRIER_H_ | ||
|
||
#include <pthread.h> | ||
#include <errno.h> | ||
|
||
typedef int pthread_barrierattr_t; | ||
typedef struct | ||
{ | ||
pthread_mutex_t mutex; | ||
pthread_cond_t cond; | ||
int count; | ||
int tripCount; | ||
} pthread_barrier_t; | ||
|
||
|
||
int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count) | ||
{ | ||
if(count == 0) | ||
{ | ||
errno = EINVAL; | ||
return -1; | ||
} | ||
if(pthread_mutex_init(&barrier->mutex, 0) < 0) | ||
{ | ||
return -1; | ||
} | ||
if(pthread_cond_init(&barrier->cond, 0) < 0) | ||
{ | ||
pthread_mutex_destroy(&barrier->mutex); | ||
return -1; | ||
} | ||
barrier->tripCount = count; | ||
barrier->count = 0; | ||
|
||
return 0; | ||
} | ||
|
||
int pthread_barrier_destroy(pthread_barrier_t *barrier) | ||
{ | ||
pthread_cond_destroy(&barrier->cond); | ||
pthread_mutex_destroy(&barrier->mutex); | ||
return 0; | ||
} | ||
|
||
int pthread_barrier_wait(pthread_barrier_t *barrier) | ||
{ | ||
pthread_mutex_lock(&barrier->mutex); | ||
++(barrier->count); | ||
if(barrier->count >= barrier->tripCount) | ||
{ | ||
barrier->count = 0; | ||
pthread_cond_broadcast(&barrier->cond); | ||
pthread_mutex_unlock(&barrier->mutex); | ||
return 1; | ||
} | ||
else | ||
{ | ||
pthread_cond_wait(&barrier->cond, &(barrier->mutex)); | ||
pthread_mutex_unlock(&barrier->mutex); | ||
return 0; | ||
} | ||
} | ||
|
||
#endif // PTHREAD_BARRIER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters