Commit e830d6dd authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

varnishtest: Barrier polish

Make the type-specific fields stand out without the help of comments.
parent e0c5201f
...@@ -61,10 +61,12 @@ struct barrier { ...@@ -61,10 +61,12 @@ struct barrier {
int waiters; int waiters;
int expected; int expected;
int cyclic; int cyclic;
int cycle; /* BARRIER_COND only */
enum barrier_e type; enum barrier_e type;
pthread_t thread; /* BARRIER_SOCK only */ union {
int cond_cycle;
pthread_t sock_thread;
};
}; };
static VTAILQ_HEAD(, barrier) barriers = VTAILQ_HEAD_INITIALIZER(barriers); static VTAILQ_HEAD(, barrier) barriers = VTAILQ_HEAD_INITIALIZER(barriers);
...@@ -254,7 +256,7 @@ barrier_sock(struct barrier *b, const char *av, struct vtclog *vl) ...@@ -254,7 +256,7 @@ barrier_sock(struct barrier *b, const char *av, struct vtclog *vl)
/* NB. We can use the BARRIER_COND's pthread_cond_t to wait until the /* NB. We can use the BARRIER_COND's pthread_cond_t to wait until the
* socket is ready for convenience. * socket is ready for convenience.
*/ */
AZ(pthread_create(&b->thread, NULL, barrier_sock_thread, b)); AZ(pthread_create(&b->sock_thread, NULL, barrier_sock_thread, b));
AZ(pthread_cond_wait(&b->cond, &b->mtx)); AZ(pthread_cond_wait(&b->cond, &b->mtx));
AZ(pthread_mutex_unlock(&b->mtx)); AZ(pthread_mutex_unlock(&b->mtx));
} }
...@@ -307,7 +309,7 @@ barrier_cond_sync(struct barrier *b, struct vtclog *vl) ...@@ -307,7 +309,7 @@ barrier_cond_sync(struct barrier *b, struct vtclog *vl)
else else
b->waiters = ++w; b->waiters = ++w;
c = b->cycle; c = b->cond_cycle;
AZ(pthread_mutex_unlock(&b->mtx)); AZ(pthread_mutex_unlock(&b->mtx));
if (w < 0) if (w < 0)
...@@ -318,7 +320,7 @@ barrier_cond_sync(struct barrier *b, struct vtclog *vl) ...@@ -318,7 +320,7 @@ barrier_cond_sync(struct barrier *b, struct vtclog *vl)
AZ(pthread_mutex_lock(&b->mtx)); AZ(pthread_mutex_lock(&b->mtx));
if (w == b->expected) { if (w == b->expected) {
vtc_log(vl, 4, "Barrier(%s) wake %u", b->name, b->expected); vtc_log(vl, 4, "Barrier(%s) wake %u", b->name, b->expected);
b->cycle++; b->cond_cycle++;
if (b->cyclic) if (b->cyclic)
b->waiters = 0; b->waiters = 0;
AZ(pthread_cond_broadcast(&b->cond)); AZ(pthread_cond_broadcast(&b->cond));
...@@ -330,7 +332,7 @@ barrier_cond_sync(struct barrier *b, struct vtclog *vl) ...@@ -330,7 +332,7 @@ barrier_cond_sync(struct barrier *b, struct vtclog *vl)
r = pthread_cond_timedwait(&b->cond, &b->mtx, &ts); r = pthread_cond_timedwait(&b->cond, &b->mtx, &ts);
assert(r == 0 || r == ETIMEDOUT); assert(r == 0 || r == ETIMEDOUT);
} while (!vtc_stop && !vtc_error && r == ETIMEDOUT && } while (!vtc_stop && !vtc_error && r == ETIMEDOUT &&
c == b->cycle); c == b->cond_cycle);
} }
AZ(pthread_mutex_unlock(&b->mtx)); AZ(pthread_mutex_unlock(&b->mtx));
} }
...@@ -455,7 +457,7 @@ cmd_barrier(CMD_ARGS) ...@@ -455,7 +457,7 @@ cmd_barrier(CMD_ARGS)
case BARRIER_COND: case BARRIER_COND:
break; break;
case BARRIER_SOCK: case BARRIER_SOCK:
AZ(pthread_join(b->thread, NULL)); AZ(pthread_join(b->sock_thread, NULL));
break; break;
default: default:
WRONG("Wrong barrier type"); WRONG("Wrong barrier type");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment