Skip to content
Snippets Groups Projects
Commit 7a625ca8 authored by Philip Mueller's avatar Philip Mueller
Browse files

There is now a sectond version of the panic function "quietPanic".

This function does not realy need runtime support.
And can thus be called anytime.

I also updated the description of the panic function to reflect it.
The original panic function now checks if the runtime is initialized or not.
If not the quiet version is called.
parent 3467b8f8
No related branches found
No related tags found
No related merge requests found
......@@ -154,18 +154,20 @@ void
__attribute__((constructor(65000)))
cLibSibylRT_init(void)
{
if(cLibSibylRT_isInit_var == 0) /* test if already initialized, good practice to test */
{
return;
};
/* test if already initialized, good practice to test */
if(cLibSibylRT_isInit_var == 0)
{ return; };
/* Initialized the look for the error messages */
/* Initialized the look for the error state */
if(mtx_init(&cLibSibylRT_errorLock_var, mtx_plain) != thrd_success)
{
cLibSibylRT_panic("Could not initialize the error lock.");
cLibSibylRT_quietPanic();
return;
};
/* Now we set the value to a non zero value */
__asm__ volatile ("mfence" ::: "memory");
cLibSibylRT_isInit_var = 0;
......@@ -184,12 +186,16 @@ void
cLibSibylRT_panic(
char* msg)
{
/* Test if the runtime is not initialized */
if(cLibSibylRT_isInit() != 0)
{ cLibSibylRT_quietPanic(); };
/* Get the current time */
time_t t = time(NULL);
struct tm* tmp = localtime(&t);
if(tmp == NULL)
{ abort(); };
{ cLibSibylRT_quietPanic(); };
/* copy it into a better format */
struct tm buf = *tmp;
......@@ -198,7 +204,7 @@ cLibSibylRT_panic(
FILE* panicLog = fopen("cLibSibyl_panic.log", "a+");
if(panicLog == NULL)
{ abort(); };
{ cLibSibylRT_quietPanic(); };
/* Get the PID */
const Int_t PID = cLibSibylRT_getPID();
......@@ -208,24 +214,35 @@ cLibSibylRT_panic(
PID,
buf.tm_year + 1900, buf.tm_mon + 1, buf.tm_mday + 1,
buf.tm_hour, buf.tm_min);
if(w <= 0)
{ abort(); };
if(w <= 0) /* Test if something was written */
{ cLibSibylRT_quietPanic(); };
if(msg != NULL)
{
w = fprintf(panicLog, " the reason was \"%s\"", msg);
if(w <= 0)
{ abort(); };
if(w <= 0) /* Test if something was written */
{ cLibSibylRT_quietPanic(); };
};
/* Print a new line to the file */
fprintf(panicLog, "\n");
/* Close the file */
fclose(panicLog);
abort();
}; //End panic
/* Call now the quite version of this function */
cLibSibylRT_quietPanic();
}; /* End panic */
void
cLibSibylRT_quietPanic()
{
/* we imediatly call the abort function */
abort();
}; /* End: quitePanic */
void
cLibSibylRT_outputImpl(
char* msg)
......
......@@ -262,11 +262,15 @@
/**
* \briefe This is the panic function. It will lead to the abortion of the process.
*
* This function will call abort() of the C runtime and the Python interpreter will
* exit, this si not diesirable and should only be done in the case of an unrecovarable
* error. It also accepts an optional string argument taht will be printed.
* This function will call exit the program, which also aborts the Python interpreter.
* This is a not desirable effect, and should only be called if necessary.
* The function will print the passed text to a file.
*
* This function does not requieres that the runtime system is initialized.
* Note calling this function, even with NULL as argument, needs runtime support.
* If you are unable to guarante a proper runtime situations, you should consider
* using cLibSibylRT_quietPanic(), which does not requiere runtime stupport.
*
* If the runtime is not initialized, quietPanic will be called.
*
* \param msg Optional message argument, set to NULL to not print.
*/
......@@ -278,6 +282,21 @@ cLibSibylRT_panic(
CSIBYL_ATTR_NORETURN;
/**
* \brief This is the quiet panic function.
*
* What differes this function from the other one, it does not requieres
* the runtime to be pressent.
*
* It will imediatly call abort() of the C-Runtime.
*/
extern
CSIBYL_INTERN
void
cLibSibylRT_quietPanic()
CSIBYL_ATTR_NORETURN;
/**
* \brief This function checks if the runtime is initialized.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment