Ejemplo n.º 1
0
static TA_RetCode TA_SystemGlobalShutdown( void *globalAllocated )
{
   TA_PROLOG
   TA_RetCode retCode, finalRetCode;
   TA_SystemGlobal *global;

   TA_TRACE_BEGIN( TA_SystemGlobalShutdown );

   /* No need to shutdown if the initialization failed. */
   if( globalAllocated == NULL )
   {
      TA_TRACE_RETURN( TA_SUCCESS );
   }

   finalRetCode = TA_SUCCESS;

   global = (TA_SystemGlobal *)globalAllocated;

   if( global->dirnameCache )
   {
      retCode = TA_StringCacheFree( global->dirnameCache );
      TA_ASSERT( retCode == TA_SUCCESS );
      if( retCode != TA_SUCCESS )
         finalRetCode = retCode;
   }

   if( global->filenameCache )
   {
      retCode = TA_StringCacheFree( global->filenameCache );
      TA_ASSERT( retCode == TA_SUCCESS );
      if( retCode != TA_SUCCESS )
         finalRetCode = retCode;
   }

   TA_Free(  global );

   TA_TRACE_RETURN( finalRetCode );
}
Ejemplo n.º 2
0
static TA_RetCode TA_SystemGlobalInit( void **globalToAlloc )
{
   TA_PROLOG
   TA_RetCode retCode;
   TA_SystemGlobal *global;

   TA_TRACE_BEGIN( TA_SystemGlobalInit );

   TA_ASSERT( globalToAlloc != NULL );

   *globalToAlloc = NULL;

   global = (TA_SystemGlobal *)TA_Malloc( sizeof( TA_SystemGlobal ) );
   if( !global )
   {
      TA_TRACE_RETURN( TA_ALLOC_ERR );
   }

   memset( global, 0, sizeof( TA_SystemGlobal ) );

   retCode = TA_StringCacheAlloc( &global->dirnameCache );
   if( retCode != TA_SUCCESS )
   {
      TA_Free( global );
      TA_TRACE_RETURN( TA_ALLOC_ERR );
   }

   retCode = TA_StringCacheAlloc( &global->filenameCache );
   if( retCode != TA_SUCCESS )
   {
      TA_StringCacheFree( global->dirnameCache );
      TA_Free( global );
      TA_TRACE_RETURN( TA_ALLOC_ERR );
   }

   /* Success! Return the global to the caller. */
   *globalToAlloc = global;
   TA_TRACE_RETURN( TA_SUCCESS );
}
Ejemplo n.º 3
0
TA_RetCode TA_Shutdown( void )
{
    /* Note: Keep that function simple.
     *       No tracing, no stdio and no assert.
     */
    const TA_GlobalControl *control;
    unsigned int i;
    TA_RetCode retCode, finalRetCode;

    if( TA_Globals->magicNb != TA_LIBC_PRIV_MAGIC_NB )
        return TA_LIB_NOT_INITIALIZE;

    /* Will change if an error occured at any point. */
    finalRetCode = TA_SUCCESS;

    /* Shutdown all the modules who were initialized.
     * Also destroy the corresponding semaphore.
     */
    for( i=0; i < TA_NB_GLOBAL_ID; i++ )
    {
        /* Disable tracing when starting to shut down
         * the tracing module. This is to avoid that
         * the memory module starts do some tracing while we
         * are shutting down the tracing itself!!!
         */
        if( i == TA_TRACE_GLOBAL_ID )
            TA_Globals->traceEnabled = 0;

#if !defined( TA_SINGLE_THREAD )
        if( TA_Globals->moduleControl[i].sema.flags & TA_SEMA_INITIALIZED )
        {
            retCode = TA_SemaWait( &(TA_Globals->moduleControl[i].sema) );
            if( retCode != TA_SUCCESS )
                finalRetCode = retCode;
#endif

            /* Just before shutting down the ta_memory module,
             * free the global string cache.
             */
            if( (i == TA_MEMORY_GLOBAL_ID) && (TA_Globals->dfltCache) )
            {
                retCode = TA_StringCacheFree( TA_Globals->dfltCache );
                if( retCode != TA_SUCCESS )
                    finalRetCode = retCode;
            }

            if( TA_Globals->moduleControl[i].initialize )
            {
                control = TA_Globals->moduleControl[i].control;
                if( control && control->shutdown )
                {
                    retCode = (*control->shutdown)( TA_Globals->moduleControl[i].global );
                    if( retCode != TA_SUCCESS )
                        finalRetCode = retCode;
                }
                TA_Globals->moduleControl[i].initialize = 0;
            }

#if !defined( TA_SINGLE_THREAD )
            retCode = TA_SemaDestroy( &(TA_Globals->moduleControl[i].sema) );
            if( retCode != TA_SUCCESS )
                finalRetCode = retCode;
        }
#endif
    }

    /* Initialize to all zero to make sure we invalidate that object. */
    memset( TA_Globals, 0, sizeof( TA_LibcPriv ) );

    return finalRetCode;
}