use ChfExit(); keep only the part of libChf that we use
This commit is contained in:
parent
2623dd28e5
commit
d3ef71cb2a
9 changed files with 56 additions and 345 deletions
|
@ -632,4 +632,5 @@ void EmulatorExit( enum ExitOption opt )
|
|||
/* Default behavior; do nothing */
|
||||
break;
|
||||
}
|
||||
ChfExit();
|
||||
}
|
||||
|
|
|
@ -7,8 +7,7 @@ SRC = src/chf_init.c \
|
|||
src/chf_abrt.c \
|
||||
src/chf_hdlr.c \
|
||||
src/chf_msgc.c \
|
||||
src/chf_st.c \
|
||||
src/chf_top.c
|
||||
src/chf_st.c
|
||||
|
||||
#
|
||||
# Target object files
|
||||
|
|
|
@ -168,4 +168,7 @@ void ChfPushHandler( const int module_id, ChfHandler new_handler, /* Handler to
|
|||
/* Signal the current conditions */
|
||||
void ChfSignal( const int module_id );
|
||||
|
||||
/* Exit */
|
||||
void ChfExit( void );
|
||||
|
||||
#endif /*!_CHF_H*/
|
||||
|
|
|
@ -149,24 +149,6 @@ int ChfInit( const char* app_name, /* Application's name */
|
|||
const int exit_code /* Abnormal exit code */
|
||||
);
|
||||
|
||||
/* Initialization with msgcat subsystem */
|
||||
/* int ChfMsgcatInit( const char* app_name, /\* Application's name *\/ */
|
||||
/* const ChfOptions options, /\* Options *\/ */
|
||||
/* const char* msgcat_name, /\* Name of the message catalog *\/ */
|
||||
/* const int condition_stack_size, /\* Size of the condition stack *\/ */
|
||||
/* const int handler_stack_size, /\* Size of the handler stack *\/ */
|
||||
/* const int exit_code /\* Abnormal exit code *\/ */
|
||||
/* ); */
|
||||
|
||||
/* /\* Pop a handler *\/ */
|
||||
/* void ChfPopHandler( const int module_id ); */
|
||||
|
||||
/* /\* Discard the current conditions *\/ */
|
||||
/* void ChfDiscard( void ); */
|
||||
|
||||
/* Exit */
|
||||
/* void ChfExit( void ); */
|
||||
|
||||
/* Abort application */
|
||||
void ChfAbort( const int abort_code );
|
||||
|
||||
|
|
|
@ -161,62 +161,3 @@ void ChfPushHandler( const int module_id, ChfHandler new_handler, void* unwind_c
|
|||
chf_context.handler_sp++;
|
||||
}
|
||||
}
|
||||
|
||||
/* .+
|
||||
|
||||
.title : ChfPopHandler
|
||||
.kind : C function
|
||||
.creation : 13-May-1996
|
||||
.description :
|
||||
This function pops the topmost condition handler from the handler stack and
|
||||
returns to the caller.
|
||||
|
||||
If some error occours during the execution, the function will generate
|
||||
and immediately signal one of the conditions listed below and marked with
|
||||
(*). The function will never return directly to the caller, since all
|
||||
conditions are CHF_FATAL.
|
||||
|
||||
NOTE: This function calls ChfAbort() with abort code CHF_ABORT_INIT if
|
||||
the CHF subsystem has not been initialized.
|
||||
|
||||
.call :
|
||||
ChfPopHandler();
|
||||
.input :
|
||||
void
|
||||
.output :
|
||||
void
|
||||
.status_codes :
|
||||
CHF_F_BAD_STATE, bad CHF state for requested operation
|
||||
CHF_F_HDLR_STACK_FULL, the handler stack is full
|
||||
.notes :
|
||||
1.1, 13-May-1996, creation
|
||||
1.6, 15-Jan-1997, update:
|
||||
- improved documentation
|
||||
2.1, 19-May-2000, update:
|
||||
- improved documentation
|
||||
|
||||
.- */
|
||||
/* void ChfPopHandler( /\* Pop a handler *\/ */
|
||||
/* const int module_id ) */
|
||||
/* { */
|
||||
/* /\* Make sure that CHF has been correctly initialized and is idle *\/ */
|
||||
/* if ( chf_context.state == CHF_UNKNOWN ) */
|
||||
/* ChfAbort( CHF_ABORT_INIT ); */
|
||||
|
||||
/* if ( chf_context.state != CHF_IDLE ) { */
|
||||
/* ChfGenerate( module_id, __FILE__, __LINE__, CHF_F_BAD_STATE, CHF_FATAL ); */
|
||||
|
||||
/* ChfSignal( module_id ); */
|
||||
/* } */
|
||||
|
||||
/* /\* Check if the handler stack is empty *\/ */
|
||||
/* else if ( chf_context.handler_sp == chf_context.handler_stack ) { */
|
||||
/* ChfGenerate( module_id, __FILE__, __LINE__, CHF_F_HDLR_STACK_EMPTY, CHF_FATAL ); */
|
||||
|
||||
/* ChfSignal( module_id ); */
|
||||
/* } */
|
||||
|
||||
/* /\* Discard the topmost condition handler *\/ */
|
||||
/* else */
|
||||
/* --chf_context.handler_sp; */
|
||||
/* } */
|
||||
|
|
|
@ -565,62 +565,62 @@ int ChfInit( /* Generic initialization */
|
|||
- added multithreading support
|
||||
|
||||
.- */
|
||||
/* void ChfExit( void ) */
|
||||
/* { */
|
||||
/* /\* Check that CHF has been correctly initialized *\/ */
|
||||
/* #ifndef _REENTRANT */
|
||||
/* if ( _chf_context.state == CHF_UNKNOWN ) */
|
||||
/* ChfAbort( CHF_ABORT_INIT ); */
|
||||
/* #else */
|
||||
/* /\* Reentrant check; lock context_mutex first *\/ */
|
||||
/* if ( pthread_mutex_lock( &context_mutex ) ) */
|
||||
/* ChfAbort( CHF_ABORT_PTHREAD ); */
|
||||
/* if ( _chf_context.state == CHF_UNKNOWN ) { */
|
||||
/* if ( pthread_mutex_unlock( &context_mutex ) ) */
|
||||
/* ChfAbort( CHF_ABORT_PTHREAD ); */
|
||||
/* ChfAbort( CHF_ABORT_INIT ); */
|
||||
/* } */
|
||||
/* #endif */
|
||||
void ChfExit( void )
|
||||
{
|
||||
/* Check that CHF has been correctly initialized */
|
||||
#ifndef _REENTRANT
|
||||
if ( _chf_context.state == CHF_UNKNOWN )
|
||||
ChfAbort( CHF_ABORT_INIT );
|
||||
#else
|
||||
/* Reentrant check; lock context_mutex first */
|
||||
if ( pthread_mutex_lock( &context_mutex ) )
|
||||
ChfAbort( CHF_ABORT_PTHREAD );
|
||||
if ( _chf_context.state == CHF_UNKNOWN ) {
|
||||
if ( pthread_mutex_unlock( &context_mutex ) )
|
||||
ChfAbort( CHF_ABORT_PTHREAD );
|
||||
ChfAbort( CHF_ABORT_INIT );
|
||||
}
|
||||
#endif
|
||||
|
||||
/* /\* Destroy the context associated with this thread now; this is necessary */
|
||||
/* to ensure that the context is actually destroyed when a single-threaded */
|
||||
/* application links with the multithreaded version of Chf: in this case, */
|
||||
/* pthread_exit() is called *after* ChfExit(), the Chf data key no longer */
|
||||
/* exists when pthread_exit() is called and the destructor registered */
|
||||
/* with pthread_key_create() does not take place. */
|
||||
/* The data pointer associated with the Chf data key is set to NULL to */
|
||||
/* avoid any subsequent reactivation of the destructor. */
|
||||
/* *\/ */
|
||||
/* #ifdef _REENTRANT */
|
||||
/* DestroyContext( &chf_context ); */
|
||||
/* if ( pthread_setspecific( data_key, ( void* )NULL ) ) { */
|
||||
/* ( void )pthread_mutex_unlock( &context_mutex ); */
|
||||
/* ChfAbort( CHF_ABORT_PTHREAD ); */
|
||||
/* } */
|
||||
/* #endif */
|
||||
/* Destroy the context associated with this thread now; this is necessary
|
||||
to ensure that the context is actually destroyed when a single-threaded
|
||||
application links with the multithreaded version of Chf: in this case,
|
||||
pthread_exit() is called *after* ChfExit(), the Chf data key no longer
|
||||
exists when pthread_exit() is called and the destructor registered
|
||||
with pthread_key_create() does not take place.
|
||||
The data pointer associated with the Chf data key is set to NULL to
|
||||
avoid any subsequent reactivation of the destructor.
|
||||
*/
|
||||
#ifdef _REENTRANT
|
||||
DestroyContext( &chf_context );
|
||||
if ( pthread_setspecific( data_key, ( void* )NULL ) ) {
|
||||
( void )pthread_mutex_unlock( &context_mutex );
|
||||
ChfAbort( CHF_ABORT_PTHREAD );
|
||||
}
|
||||
#endif
|
||||
|
||||
/* /\* Shut down the message retrieval subsystem first *\/ */
|
||||
/* _chf_context.mrs_exit( _chf_context.mrs_data ); */
|
||||
/* Shut down the message retrieval subsystem first */
|
||||
_chf_context.mrs_exit( _chf_context.mrs_data );
|
||||
|
||||
/* #ifndef _REENTRANT */
|
||||
/* /\* Free the dynamic memory previously allocated *\/ */
|
||||
/* free( _chf_context.message_buffer ); */
|
||||
/* free( _chf_context.handler_stack ); */
|
||||
/* free( _chf_context.condition_stack ); */
|
||||
/* #else */
|
||||
/* /\* Destroy the Chf data key *\/ */
|
||||
/* if ( pthread_key_delete( data_key ) ) */
|
||||
/* ChfAbort( CHF_ABORT_PTHREAD ); */
|
||||
/* #endif */
|
||||
#ifndef _REENTRANT
|
||||
/* Free the dynamic memory previously allocated */
|
||||
free( _chf_context.message_buffer );
|
||||
free( _chf_context.handler_stack );
|
||||
free( _chf_context.condition_stack );
|
||||
#else
|
||||
/* Destroy the Chf data key */
|
||||
if ( pthread_key_delete( data_key ) )
|
||||
ChfAbort( CHF_ABORT_PTHREAD );
|
||||
#endif
|
||||
|
||||
/* /\* Reset CHF state to prevent subsequent calls to ChfExit() itself *\/ */
|
||||
/* _chf_context.state = CHF_UNKNOWN; */
|
||||
/* Reset CHF state to prevent subsequent calls to ChfExit() itself */
|
||||
_chf_context.state = CHF_UNKNOWN;
|
||||
|
||||
/* #ifdef _REENTRANT */
|
||||
/* if ( pthread_mutex_unlock( &context_mutex ) ) */
|
||||
/* ChfAbort( CHF_ABORT_PTHREAD ); */
|
||||
/* #endif */
|
||||
/* } */
|
||||
#ifdef _REENTRANT
|
||||
if ( pthread_mutex_unlock( &context_mutex ) )
|
||||
ChfAbort( CHF_ABORT_PTHREAD );
|
||||
#endif
|
||||
}
|
||||
|
||||
/* .+
|
||||
|
||||
|
|
|
@ -59,83 +59,3 @@ static void ExitMessage( void* private_context )
|
|||
( void )catclose( ( ( ChfMsgcatContext* )private_context )->catalog );
|
||||
free( private_context );
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
Public functions
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* .+
|
||||
|
||||
.title : ChfMsgcatInit
|
||||
.kind : C function
|
||||
.creation : 17-May-1996
|
||||
.description :
|
||||
This function initializes CHF and returns to the caller a condition code;
|
||||
that code will be either CHF_S_OK if the initialization was succesful,
|
||||
or one of the other values listed below.
|
||||
|
||||
It's necessary to invoke succesfully either ChfMsgcatInit() or one of the
|
||||
other CHF initialization routines before using any other CHF function.
|
||||
|
||||
NOTE: This function will call ChfAbort() with abort code CHF_ABORT_DUP_INIT
|
||||
if CHF has already been initialized before.
|
||||
|
||||
WIN32:
|
||||
|
||||
- this function is not available due to lack of system support, and
|
||||
always returns CHF_F_NOT_AVAILABLE
|
||||
|
||||
.call :
|
||||
cc = ChfMsgcatInit(app_name, options,
|
||||
msgcat_name,
|
||||
condition_stack_size, handler_stack_size,
|
||||
exit_code);
|
||||
.input :
|
||||
const char *app_name, Application's name
|
||||
const ChfOptions options, Options
|
||||
const char *msgcat_name, Name of the message catalog
|
||||
const int condition_stack_size, Size of the condition stack
|
||||
const int handler_stack_size, Size of the handler stack
|
||||
const int exit_code, Abnormal exit code
|
||||
.output :
|
||||
int cc, condition code
|
||||
.status_codes :
|
||||
CHF_F_SETLOCALE, setlocale() failed
|
||||
CHF_F_CATOPEN, catopen() failed
|
||||
CHF_F_MALLOC, FATAL, memory allocation failed
|
||||
CHF_F_NOT_AVAILABLE, FATAL, function not available
|
||||
.notes :
|
||||
1.1, 17-May-1996, creation
|
||||
2.2, 22-Jan-2001, update:
|
||||
- added Win32 support
|
||||
|
||||
.- */
|
||||
/* int ChfMsgcatInit( /\* Initialization with msgcat subsystem *\/ */
|
||||
/* const char* app_name, /\* Application's name *\/ */
|
||||
/* const ChfOptions options, /\* Options *\/ */
|
||||
/* const char* msgcat_name, /\* Name of the message catalog *\/ */
|
||||
/* const int condition_stack_size, /\* Size of the condition stack *\/ */
|
||||
/* const int handler_stack_size, /\* Size of the handler stack *\/ */
|
||||
/* const int exit_code /\* Abnormal exit code *\/ */
|
||||
/* ) */
|
||||
/* { */
|
||||
/* ChfMsgcatContext* private_context; */
|
||||
/* int cc; */
|
||||
|
||||
/* if ( ( private_context = ( ChfMsgcatContext* )malloc( sizeof( ChfMsgcatContext ) ) ) == ( ChfMsgcatContext* )NULL ) */
|
||||
/* cc = CHF_F_MALLOC; */
|
||||
/* else if ( setlocale( LC_ALL, "" ) == ( char* )NULL ) { */
|
||||
/* free( private_context ); */
|
||||
/* cc = CHF_F_SETLOCALE; */
|
||||
/* } else if ( ( private_context->catalog = catopen( msgcat_name, 0 ) ) == ( nl_catd )( -1 ) ) { */
|
||||
/* free( private_context ); */
|
||||
/* cc = CHF_F_CATOPEN; */
|
||||
/* } else if ( ( cc = ChfInit( app_name, options, ( void* )private_context, GetMessage, ExitMessage, condition_stack_size, */
|
||||
/* handler_stack_size, exit_code ) ) != CHF_S_OK ) { */
|
||||
/* ( void )catclose( private_context->catalog ); */
|
||||
/* free( private_context ); */
|
||||
/* } else */
|
||||
/* cc = CHF_S_OK; */
|
||||
|
||||
/* return cc; */
|
||||
/* } */
|
||||
|
|
|
@ -319,42 +319,3 @@ void ChfSignal( const int module_id )
|
|||
/* Restore the old CHF state */
|
||||
chf_context.state = saved_state;
|
||||
}
|
||||
|
||||
/* .+
|
||||
|
||||
.title : ChfDiscard
|
||||
.kind : C function
|
||||
.creation : 17-May-1996
|
||||
.description :
|
||||
This function discards the topmost condition group currently in the
|
||||
condition stack, without signalling it. The function does nothing if
|
||||
the condition stack is empty.
|
||||
|
||||
NOTE: This function uses the CHF function 'ChfAbort()' to
|
||||
abort the application if either
|
||||
- CHF has not been initialized correctly (abort code CHF_ABORT_INIT)
|
||||
|
||||
.call :
|
||||
ChfDiscard();
|
||||
.input :
|
||||
void
|
||||
.output :
|
||||
void
|
||||
.status_codes :
|
||||
none
|
||||
.notes :
|
||||
1.1, 17-May-1996, creation
|
||||
|
||||
.- */
|
||||
/* void ChfDiscard( /\* Discard the current conditions *\/ */
|
||||
/* void ) */
|
||||
/* { */
|
||||
/* /\* Check that CHF has been correctly initialized *\/ */
|
||||
/* if ( chf_context.state == CHF_UNKNOWN ) */
|
||||
/* ChfAbort( CHF_ABORT_INIT ); */
|
||||
|
||||
/* /\* Reset the current condition stack pointer to the current condition */
|
||||
/* stack base pointer */
|
||||
/* *\/ */
|
||||
/* chf_context.condition_sp = chf_context.condition_base; */
|
||||
/* } */
|
||||
|
|
|
@ -1,96 +0,0 @@
|
|||
/* .+
|
||||
|
||||
.identifier : $Id: chf_top.c,v 2.2 2001/01/25 14:09:21 cibrario Exp $
|
||||
.context : CHF, Condition Handling Facility
|
||||
.title : $RCSfile: chf_top.c,v $
|
||||
.kind : C source
|
||||
.author : Ivan Cibrario B.
|
||||
.site : CSTV-CNR
|
||||
.creation : 5-Jun-1996
|
||||
.keywords : *
|
||||
.description :
|
||||
This module implements the CHF function ChfGetTopCondition()
|
||||
|
||||
.include : Chf.h
|
||||
|
||||
.notes :
|
||||
$Log: chf_top.c,v $
|
||||
Revision 2.2 2001/01/25 14:09:21 cibrario
|
||||
Added partial Win32 support (Windows CE only).
|
||||
|
||||
Revision 2.1 2000/05/26 14:23:33 cibrario
|
||||
ChfGetTopCondition() used to return a pointer to the wrong condition
|
||||
descriptor; fixed.
|
||||
|
||||
Revision 1.2 1996/06/11 12:47:17 cibrario
|
||||
file creation
|
||||
|
||||
|
||||
.- */
|
||||
|
||||
#include "Chf.h"
|
||||
#include "ChfPriv.h"
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
Public functions
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* .+
|
||||
|
||||
.title : ChfGetTopCondition
|
||||
.kind : C function
|
||||
.creation : 5-Jun-1996
|
||||
.description :
|
||||
This function returns to the caller a pointer to the top condition of
|
||||
the current condition group. It generates and immediately signals the
|
||||
condition CHF_F_BAD_STATE if the current condition group is empty.
|
||||
|
||||
|
||||
NOTE: During condition signalling, CHF creates a new, empty, condition group
|
||||
immediately before starting the invocation sequence of the condition
|
||||
handlers, as described in the documentation. Therefore
|
||||
ChfGetTopCondition(), if called from a condition handler, will return
|
||||
a pointer to the top condition generated during the handling ONLY, and
|
||||
NOT to the top condition of the condition group being signalled. The
|
||||
latter pointer is directly available, as an argument, to the condition
|
||||
handlers.
|
||||
|
||||
NOTE: This function will call ChfAbort() with abort code CHF_ABORT_INIT
|
||||
if CHF hasn't been correctly initialized.
|
||||
|
||||
NOTE: The returned pointer is no longer valid when any other CHF function
|
||||
is called after ChfGetTopCondition().
|
||||
|
||||
.call :
|
||||
d = ChfGetTopCondition();
|
||||
.input :
|
||||
void
|
||||
.output :
|
||||
const ChfDescriptor *d, condition descriptor
|
||||
.status_codes :
|
||||
|
||||
.notes :
|
||||
1.2, 17-May-1996, creation
|
||||
2.1, 24-May-2000, bug fix:
|
||||
- condition stack referenced incorrectly
|
||||
|
||||
.- */
|
||||
/* Retrieve top condition */
|
||||
/* const ChfDescriptor* ChfGetTopCondition( const int module_id ) */
|
||||
/* { */
|
||||
/* ChfDescriptor* d; */
|
||||
|
||||
/* /\* Check that CHF has been correctly initialized *\/ */
|
||||
/* if ( chf_context.state == CHF_UNKNOWN ) */
|
||||
/* ChfAbort( CHF_ABORT_INIT ); */
|
||||
|
||||
/* if ( ( d = chf_context.condition_sp ) == chf_context.condition_base ) { */
|
||||
/* ChfGenerate( module_id, __FILE__, __LINE__, CHF_F_BAD_STATE, CHF_FATAL ); */
|
||||
/* ChfSignal( module_id ); */
|
||||
/* } */
|
||||
|
||||
/* /\* The top element of the condition group is the element immediately */
|
||||
/* below the stack pointer. */
|
||||
/* *\/ */
|
||||
/* return d - 1; */
|
||||
/* } */
|
Loading…
Add table
Reference in a new issue