diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-01 14:34:29 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-01 14:34:29 -0800 |
| commit | 3fd43c488b47874db22a87a1d87eed94bbd85725 (patch) | |
| tree | ed9fe38b370c9a6162ac05596b91adfac9cb5579 /src/protocol/pair | |
| parent | c7b541af4a1a2c410dc63a638a17adb31d7342a3 (diff) | |
| download | nng-3fd43c488b47874db22a87a1d87eed94bbd85725.tar.gz nng-3fd43c488b47874db22a87a1d87eed94bbd85725.tar.bz2 nng-3fd43c488b47874db22a87a1d87eed94bbd85725.zip | |
Pipe simplifications for thread management.
This may also address a race in closing down pipes. Now pipes are always
registered with the socket. They also always have both a sender and receiver
thread. If the protocol doesn't need one or the other, the stock thread just
exits early.
Diffstat (limited to 'src/protocol/pair')
| -rw-r--r-- | src/protocol/pair/pair.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/protocol/pair/pair.c b/src/protocol/pair/pair.c index 3f57c12b..9336af8c 100644 --- a/src/protocol/pair/pair.c +++ b/src/protocol/pair/pair.c @@ -23,7 +23,7 @@ typedef struct nni_pair_sock nni_pair_sock; struct nni_pair_sock { nni_socket * sock; nni_pair_pipe * pipe; - nni_mutex mx; + nni_mtx mx; nni_msgqueue * uwq; nni_msgqueue * urq; }; @@ -50,7 +50,7 @@ nni_pair_create(void **pairp, nni_socket *sock) if ((pair = nni_alloc(sizeof (*pair))) == NULL) { return (NNG_ENOMEM); } - if ((rv = nni_mutex_init(&pair->mx)) != 0) { + if ((rv = nni_mtx_init(&pair->mx)) != 0) { nni_free(pair, sizeof (*pair)); return (rv); } @@ -72,7 +72,7 @@ nni_pair_destroy(void *arg) // this wold be the time to shut them all down. We don't, because // the socket already shut us down, and we don't have any other // threads that run. - nni_mutex_fini(&pair->mx); + nni_mtx_fini(&pair->mx); nni_free(pair, sizeof (*pair)); } @@ -88,18 +88,14 @@ nni_pair_add_pipe(void *arg, nni_pipe *pipe, void *data) pp->sigclose = 0; pp->pair = pair; - nni_mutex_enter(&pair->mx); + nni_mtx_lock(&pair->mx); if (pair->pipe != NULL) { - rv = NNG_EBUSY; // Already have a peer, denied. - goto fail; + nni_mtx_unlock(&pair->mx); + return (NNG_EBUSY); // Already have a peer, denied. } pair->pipe = pp; - nni_mutex_exit(&pair->mx); + nni_mtx_unlock(&pair->mx); return (0); - -fail: - nni_mutex_exit(&pair->mx); - return (rv); } @@ -109,13 +105,11 @@ nni_pair_rem_pipe(void *arg, void *data) nni_pair_sock *pair = arg; nni_pair_pipe *pp = data; - nni_mutex_enter(&pair->mx); - if (pair->pipe != pp) { - nni_mutex_exit(&pair->mx); - return; + nni_mtx_lock(&pair->mx); + if (pair->pipe == pp) { + pair->pipe = NULL; } - pair->pipe = NULL; - nni_mutex_exit(&pair->mx); + nni_mtx_unlock(&pair->mx); } |
