Removed silc_fsm_uninit -> not needed.
authorPekka Riikonen <priikone@silcnet.org>
Sat, 24 Jun 2006 19:39:19 +0000 (19:39 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sat, 24 Jun 2006 19:39:19 +0000 (19:39 +0000)
lib/silcutil/silcfsm.c
lib/silcutil/silcfsm.h
lib/silcutil/tests/test_silcfsm.c

index dcefb09cef98b208d93f6896a094c3fd57b5945c..863516dadd9ac53a40a97ac11ba98d52741a264e 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2005 Pekka Riikonen
+  Copyright (C) 2005 - 2006 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -137,6 +137,9 @@ SILC_TASK_CALLBACK(silc_fsm_free_final)
   SilcFSM f = context;
 
 #if defined(SILC_DEBUG)
+  /* We must be finished */
+  assert(f->finished);
+
   /* Machine must not have active threads */
   if (!f->thread && f->u.m.threads)
     assert(f->u.m.threads == 0);
@@ -159,35 +162,6 @@ void silc_fsm_free(void *fsm)
   silc_schedule_task_add_timeout(f->schedule, silc_fsm_free_final, f, 0, 1);
 }
 
-/* FSM is uninitialized through scheduler to make sure that all dying
-   real system threads will have their finish callbacks scheduled before
-   this one (when SILC_FSM_THREAD_WAIT was used). */
-
-SILC_TASK_CALLBACK(silc_fsm_uninit_final)
-{
-  SilcFSM f = context;
-
-#if defined(SILC_DEBUG)
-  /* Machine must not have active threads */
-  if (!f->thread && f->u.m.threads)
-    assert(f->u.m.threads == 0);
-#endif /* SILC_DEBUG */
-
-  if (!f->thread && f->u.m.lock)
-    silc_mutex_free(f->u.m.lock);
-
-  if (f->thread && f->u.t.sema)
-    silc_fsm_sema_free(f->u.t.sema);
-}
-
-/* Uninitializes FSM */
-
-void silc_fsm_uninit(void *fsm)
-{
-  SilcFSM f = fsm;
-  silc_schedule_task_add_timeout(f->schedule, silc_fsm_uninit_final, f, 0, 1);
-}
-
 /* Task to start real thread. We start threads through scheduler, not
    directly in silc_fsm_start. */
 
@@ -433,6 +407,11 @@ SILC_TASK_CALLBACK(silc_fsm_finish)
       fsm->destructor(fsm, fsm->fsm_context, fsm->destructor_context);
 
   } else {
+    if (fsm->u.m.lock) {
+      silc_mutex_free(fsm->u.m.lock);
+      fsm->u.m.lock = NULL;
+    }
+
     /* Call the destructor callback. */
     if (fsm->destructor)
       fsm->destructor(fsm, fsm->fsm_context, fsm->destructor_context);
index 72f11189a509837a07d7d767f797dbc4c8a63461..8822b2dd79e549015e1670c74c003ce968845132 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2005 Pekka Riikonen
+  Copyright (C) 2005, 2006 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -67,7 +67,7 @@ typedef struct SilcFSMObject *SilcFSM;
  *
  *    The actual FSM context and can be used as pre-allocated FSM context,
  *    instead of SilcFSM context.  This context is initialized with the
- *    silc_fsm_init function.  It is uninitialized with silc_fsm_uninit.
+ *    silc_fsm_init function.  It need not be uninitialized.
  *
  ***/
 typedef struct SilcFSMObject SilcFSMStruct;
@@ -101,8 +101,7 @@ typedef struct SilcFSMObject *SilcFSMThread;
  *
  *    FSM thread context and can be used as a pre-allocated FSM thread context,
  *    instead of SilcFSMThread context.  This context is initialized with the
- *    silc_fsm_thread_init function.  It is uninitialized with the
- *    silc_fsm_uninit function.
+ *    silc_fsm_thread_init function.  It need not be uninitialized.
  *
  ***/
 typedef struct SilcFSMObject SilcFSMThreadStruct;
@@ -536,26 +535,6 @@ void silc_fsm_thread_init(SilcFSMThread thread,
  ***/
 void silc_fsm_free(void *fsm);
 
-/****f* silcutil/SilcFSMAPI/silc_fsm_uninit
- *
- * SYNOPSIS
- *
- *    void silc_fsm_uninit(void *fsm);
- *
- * DESCRIPTION
- *
- *    Uninitializes a pre-allocated SilcFSM or SilcFSMThread context.
- *    If you used the function silc_fsm_init or silc_fsm_thread_init, call
- *    this function to uninitialize it.  This function is used with both
- *    SilcFSMStruct and SilcFSMThreadStruct contexts.
- *
- * NOTES
- *
- *    When uninitializing FSM, it must not have any active threads.
- *
- ***/
-void silc_fsm_uninit(void *fsm);
-
 /****f* silcutil/SilcFSMAPI/silc_fsm_start
  *
  * SYNOPSIS
index c801a5e0187bf3e4627489263953d7afdddbc33c..1a48aed15c021a57484bc4894441d6b7df0ab075 100644 (file)
@@ -258,9 +258,6 @@ SILC_FSM_STATE(test_st_eighth)
     }
   }
 
-  for (i = 0; i < NUM_THREADS; i++)
-    silc_fsm_uninit(&f->threads[i].thread);
-
   SILC_LOG_DEBUG(("All %d threads terminated", NUM_THREADS));
 
   /** Move to next thread */
@@ -320,9 +317,6 @@ SILC_FSM_STATE(test_st_tenth)
       f->threads2[i].finished = TRUE;
     }
 
-  for (i = 0; i < NUM_THREADS; i++)
-    silc_fsm_uninit(&f->threads2[i].thread);
-
   SILC_LOG_DEBUG(("All %d real threads terminated", NUM_THREADS));
 
   /** Finished successfully */