|
@@ -19,6 +19,8 @@
|
|
|
int _starpu_barrier_counter_init(struct _starpu_barrier_counter *barrier_c, unsigned count)
|
|
|
{
|
|
|
_starpu_barrier_init(&barrier_c->barrier, count);
|
|
|
+ barrier_c->min_threshold = 0;
|
|
|
+ barrier_c->max_threshold = 0;
|
|
|
STARPU_PTHREAD_COND_INIT(&barrier_c->cond2, NULL);
|
|
|
return 0;
|
|
|
}
|
|
@@ -43,13 +45,33 @@ int _starpu_barrier_counter_wait_for_empty_counter(struct _starpu_barrier_counte
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-int _starpu_barrier_counter_wait_until_counter_reaches_n(struct _starpu_barrier_counter *barrier_c, unsigned n)
|
|
|
+int _starpu_barrier_counter_wait_until_counter_reaches_down_to_n(struct _starpu_barrier_counter *barrier_c, unsigned n)
|
|
|
{
|
|
|
struct _starpu_barrier *barrier = &barrier_c->barrier;
|
|
|
STARPU_PTHREAD_MUTEX_LOCK(&barrier->mutex);
|
|
|
|
|
|
while (barrier->reached_start > n)
|
|
|
+ {
|
|
|
+ if (barrier_c->max_threshold < n)
|
|
|
+ barrier_c->max_threshold = n;
|
|
|
STARPU_PTHREAD_COND_WAIT(&barrier->cond, &barrier->mutex);
|
|
|
+ }
|
|
|
+
|
|
|
+ STARPU_PTHREAD_MUTEX_UNLOCK(&barrier->mutex);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+int _starpu_barrier_counter_wait_until_counter_reaches_up_to_n(struct _starpu_barrier_counter *barrier_c, unsigned n)
|
|
|
+{
|
|
|
+ struct _starpu_barrier *barrier = &barrier_c->barrier;
|
|
|
+ STARPU_PTHREAD_MUTEX_LOCK(&barrier->mutex);
|
|
|
+
|
|
|
+ while (barrier->reached_start < n)
|
|
|
+ {
|
|
|
+ if (barrier_c->min_threshold > n)
|
|
|
+ barrier_c->min_threshold = n;
|
|
|
+ STARPU_PTHREAD_COND_WAIT(&barrier_c->cond2, &barrier->mutex);
|
|
|
+ }
|
|
|
|
|
|
STARPU_PTHREAD_MUTEX_UNLOCK(&barrier->mutex);
|
|
|
return 0;
|
|
@@ -79,6 +101,12 @@ int _starpu_barrier_counter_decrement_until_empty_counter(struct _starpu_barrier
|
|
|
ret = 1;
|
|
|
STARPU_PTHREAD_COND_BROADCAST(&barrier->cond);
|
|
|
}
|
|
|
+ if (barrier_c->max_threshold && barrier->reached_start == barrier_c->max_threshold)
|
|
|
+ {
|
|
|
+ /* have those not happy enough tell us how much again */
|
|
|
+ barrier_c->max_threshold = 0;
|
|
|
+ STARPU_PTHREAD_COND_BROADCAST(&barrier->cond);
|
|
|
+ }
|
|
|
|
|
|
STARPU_PTHREAD_MUTEX_UNLOCK(&barrier->mutex);
|
|
|
return ret;
|
|
@@ -96,6 +124,12 @@ int _starpu_barrier_counter_increment_until_full_counter(struct _starpu_barrier_
|
|
|
ret = 1;
|
|
|
STARPU_PTHREAD_COND_BROADCAST(&barrier_c->cond2);
|
|
|
}
|
|
|
+ if (barrier_c->min_threshold && barrier->reached_start == barrier_c->min_threshold)
|
|
|
+ {
|
|
|
+ /* have those not happy enough tell us how much again */
|
|
|
+ barrier_c->min_threshold = 0;
|
|
|
+ STARPU_PTHREAD_COND_BROADCAST(&barrier->cond);
|
|
|
+ }
|
|
|
|
|
|
STARPU_PTHREAD_MUTEX_UNLOCK(&barrier->mutex);
|
|
|
return ret;
|