diff --git a/include/pthread_barrier.h b/include/pthread_barrier.h new file mode 100644 index 0000000..fb9bd6f --- /dev/null +++ b/include/pthread_barrier.h @@ -0,0 +1,68 @@ +#ifdef __APPLE__ + +#ifndef PTHREAD_BARRIER_H_ +#define PTHREAD_BARRIER_H_ + +#include +#include + +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_ +#endif // __APPLE__ diff --git a/psystem b/psystem index 6dc5c07..e26c538 100755 Binary files a/psystem and b/psystem differ diff --git a/source/main.cpp b/source/main.cpp index bec9a19..9f425bc 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,4 +1,9 @@ #include "main.h" + +#ifdef __APPLE__ +#include "pthread_barrier.h" +#endif + #include "axis.h" #include "camera.h" #include "grid.h" @@ -26,7 +31,7 @@ const unsigned int SCR_WIDTH = 2560; const unsigned int SCR_HEIGHT = 1440; const char *glsl_version; -const unsigned int PARTICLE_COUNT = 500; +const unsigned int PARTICLE_COUNT = 5000; GLFWwindow *window; unsigned int VBO, VAO;