void *destructor_context,
SilcSchedule schedule)
{
- if (!schedule)
- return FALSE;
+ if (!schedule) {
+ schedule = silc_schedule_get_global();
+ if (!schedule) {
+ silc_set_errno(SILC_ERR_INVALID_ARGUMENT);
+ return FALSE;
+ }
+ }
fsm->fsm_context = fsm_context;
fsm->state_context = NULL;
SILC_LOG_DEBUG(("Initializing new thread %p (%s)",
thread, real_thread ? "real" : "FSM"));
- SILC_ASSERT(!fsm->thread);
+ SILC_VERIFY(!fsm->thread);
thread->fsm_context = thread_context;
thread->state_context = NULL;
{
SilcFSM f = fsm;
- SILC_ASSERT(!f->finished);
-
- /* Machine must not have active threads */
- if (!f->thread && silc_atomic_get_int32(&f->u.m.threads))
- assert(silc_atomic_get_int32(&f->u.m.threads) == 0);
+ SILC_VERIFY(!f->finished);
f->started = FALSE;
f->finished = TRUE;
SilcFSM silc_fsm_get_machine(SilcFSMThread thread)
{
- SILC_ASSERT(thread->thread);
+ SILC_VERIFY(thread->thread);
return (SilcFSM)thread->u.t.fsm;
}
{
SilcFSM t = thread;
- SILC_ASSERT(t->thread);
+ SILC_VERIFY(t->thread);
t->u.t.event = silc_fsm_event_alloc(t->u.t.fsm);
if (!t->u.t.event)
fsm->destructor(fsm, fsm->fsm_context, fsm->destructor_context);
} else {
+ /* Machine must not have active threads */
+ SILC_VERIFY(silc_atomic_get_int32(&fsm->u.m.threads) == 0);
+
if (fsm->u.m.lock) {
silc_mutex_free(fsm->u.m.lock);
fsm->u.m.lock = NULL;
void silc_fsm_event_init(SilcFSMEvent event, SilcFSM fsm)
{
SILC_LOG_DEBUG(("Initializing event %p", event));
- SILC_ASSERT(!fsm->thread);
+ SILC_VERIFY(!fsm->thread);
memset(event, 0, sizeof(*event));
event->fsm = fsm;
event->refcnt = 0;
/* We allocate new SilcSchedule for the FSM, as the old SilcSchedule
cannot be used in this thread. Application may still use it if it
wants but we use our own. */
- fsm->schedule = silc_schedule_init(0, old);
- if (silc_unlikely(!fsm->schedule))
+ fsm->schedule = silc_schedule_init(0, old, silc_schedule_get_stack(old));
+ if (silc_unlikely(!fsm->schedule)) {
+ fsm->schedule = old;
return NULL;
+ }
/* Start the FSM thread */
if (silc_unlikely(!silc_schedule_task_add_timeout(fsm->schedule,
- silc_fsm_run, fsm, 0, 0)))
+ silc_fsm_run, fsm, 0, 0))) {
+ silc_schedule_uninit(fsm->schedule);
+ fsm->schedule = old;
return NULL;
+ }
/* Run the scheduler */
silc_schedule(fsm->schedule);