diff options
author | Ark Degtiarov <a@amcloud.co> | 2014-07-10 03:58:35 +0200 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2014-07-10 03:58:35 +0200 |
commit | 23dfb299676243701a4128d2954ee9a123bcce60 (patch) | |
tree | 3117d2d77b855aafc6cda0d14cd88549ed72ff55 /src/aio | |
parent | fd48282b866143278c803ad04b57dae2f7306a77 (diff) | |
download | nanomsg-23dfb299676243701a4128d2954ee9a123bcce60.tar.gz |
Added socket's life cycle stress test.
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src/aio')
-rw-r--r-- | src/aio/timer.c | 4 | ||||
-rw-r--r-- | src/aio/usock_posix.inc | 5 | ||||
-rw-r--r-- | src/aio/worker.h | 1 | ||||
-rw-r--r-- | src/aio/worker_posix.inc | 7 |
4 files changed, 14 insertions, 3 deletions
diff --git a/src/aio/timer.c b/src/aio/timer.c index 9a45880..0416c9c 100644 --- a/src/aio/timer.c +++ b/src/aio/timer.c @@ -95,8 +95,8 @@ static void nn_timer_shutdown (struct nn_fsm *self, int src, int type, timer = nn_cont (self, struct nn_timer, fsm); if (nn_slow (src == NN_FSM_ACTION && type == NN_FSM_STOP)) { - nn_worker_execute (timer->worker, &timer->stop_task); timer->state = NN_TIMER_STATE_STOPPING; + nn_worker_execute (timer->worker, &timer->stop_task); return; } if (nn_slow (timer->state == NN_TIMER_STATE_STOPPING)) { @@ -131,8 +131,8 @@ static void nn_timer_handler (struct nn_fsm *self, int src, int type, case NN_FSM_START: /* Send start event to the worker thread. */ - nn_worker_execute (timer->worker, &timer->start_task); timer->state = NN_TIMER_STATE_ACTIVE; + nn_worker_execute (timer->worker, &timer->start_task); return; default: nn_fsm_bad_action (timer->state, src, type); diff --git a/src/aio/usock_posix.inc b/src/aio/usock_posix.inc index 4cc559d..baee3f7 100644 --- a/src/aio/usock_posix.inc +++ b/src/aio/usock_posix.inc @@ -130,6 +130,9 @@ void nn_usock_term (struct nn_usock *self) nn_fsm_event_term (&self->event_received); nn_fsm_event_term (&self->event_sent); nn_fsm_event_term (&self->event_established); + + nn_worker_maybe_cancel (self->worker, &self->task_recv); + nn_worker_task_term (&self->task_stop); nn_worker_task_term (&self->task_recv); nn_worker_task_term (&self->task_send); @@ -858,8 +861,8 @@ error: usock->state = NN_USOCK_STATE_LISTENING; return; case NN_USOCK_ACTION_CANCEL: - nn_worker_execute (usock->worker, &usock->task_stop); usock->state = NN_USOCK_STATE_CANCELLING; + nn_worker_execute (usock->worker, &usock->task_stop); return; default: nn_fsm_bad_action (usock->state, src, type); diff --git a/src/aio/worker.h b/src/aio/worker.h index adceae3..1c05dd9 100644 --- a/src/aio/worker.h +++ b/src/aio/worker.h @@ -58,6 +58,7 @@ struct nn_worker; int nn_worker_init (struct nn_worker *self); void nn_worker_term (struct nn_worker *self); void nn_worker_execute (struct nn_worker *self, struct nn_worker_task *task); +void nn_worker_maybe_cancel (struct nn_worker *self, struct nn_worker_task *task); void nn_worker_add_timer (struct nn_worker *self, int timeout, struct nn_worker_timer *timer); diff --git a/src/aio/worker_posix.inc b/src/aio/worker_posix.inc index 36867d4..2caf70a 100644 --- a/src/aio/worker_posix.inc +++ b/src/aio/worker_posix.inc @@ -145,6 +145,13 @@ void nn_worker_execute (struct nn_worker *self, struct nn_worker_task *task) nn_mutex_unlock (&self->sync); } +void nn_worker_maybe_cancel (struct nn_worker *self, struct nn_worker_task *task) +{ + nn_mutex_lock (&self->sync); + nn_queue_maybe_remove (&self->tasks, &task->item); + nn_mutex_unlock (&self->sync); +} + static void nn_worker_routine (void *arg) { int rc; |