Made Util::streamName and exitReason thread-local
This commit is contained in:
parent
7c6da9d455
commit
7423868de4
11 changed files with 40 additions and 32 deletions
|
@ -30,6 +30,7 @@
|
|||
#include <iostream>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h> // for va_list
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -39,8 +40,13 @@ bool Util::Config::is_active = false;
|
|||
bool Util::Config::is_restarting = false;
|
||||
static Socket::Server *serv_sock_pointer = 0;
|
||||
uint32_t Util::printDebugLevel = DEBUG;
|
||||
std::string Util::streamName;
|
||||
char Util::exitReason[256] ={0};
|
||||
__thread char Util::streamName[256] = {0};
|
||||
__thread char Util::exitReason[256] ={0};
|
||||
|
||||
|
||||
void Util::setStreamName(const std::string & sn){
|
||||
strncpy(Util::streamName, sn.c_str(), 256);
|
||||
}
|
||||
|
||||
void Util::logExitReason(const char *format, ...){
|
||||
if (exitReason[0]){return;}
|
||||
|
|
|
@ -14,8 +14,9 @@
|
|||
/// Contains utility code, not directly related to streaming media
|
||||
namespace Util{
|
||||
extern uint32_t printDebugLevel;
|
||||
extern std::string streamName; ///< Used by debug messages to identify the stream name
|
||||
extern char exitReason[256];
|
||||
extern __thread char streamName[256]; ///< Used by debug messages to identify the stream name
|
||||
void setStreamName(const std::string & sn);
|
||||
extern __thread char exitReason[256];
|
||||
void logExitReason(const char *format, ...);
|
||||
|
||||
/// Deals with parsing configuration from commandline options.
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
//Declare as extern so we don't have to include the whole config.h header
|
||||
namespace Util{
|
||||
extern uint32_t printDebugLevel;
|
||||
extern std::string streamName;
|
||||
extern __thread char streamName[256];
|
||||
}
|
||||
|
||||
static const char *DBG_LVL_LIST[] ={"NONE", "FAIL", "ERROR", "WARN", "INFO", "MEDIUM",
|
||||
|
@ -53,13 +53,13 @@ static const char *DBG_LVL_LIST[] ={"NONE", "FAIL", "ERROR", "WARN", "IN
|
|||
#define DEBUG_MSG(lvl, msg, ...) \
|
||||
if (Util::printDebugLevel >= lvl){\
|
||||
fprintf(stderr, "%s|%s|%d|%s:%d|%s|" msg "\n", DBG_LVL_LIST[lvl], program_invocation_short_name, \
|
||||
getpid(), __FILE__, __LINE__, Util::streamName.c_str(), ##__VA_ARGS__); \
|
||||
getpid(), __FILE__, __LINE__, Util::streamName, ##__VA_ARGS__); \
|
||||
}
|
||||
#else
|
||||
#define DEBUG_MSG(lvl, msg, ...) \
|
||||
if (Util::printDebugLevel >= lvl){\
|
||||
fprintf(stderr, "%s|%s|%d||%s|" msg "\n", DBG_LVL_LIST[lvl], program_invocation_short_name, \
|
||||
getpid(), Util::streamName.c_str(), ##__VA_ARGS__); \
|
||||
getpid(), Util::streamName, ##__VA_ARGS__); \
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
|
@ -67,13 +67,13 @@ static const char *DBG_LVL_LIST[] ={"NONE", "FAIL", "ERROR", "WARN", "IN
|
|||
#define DEBUG_MSG(lvl, msg, ...) \
|
||||
if (Util::printDebugLevel >= lvl){\
|
||||
fprintf(stderr, "%s|MistProcess|%d|%s:%d|%s|" msg "\n", DBG_LVL_LIST[lvl], getpid(), __FILE__, \
|
||||
__LINE__, Util::streamName.c_str(), ##__VA_ARGS__); \
|
||||
__LINE__, Util::streamName, ##__VA_ARGS__); \
|
||||
}
|
||||
#else
|
||||
#define DEBUG_MSG(lvl, msg, ...) \
|
||||
if (Util::printDebugLevel >= lvl){\
|
||||
fprintf(stderr, "%s|MistProcess|%d||%s|" msg "\n", DBG_LVL_LIST[lvl], getpid(), \
|
||||
Util::streamName.c_str(), ##__VA_ARGS__); \
|
||||
Util::streamName, ##__VA_ARGS__); \
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue