moving method

This commit is contained in:
rusefi 2018-08-31 22:30:03 -04:00
parent 95117bcfdc
commit 49a301d57a
3 changed files with 32 additions and 30 deletions

View File

@ -110,10 +110,10 @@ static void vappendPrintfI(Logging *logging, const char *fmt, va_list arg) {
/**
* this method acquires system lock to guard the shared intermediateLoggingBuffer memory stream
*/
static void vappendPrintf(Logging *logging, const char *fmt, va_list arg) {
void Logging::vappendPrintf(const char *fmt, va_list arg) {
efiAssertVoid(CUSTOM_ERR_6604, getRemainingStack(chThdGetSelfX()) > 128, "lowstck#5b");
int wasLocked = lockAnyContext();
vappendPrintfI(logging, fmt, arg);
vappendPrintfI(this, fmt, arg);
if (!wasLocked) {
unlockAnyContext();
}
@ -124,7 +124,7 @@ void appendPrintf(Logging *logging, const char *fmt, ...) {
efiAssertVoid(CUSTOM_ERR_6607, getRemainingStack(chThdGetSelfX()) > 128, "lowstck#4");
va_list ap;
va_start(ap, fmt);
vappendPrintf(logging, fmt, ap);
logging->vappendPrintf(fmt, ap);
va_end(ap);
}
@ -132,7 +132,7 @@ void Logging::appendPrintf(const char *fmt, ...) {
efiAssertVoid(CUSTOM_ERR_6607, getRemainingStack(chThdGetSelfX()) > 128, "lowstck#4");
va_list ap;
va_start(ap, fmt);
vappendPrintf(this, fmt, ap);
vappendPrintf(fmt, ap);
va_end(ap);
}
@ -255,7 +255,7 @@ void printMsg(Logging *logger, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vappendPrintf(logger, fmt, ap);
logger->vappendPrintf(fmt, ap);
va_end(ap);
append(logger, DELIMETER);
@ -263,31 +263,6 @@ void printMsg(Logging *logger, const char *fmt, ...) {
resetLogging(logger);
}
/**
* this whole method is executed under syslock so that we can have multiple threads use the same shared buffer
* in order to reduce memory usage
*/
void scheduleMsg(Logging *logging, const char *fmt, ...) {
if (logging == NULL) {
warning(CUSTOM_ERR_LOGGING_NULL, "logging NULL");
return;
}
int wasLocked = lockAnyContext();
resetLogging(logging); // todo: is 'reset' really needed here?
appendMsgPrefix(logging);
va_list ap;
va_start(ap, fmt);
vappendPrintf(logging, fmt, ap);
va_end(ap);
appendMsgPostfix(logging);
scheduleLogging(logging);
if (!wasLocked) {
unlockAnyContext();
}
}
uint32_t remainingSize(Logging *logging) {
return logging->bufferSize - loggingSize(logging);
}

View File

@ -22,6 +22,7 @@ public:
Logging();
Logging(const char *name, char *buffer, int bufferSize);
void initLoggingExt(const char *name, char *buffer, int bufferSize);
void vappendPrintf(const char *fmt, va_list arg);
void append(const char *text);
void appendFast(const char *text);
void appendPrintf(const char *fmt, ...);

View File

@ -128,4 +128,30 @@ void initLoggingCentral(void) {
accumulatedSize = 0;
}
/**
* this whole method is executed under syslock so that we can have multiple threads use the same shared buffer
* in order to reduce memory usage
*/
void scheduleMsg(Logging *logging, const char *fmt, ...) {
if (logging == NULL) {
warning(CUSTOM_ERR_LOGGING_NULL, "logging NULL");
return;
}
int wasLocked = lockAnyContext();
resetLogging(logging); // todo: is 'reset' really needed here?
appendMsgPrefix(logging);
va_list ap;
va_start(ap, fmt);
logging->vappendPrintf(fmt, ap);
va_end(ap);
appendMsgPostfix(logging);
scheduleLogging(logging);
if (!wasLocked) {
unlockAnyContext();
}
}
#endif /* EFI_UNIT_TEST */