forked from speed-dreams/speed-dreams-code
Trace some infos about the current OS at startup (name, version, nb of bits, ...)
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5067 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: c005b39304949a349750d7e57a8178dc2497f1a1 Former-commit-id: d00bcf46def9ce2f1d6994d6851ec1c959fcad53
This commit is contained in:
parent
399bf7ddc0
commit
fb94b2fb9f
6 changed files with 970 additions and 875 deletions
|
@ -72,6 +72,35 @@ GfApplication::GfApplication(const char* pszName, const char* pszVersion, const
|
|||
// Initialize the gaming framework.
|
||||
GfInit();
|
||||
|
||||
// Trace current OS information.
|
||||
std::string strName;
|
||||
int nMajor, nMinor, nPatch, nBits;
|
||||
if (GfGetOSInfo(strName, nMajor, nMinor, nPatch, nBits))
|
||||
{
|
||||
GfLogInfo("Current OS is %s", (strName.empty() ? "unknown" : strName.c_str()));
|
||||
if (nMajor >= 0)
|
||||
{
|
||||
GfLogInfo(" (R%d", nMajor);
|
||||
if (nMinor >= 0)
|
||||
{
|
||||
GfLogInfo(".%d", nMinor);
|
||||
if (nPatch >= 0)
|
||||
GfLogInfo(".%d", nPatch);
|
||||
}
|
||||
}
|
||||
if (nBits >= 0)
|
||||
{
|
||||
if (nMajor >= 0)
|
||||
GfLogInfo(", ");
|
||||
else
|
||||
GfLogInfo(" (");
|
||||
GfLogInfo("%d bits", nBits);
|
||||
}
|
||||
if (nMajor >= 0 || nBits >= 0)
|
||||
GfLogInfo(")");
|
||||
GfLogInfo("\n");
|
||||
}
|
||||
|
||||
// Trace build information.
|
||||
GfLogInfo("Built on %s\n", SD_BUILD_INFO_SYSTEM);
|
||||
GfLogInfo(" with CMake %s, '%s' generator\n",
|
||||
|
@ -173,13 +202,13 @@ void GfApplication::restart()
|
|||
|
||||
// Restart the process, using same command line args.
|
||||
// 1) The process executable path-name is the 1st arg left untouched.
|
||||
GfLogInfo("Restarting :\n");
|
||||
GfLogInfo(" Command : %s\n", _lstArgs.front().c_str());
|
||||
GfLogInfo("Restarting :\n");
|
||||
GfLogInfo(" Command : %s\n", _lstArgs.front().c_str());
|
||||
|
||||
// 2) Allocate and populate the args array (last arg must be a null pointer).
|
||||
// TODO: Add an API for filtering the args (some might not be relevant for a restart).
|
||||
GfLogInfo(" Args : ");
|
||||
char** apszArgs = (char**)malloc(sizeof(char*) * (_lstArgs.size() + 1));
|
||||
GfLogInfo(" Args : ");
|
||||
char** apszArgs = (char**)malloc(sizeof(char*) * (_lstArgs.size() + 1));
|
||||
|
||||
unsigned nArgInd = 0;
|
||||
std::list<std::string>::const_iterator itArg;
|
||||
|
@ -212,18 +241,18 @@ void GfApplication::restart()
|
|||
nArgInd++;
|
||||
}
|
||||
apszArgs[nArgInd] = 0;
|
||||
GfLogInfo("...\n\n");
|
||||
GfLogInfo("...\n\n");
|
||||
|
||||
// 3) Exec the command with its args (replacing current process).
|
||||
const int retcode = execvp(_lstArgs.front().c_str(), apszArgs);
|
||||
// 3) Exec the command with its args (replacing current process).
|
||||
const int retcode = execvp(_lstArgs.front().c_str(), apszArgs);
|
||||
|
||||
// If the restart was successfull, we never get there ... But if it failed ...
|
||||
GfLogError("Failed to restart (exit code %d, %s)\n", retcode, strerror(errno));
|
||||
for (nArgInd = 0; apszArgs[nArgInd]; nArgInd++)
|
||||
// If the restart was successfull, we never get there ... But if it failed ...
|
||||
GfLogError("Failed to restart (exit code %d, %s)\n", retcode, strerror(errno));
|
||||
for (nArgInd = 0; apszArgs[nArgInd]; nArgInd++)
|
||||
free(apszArgs[nArgInd]);
|
||||
free(apszArgs);
|
||||
|
||||
exit(1);
|
||||
free(apszArgs);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void GfApplication::printUsage(const char* pszErrMsg) const
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/***************************************************************************
|
||||
|
||||
file : linuxspec.cpp
|
||||
created : Sat Mar 18 23:54:05 CET 2000
|
||||
copyright : (C) 2000 by Eric Espie
|
||||
email : torcs@free.fr
|
||||
version : $Id$
|
||||
|
||||
|
||||
file : linuxspec.cpp
|
||||
created : Sat Mar 18 23:54:05 CET 2000
|
||||
copyright : (C) 2000 by Eric Espie
|
||||
email : torcs@free.fr
|
||||
version : $Id$
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
|
@ -34,6 +34,7 @@
|
|||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/utsname.h> // uname
|
||||
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
|
||||
#include <sys/param.h>
|
||||
|
@ -83,44 +84,44 @@
|
|||
static int
|
||||
linuxModLoad(unsigned int /* gfid */, const char *sopath, tModList **modlist)
|
||||
{
|
||||
tSOHandle handle;
|
||||
tModList* curMod;
|
||||
|
||||
/* Try and avoid loading the same module twice (WARNING: Only checks sopath equality !) */
|
||||
if ((curMod = GfModIsInList(sopath, *modlist)) != 0)
|
||||
{
|
||||
GfLogInfo("Module %s already loaded\n", sopath);
|
||||
GfModMoveToListHead(curMod, modlist); // Force module to be the first in the list.
|
||||
return 0;
|
||||
}
|
||||
|
||||
GfLogInfo("Loading module %s\n", sopath);
|
||||
|
||||
/* Load the shared library */
|
||||
handle = dlopen(sopath, RTLD_LAZY);
|
||||
if (handle)
|
||||
{
|
||||
/* Initialize the module */
|
||||
if (GfModInitialize(handle, sopath, GfIdAny, &curMod) == 0)
|
||||
tSOHandle handle;
|
||||
tModList* curMod;
|
||||
|
||||
/* Try and avoid loading the same module twice (WARNING: Only checks sopath equality !) */
|
||||
if ((curMod = GfModIsInList(sopath, *modlist)) != 0)
|
||||
{
|
||||
if (curMod) /* Retained against GfIdAny */
|
||||
// Add the loaded module at the head of the list (no sort by priority).
|
||||
GfModAddInList(curMod, modlist, /* priosort */ 0);
|
||||
GfLogInfo("Module %s already loaded\n", sopath);
|
||||
GfModMoveToListHead(curMod, modlist); // Force module to be the first in the list.
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
|
||||
GfLogInfo("Loading module %s\n", sopath);
|
||||
|
||||
/* Load the shared library */
|
||||
handle = dlopen(sopath, RTLD_LAZY);
|
||||
if (handle)
|
||||
{
|
||||
dlclose(handle);
|
||||
GfLogError("linuxModLoad: Module init function failed %s\n", sopath);
|
||||
return -1;
|
||||
/* Initialize the module */
|
||||
if (GfModInitialize(handle, sopath, GfIdAny, &curMod) == 0)
|
||||
{
|
||||
if (curMod) /* Retained against GfIdAny */
|
||||
// Add the loaded module at the head of the list (no sort by priority).
|
||||
GfModAddInList(curMod, modlist, /* priosort */ 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
dlclose(handle);
|
||||
GfLogError("linuxModLoad: Module init function failed %s\n", sopath);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GfLogError("linuxModLoad: ... %s\n", dlerror());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
GfLogError("linuxModLoad: ... %s\n", dlerror());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -152,52 +153,52 @@ linuxModLoad(unsigned int /* gfid */, const char *sopath, tModList **modlist)
|
|||
static int
|
||||
linuxModInfo(unsigned int /* gfid */, const char *sopath, tModList **modlist)
|
||||
{
|
||||
tSOHandle handle;
|
||||
tModList *curMod;
|
||||
int infoSts = 0;
|
||||
|
||||
/* Try and avoid loading the same module twice (WARNING: Only checks sopath equality !) */
|
||||
if ((curMod = GfModIsInList(sopath, *modlist)) != 0)
|
||||
{
|
||||
GfLogInfo("Module %s already requested\n", sopath);
|
||||
GfModMoveToListHead(curMod, modlist); // Force module to be the first in the list.
|
||||
return infoSts;
|
||||
}
|
||||
|
||||
GfLogTrace("Querying module %s\n", sopath);
|
||||
|
||||
/* Load the shared library */
|
||||
handle = dlopen(sopath, RTLD_LAZY);
|
||||
if (handle)
|
||||
{
|
||||
/* Initialize the module */
|
||||
if (GfModInitialize(handle, sopath, GfIdAny, &curMod) == 0)
|
||||
tSOHandle handle;
|
||||
tModList *curMod;
|
||||
int infoSts = 0;
|
||||
|
||||
/* Try and avoid loading the same module twice (WARNING: Only checks sopath equality !) */
|
||||
if ((curMod = GfModIsInList(sopath, *modlist)) != 0)
|
||||
{
|
||||
if (curMod) /* Retained against GfIdAny */
|
||||
{
|
||||
// Add the loaded module at the head of the list (no sort by priority).
|
||||
GfModAddInList(curMod, modlist, /* priosort */ 0);
|
||||
}
|
||||
|
||||
/* Terminate the module */
|
||||
infoSts = GfModTerminate(handle, sopath);
|
||||
GfLogInfo("Module %s already requested\n", sopath);
|
||||
GfModMoveToListHead(curMod, modlist); // Force module to be the first in the list.
|
||||
return infoSts;
|
||||
}
|
||||
|
||||
GfLogTrace("Querying module %s\n", sopath);
|
||||
|
||||
/* Load the shared library */
|
||||
handle = dlopen(sopath, RTLD_LAZY);
|
||||
if (handle)
|
||||
{
|
||||
/* Initialize the module */
|
||||
if (GfModInitialize(handle, sopath, GfIdAny, &curMod) == 0)
|
||||
{
|
||||
if (curMod) /* Retained against GfIdAny */
|
||||
{
|
||||
// Add the loaded module at the head of the list (no sort by priority).
|
||||
GfModAddInList(curMod, modlist, /* priosort */ 0);
|
||||
}
|
||||
|
||||
/* Terminate the module */
|
||||
infoSts = GfModTerminate(handle, sopath);
|
||||
}
|
||||
else
|
||||
{
|
||||
GfLogError("linuxModInfo: Module init function failed %s\n", sopath);
|
||||
infoSts = -1;
|
||||
}
|
||||
|
||||
/* Close the DLL whatever happened */
|
||||
dlclose(handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
GfLogError("linuxModInfo: Module init function failed %s\n", sopath);
|
||||
infoSts = -1;
|
||||
GfLogError("linuxModInfo: ... %s\n", dlerror());
|
||||
infoSts = -1;
|
||||
}
|
||||
|
||||
/* Close the DLL whatever happened */
|
||||
dlclose(handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
GfLogError("linuxModInfo: ... %s\n", dlerror());
|
||||
infoSts = -1;
|
||||
}
|
||||
|
||||
return infoSts;
|
||||
|
||||
return infoSts;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -226,68 +227,68 @@ linuxModInfo(unsigned int /* gfid */, const char *sopath, tModList **modlist)
|
|||
static int
|
||||
linuxModLoadDir(unsigned int gfid, const char *dir, tModList **modlist)
|
||||
{
|
||||
char sopath[256]; /* path of the lib[x].so */
|
||||
tSOHandle handle;
|
||||
DIR *dp;
|
||||
struct dirent *ep;
|
||||
int modnb; /* number on loaded modules */
|
||||
tModList *curMod;
|
||||
|
||||
modnb = 0;
|
||||
|
||||
/* open the current directory */
|
||||
dp = opendir(dir);
|
||||
if (dp)
|
||||
{
|
||||
/* some files in it */
|
||||
while ((ep = readdir (dp)) != 0)
|
||||
char sopath[256]; /* path of the lib[x].so */
|
||||
tSOHandle handle;
|
||||
DIR *dp;
|
||||
struct dirent *ep;
|
||||
int modnb; /* number on loaded modules */
|
||||
tModList *curMod;
|
||||
|
||||
modnb = 0;
|
||||
|
||||
/* open the current directory */
|
||||
dp = opendir(dir);
|
||||
if (dp)
|
||||
{
|
||||
if ((strlen(ep->d_name) > 4) &&
|
||||
(strcmp(".so", ep->d_name+strlen(ep->d_name)-3) == 0)) /* xxxx.so */
|
||||
{
|
||||
sprintf(sopath, "%s/%s", dir, ep->d_name);
|
||||
/* Try and avoid loading the same module twice (WARNING: Only checks sopath equality !) */
|
||||
if (!GfModIsInList(sopath, *modlist))
|
||||
/* some files in it */
|
||||
while ((ep = readdir (dp)) != 0)
|
||||
{
|
||||
/* Load the shared library */
|
||||
GfLogInfo("Loading module %s\n", sopath);
|
||||
handle = dlopen(sopath, RTLD_LAZY);
|
||||
if (handle)
|
||||
{
|
||||
/* Initialize the module */
|
||||
if (GfModInitialize(handle, sopath, gfid, &curMod) == 0)
|
||||
if ((strlen(ep->d_name) > 4) &&
|
||||
(strcmp(".so", ep->d_name+strlen(ep->d_name)-3) == 0)) /* xxxx.so */
|
||||
{
|
||||
if (curMod) /* Retained against gfid */
|
||||
{
|
||||
modnb++;
|
||||
GfModAddInList(curMod, modlist, /* priosort */ 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dlclose(handle);
|
||||
modnb = -1;
|
||||
break;
|
||||
sprintf(sopath, "%s/%s", dir, ep->d_name);
|
||||
/* Try and avoid loading the same module twice (WARNING: Only checks sopath equality !) */
|
||||
if (!GfModIsInList(sopath, *modlist))
|
||||
{
|
||||
/* Load the shared library */
|
||||
GfLogInfo("Loading module %s\n", sopath);
|
||||
handle = dlopen(sopath, RTLD_LAZY);
|
||||
if (handle)
|
||||
{
|
||||
/* Initialize the module */
|
||||
if (GfModInitialize(handle, sopath, gfid, &curMod) == 0)
|
||||
{
|
||||
if (curMod) /* Retained against gfid */
|
||||
{
|
||||
modnb++;
|
||||
GfModAddInList(curMod, modlist, /* priosort */ 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dlclose(handle);
|
||||
modnb = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GfLogError("linuxModLoadDir: ... %s\n", dlerror());
|
||||
modnb = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GfLogError("linuxModLoadDir: ... %s\n", dlerror());
|
||||
modnb = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
(void)closedir(dp);
|
||||
}
|
||||
(void)closedir(dp);
|
||||
}
|
||||
else
|
||||
{
|
||||
GfLogError("linuxModLoadDir: ... Couldn't open the directory %s\n", dir);
|
||||
modnb = -1;
|
||||
}
|
||||
|
||||
return modnb;
|
||||
else
|
||||
{
|
||||
GfLogError("linuxModLoadDir: ... Couldn't open the directory %s\n", dir);
|
||||
modnb = -1;
|
||||
}
|
||||
|
||||
return modnb;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -318,72 +319,72 @@ linuxModLoadDir(unsigned int gfid, const char *dir, tModList **modlist)
|
|||
static int
|
||||
linuxModInfoDir(unsigned int /* gfid */, const char *dir, int level, tModList **modlist)
|
||||
{
|
||||
char sopath[256]; /* path of the lib[x].so */
|
||||
tSOHandle handle;
|
||||
DIR *dp;
|
||||
struct dirent *ep;
|
||||
int modnb; /* number on loaded modules */
|
||||
tModList *curMod;
|
||||
|
||||
modnb = 0;
|
||||
|
||||
/* open the current directory */
|
||||
dp = opendir(dir);
|
||||
if (dp)
|
||||
{
|
||||
/* some files in it */
|
||||
while ((ep = readdir (dp)) != 0)
|
||||
char sopath[256]; /* path of the lib[x].so */
|
||||
tSOHandle handle;
|
||||
DIR *dp;
|
||||
struct dirent *ep;
|
||||
int modnb; /* number on loaded modules */
|
||||
tModList *curMod;
|
||||
|
||||
modnb = 0;
|
||||
|
||||
/* open the current directory */
|
||||
dp = opendir(dir);
|
||||
if (dp)
|
||||
{
|
||||
if (((strlen(ep->d_name) > 4) &&
|
||||
(strcmp(".so", ep->d_name+strlen(ep->d_name)-3) == 0)) /* xxxx.so */
|
||||
|| ((level == 1) && (ep->d_name[0] != '.')))
|
||||
{
|
||||
if (level == 1)
|
||||
sprintf(sopath, "%s/%s/%s.so", dir, ep->d_name, ep->d_name);
|
||||
else
|
||||
sprintf(sopath, "%s/%s", dir, ep->d_name);
|
||||
|
||||
/* Try and avoid loading the same module twice (WARNING: Only checks sopath equality !) */
|
||||
if (!GfModIsInList(sopath, *modlist))
|
||||
/* some files in it */
|
||||
while ((ep = readdir (dp)) != 0)
|
||||
{
|
||||
/* Load the shared library */
|
||||
GfLogTrace("Querying module %s\n", sopath);
|
||||
handle = dlopen(sopath, RTLD_LAZY);
|
||||
if (handle)
|
||||
{
|
||||
/* Initialize the module */
|
||||
if (GfModInitialize(handle, sopath, GfIdAny, &curMod) == 0)
|
||||
if (((strlen(ep->d_name) > 4) &&
|
||||
(strcmp(".so", ep->d_name+strlen(ep->d_name)-3) == 0)) /* xxxx.so */
|
||||
|| ((level == 1) && (ep->d_name[0] != '.')))
|
||||
{
|
||||
if (curMod) /* Retained against gfid */
|
||||
{
|
||||
/* Get associated info */
|
||||
modnb++;
|
||||
GfModAddInList(curMod, modlist, /* priosort */ 1);
|
||||
}
|
||||
|
||||
/* Terminate the module */
|
||||
GfModTerminate(handle, sopath);
|
||||
if (level == 1)
|
||||
sprintf(sopath, "%s/%s/%s.so", dir, ep->d_name, ep->d_name);
|
||||
else
|
||||
sprintf(sopath, "%s/%s", dir, ep->d_name);
|
||||
|
||||
/* Try and avoid loading the same module twice (WARNING: Only checks sopath equality !) */
|
||||
if (!GfModIsInList(sopath, *modlist))
|
||||
{
|
||||
/* Load the shared library */
|
||||
GfLogTrace("Querying module %s\n", sopath);
|
||||
handle = dlopen(sopath, RTLD_LAZY);
|
||||
if (handle)
|
||||
{
|
||||
/* Initialize the module */
|
||||
if (GfModInitialize(handle, sopath, GfIdAny, &curMod) == 0)
|
||||
{
|
||||
if (curMod) /* Retained against gfid */
|
||||
{
|
||||
/* Get associated info */
|
||||
modnb++;
|
||||
GfModAddInList(curMod, modlist, /* priosort */ 1);
|
||||
}
|
||||
|
||||
/* Terminate the module */
|
||||
GfModTerminate(handle, sopath);
|
||||
}
|
||||
|
||||
/* Close the shared library */
|
||||
dlclose(handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
GfLogError("linuxModInfoDir: ... %s\n", dlerror());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Close the shared library */
|
||||
dlclose(handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
GfLogError("linuxModInfoDir: ... %s\n", dlerror());
|
||||
}
|
||||
}
|
||||
}
|
||||
(void)closedir(dp);
|
||||
}
|
||||
else
|
||||
{
|
||||
GfLogError("linuxModInfoDir: ... Couldn't open the directory %s.\n", dir);
|
||||
return -1;
|
||||
}
|
||||
(void)closedir(dp);
|
||||
}
|
||||
else
|
||||
{
|
||||
GfLogError("linuxModInfoDir: ... Couldn't open the directory %s.\n", dir);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return modnb;
|
||||
|
||||
return modnb;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -406,40 +407,40 @@ linuxModInfoDir(unsigned int /* gfid */, const char *dir, int level, tModList **
|
|||
static int
|
||||
linuxModUnloadList(tModList **modlist)
|
||||
{
|
||||
tModList *curMod;
|
||||
tModList *nextMod;
|
||||
int termSts;
|
||||
int unloadSts = 0;
|
||||
|
||||
curMod = *modlist;
|
||||
if (curMod == 0)
|
||||
return 0;
|
||||
|
||||
do
|
||||
{
|
||||
nextMod = curMod->next;
|
||||
|
||||
/* Terminate the module */
|
||||
termSts = GfModTerminate(curMod->handle, curMod->sopath);
|
||||
if (termSts)
|
||||
unloadSts = termSts;
|
||||
|
||||
// Comment out for valgrind runs, be aware that the driving with the keyboard does
|
||||
// just work to first time this way.
|
||||
dlclose(curMod->handle);
|
||||
GfLogInfo("Unloaded module %s\n", curMod->sopath);
|
||||
|
||||
GfModInfoFreeNC(curMod->modInfo, curMod->modInfoSize);
|
||||
free(curMod->sopath);
|
||||
free(curMod);
|
||||
|
||||
curMod = nextMod;
|
||||
}
|
||||
while (curMod != *modlist);
|
||||
|
||||
*modlist = (tModList *)NULL;
|
||||
|
||||
return unloadSts;
|
||||
tModList *curMod;
|
||||
tModList *nextMod;
|
||||
int termSts;
|
||||
int unloadSts = 0;
|
||||
|
||||
curMod = *modlist;
|
||||
if (curMod == 0)
|
||||
return 0;
|
||||
|
||||
do
|
||||
{
|
||||
nextMod = curMod->next;
|
||||
|
||||
/* Terminate the module */
|
||||
termSts = GfModTerminate(curMod->handle, curMod->sopath);
|
||||
if (termSts)
|
||||
unloadSts = termSts;
|
||||
|
||||
// Comment out for valgrind runs, be aware that the driving with the keyboard does
|
||||
// just work to first time this way.
|
||||
dlclose(curMod->handle);
|
||||
GfLogInfo("Unloaded module %s\n", curMod->sopath);
|
||||
|
||||
GfModInfoFreeNC(curMod->modInfo, curMod->modInfoSize);
|
||||
free(curMod->sopath);
|
||||
free(curMod);
|
||||
|
||||
curMod = nextMod;
|
||||
}
|
||||
while (curMod != *modlist);
|
||||
|
||||
*modlist = (tModList *)NULL;
|
||||
|
||||
return unloadSts;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -462,7 +463,7 @@ linuxDirGetList(const char *dir)
|
|||
struct dirent *ep;
|
||||
tFList *flist = (tFList*)NULL;
|
||||
tFList *curf;
|
||||
|
||||
|
||||
/* open the current directory */
|
||||
dp = opendir(dir);
|
||||
if (dp != NULL) {
|
||||
|
@ -497,7 +498,7 @@ linuxDirGetList(const char *dir)
|
|||
}
|
||||
closedir(dp);
|
||||
}
|
||||
return flist;
|
||||
return flist;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -520,15 +521,15 @@ linuxDirGetListFiltered(const char *dir, const char *prefix, const char *suffix)
|
|||
struct dirent *ep;
|
||||
tFList *flist = (tFList*)NULL;
|
||||
tFList *curf;
|
||||
int prefixLg, suffixLg;
|
||||
int prefixLg, suffixLg;
|
||||
int fnameLg;
|
||||
|
||||
if ((!prefix || strlen(prefix) == 0) && (!suffix || strlen(suffix) == 0))
|
||||
|
||||
if ((!prefix || strlen(prefix) == 0) && (!suffix || strlen(suffix) == 0))
|
||||
return linuxDirGetList(dir);
|
||||
|
||||
suffixLg = suffix ? strlen(suffix) : 0;
|
||||
prefixLg = prefix ? strlen(prefix) : 0;
|
||||
|
||||
|
||||
suffixLg = suffix ? strlen(suffix) : 0;
|
||||
prefixLg = prefix ? strlen(prefix) : 0;
|
||||
|
||||
/* open the current directory */
|
||||
dp = opendir(dir);
|
||||
if (dp != NULL) {
|
||||
|
@ -565,7 +566,7 @@ linuxDirGetListFiltered(const char *dir, const char *prefix, const char *suffix)
|
|||
curf->next->prev = curf;
|
||||
flist = curf;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
|
@ -592,14 +593,14 @@ static double InitTime = -1.0;
|
|||
static double
|
||||
linuxTimeClock(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, 0);
|
||||
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, 0);
|
||||
|
||||
if (InitTime < 0)
|
||||
InitTime = (double)(tv.tv_sec + tv.tv_usec * 1e-6);
|
||||
|
||||
return (double)(tv.tv_sec + tv.tv_usec * 1e-6) - InitTime;
|
||||
return (double)(tv.tv_sec + tv.tv_usec * 1e-6) - InitTime;
|
||||
}
|
||||
|
||||
|
||||
|
@ -625,43 +626,43 @@ linuxTimeClock(void)
|
|||
unsigned linuxGetNumberOfCPUs()
|
||||
{
|
||||
static unsigned nCPUs = 0;
|
||||
|
||||
|
||||
if (nCPUs == 0)
|
||||
{
|
||||
|
||||
// MacOS X, FreeBSD, OpenBSD, NetBSD, etc ...
|
||||
|
||||
// MacOS X, FreeBSD, OpenBSD, NetBSD, etc ...
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
|
||||
|
||||
|
||||
nt mib[4];
|
||||
size_t len;
|
||||
|
||||
|
||||
// Set the mib for hw.ncpu
|
||||
|
||||
|
||||
// Get the number of CPUs from the system
|
||||
// 1) Try HW_AVAILCPU first.
|
||||
mib[0] = CTL_HW;
|
||||
mib[1] = HW_AVAILCPU; // alternatively, try HW_NCPU;
|
||||
sysctl(mib, 2, &nCPUs, &len, NULL, 0);
|
||||
|
||||
|
||||
if (nCPUs < 1)
|
||||
{
|
||||
// 2) Try alternatively HW_NCPU.
|
||||
mib[1] = HW_NCPU;
|
||||
sysctl(mib, 2, &nCPUs, &len, NULL, 0);
|
||||
}
|
||||
|
||||
// Linux, Solaris, AIX
|
||||
|
||||
// Linux, Solaris, AIX
|
||||
#elif defined(linux) || defined(__linux__)
|
||||
|
||||
|
||||
nCPUs = (unsigned)sysconf(_SC_NPROCESSORS_ONLN);
|
||||
|
||||
// Anything else ... not supported.
|
||||
|
||||
// Anything else ... not supported.
|
||||
#else
|
||||
|
||||
|
||||
#warning "Unsupported Linux OS"
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
if (nCPUs < 1)
|
||||
{
|
||||
GfLogWarning("Could not get the number of CPUs here ; assuming only 1\n");
|
||||
|
@ -670,7 +671,7 @@ unsigned linuxGetNumberOfCPUs()
|
|||
else
|
||||
GfLogInfo("Detected %d CPUs\n", nCPUs);
|
||||
}
|
||||
|
||||
|
||||
return nCPUs;
|
||||
}
|
||||
|
||||
|
@ -707,18 +708,18 @@ std::string cpuSet2String(const cpu_set_t* pCPUSet)
|
|||
bool
|
||||
linuxSetThreadAffinity(int nCPUId)
|
||||
{
|
||||
// MacOS X, FreeBSD, OpenBSD, NetBSD, etc ...
|
||||
// MacOS X, FreeBSD, OpenBSD, NetBSD, etc ...
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
|
||||
|
||||
GfLogWarning("Thread affinity not yet implemented on Mac OS X or BSD.\n");
|
||||
|
||||
GfLogWarning("Thread affinity not yet implemented on Mac OS X or BSD.\n");
|
||||
// TODO.
|
||||
|
||||
// Linux, Solaris, AIX ... with NPTL (Native POSIX Threads Library)
|
||||
|
||||
// Linux, Solaris, AIX ... with NPTL (Native POSIX Threads Library)
|
||||
#elif defined(linux) || defined(__linux__)
|
||||
|
||||
|
||||
// Get the handle for the current thread.
|
||||
pthread_t hCurrThread = pthread_self();
|
||||
|
||||
pthread_t hCurrThread = pthread_self();
|
||||
|
||||
// Determine the affinity mask to set for the current thread.
|
||||
cpu_set_t nThreadAffinityMask;
|
||||
CPU_ZERO(&nThreadAffinityMask);
|
||||
|
@ -737,30 +738,77 @@ linuxSetThreadAffinity(int nCPUId)
|
|||
CPU_SET(nCPUId, &nThreadAffinityMask);
|
||||
}
|
||||
|
||||
// Set the affinity mask for the current thread ("stick" it to the target core).
|
||||
// Set the affinity mask for the current thread ("stick" it to the target core).
|
||||
if (pthread_setaffinity_np(hCurrThread, sizeof(nThreadAffinityMask), &nThreadAffinityMask))
|
||||
{
|
||||
GfLogError("Failed to set current pthread (handle=0x%X) affinity on CPU(s) %s (%s)\n",
|
||||
{
|
||||
GfLogError("Failed to set current pthread (handle=0x%X) affinity on CPU(s) %s (%s)\n",
|
||||
hCurrThread, cpuSet2String(&nThreadAffinityMask).c_str(), strerror(errno));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
GfLogInfo("Affinity set on CPU(s) %s for current pthread (handle=0x%X)\n",
|
||||
return false;
|
||||
}
|
||||
else
|
||||
GfLogInfo("Affinity set on CPU(s) %s for current pthread (handle=0x%X)\n",
|
||||
cpuSet2String(&nThreadAffinityMask).c_str(), hCurrThread);
|
||||
|
||||
return true;
|
||||
|
||||
// Anything else ... not supported.
|
||||
|
||||
return true;
|
||||
|
||||
// Anything else ... not supported.
|
||||
#else
|
||||
|
||||
|
||||
#warning "linuxspec.cpp::linuxSetThreadAffinity : Unsupported Linux OS"
|
||||
GfLogWarning("Thread affinity not yet implemented on this unknown Unix.\n");
|
||||
|
||||
GfLogWarning("Thread affinity not yet implemented on this unknown Unix.\n");
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function
|
||||
* linuxGetOSInfo
|
||||
*
|
||||
* Description
|
||||
* Get some info about the running OS (name, x.y.z release, and nb of bits).
|
||||
*
|
||||
* Parameters
|
||||
* strName : target string for the OS name ("" if any error occurred)
|
||||
* nMajor : target OS major version integer (-1 if could not be obtained)
|
||||
* nMinor : target OS minor version integer (-1 if could not be obtained)
|
||||
* nPatch : target OS patch version integer (-1 if could not be obtained)
|
||||
* nBits : target OS number of bits (32 or 64) integer (or -1 if could not be obtained)
|
||||
*
|
||||
* Return
|
||||
* True if OK, False otherwise.
|
||||
*/
|
||||
static bool
|
||||
linuxGetOSInfo(std::string& strName, int& nMajor, int& nMinor, int& nPatch, int& nBits)
|
||||
{
|
||||
struct utsname utsName;
|
||||
if(uname(&utsName) < 0)
|
||||
{
|
||||
const int errnum = errno; // Get errno before it is overwritten by some system call.
|
||||
GfLogWarning("Could not get OS info through uname (%s).\n", strerror(errnum));
|
||||
return false;
|
||||
}
|
||||
|
||||
//GfLogDebug("linuxGetOSInfo : name='%s', version='%s', release='%s'\n",
|
||||
// utsName.sysname, utsName.version, utsName.release);
|
||||
strName = utsName.sysname;
|
||||
strName += " ";
|
||||
strName += utsName.release;
|
||||
strName += " ";
|
||||
strName += utsName.version;
|
||||
const int nNums = sscanf(utsName.release, "%d.%d.%d", &nMajor, &nMinor, &nPatch);
|
||||
if (nNums < 1)
|
||||
nMajor = -1;
|
||||
if (nNums < 2)
|
||||
nMinor = -1;
|
||||
if (nNums < 3)
|
||||
nPatch = -1;
|
||||
nBits = strstr(utsName.release, "64") ? 64 : 32;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function
|
||||
* LinuxSpecInit
|
||||
|
@ -780,17 +828,17 @@ linuxSetThreadAffinity(int nCPUId)
|
|||
void
|
||||
LinuxSpecInit(void)
|
||||
{
|
||||
memset(&GfOs, 0, sizeof(GfOs));
|
||||
|
||||
GfOs.modLoad = linuxModLoad;
|
||||
GfOs.modLoadDir = linuxModLoadDir;
|
||||
GfOs.modUnloadList = linuxModUnloadList;
|
||||
GfOs.modInfo = linuxModInfo;
|
||||
GfOs.modInfoDir = linuxModInfoDir;
|
||||
GfOs.dirGetList = linuxDirGetList;
|
||||
GfOs.dirGetListFiltered = linuxDirGetListFiltered;
|
||||
GfOs.timeClock = linuxTimeClock;
|
||||
GfOs.sysGetNumberOfCPUs = linuxGetNumberOfCPUs;
|
||||
GfOs.sysSetThreadAffinity = linuxSetThreadAffinity;
|
||||
memset(&GfOs, 0, sizeof(GfOs));
|
||||
|
||||
GfOs.modLoad = linuxModLoad;
|
||||
GfOs.modLoadDir = linuxModLoadDir;
|
||||
GfOs.modUnloadList = linuxModUnloadList;
|
||||
GfOs.modInfo = linuxModInfo;
|
||||
GfOs.modInfoDir = linuxModInfoDir;
|
||||
GfOs.dirGetList = linuxDirGetList;
|
||||
GfOs.dirGetListFiltered = linuxDirGetListFiltered;
|
||||
GfOs.timeClock = linuxTimeClock;
|
||||
GfOs.sysGetNumberOfCPUs = linuxGetNumberOfCPUs;
|
||||
GfOs.sysSetThreadAffinity = linuxSetThreadAffinity;
|
||||
GfOs.sysGetOSInfo = linuxGetOSInfo;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ unsigned GfGetNumberOfCPUs()
|
|||
|
||||
/* Force the current thread to run on the specified CPU.
|
||||
* @param nCPUId the index in [0, # of actual CPUs on the system [ (any other value will actually reset the thread affinity to the "system" affinity mask, meaning no special processor / core assignement)
|
||||
* @return true if any error occured, false otherwise
|
||||
* @return false if any error occurred, false otherwise
|
||||
*/
|
||||
bool GfSetThreadAffinity(int nCPUId)
|
||||
{
|
||||
|
@ -89,3 +89,19 @@ bool GfSetThreadAffinity(int nCPUId)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get some info about the running OS.
|
||||
* @param strName target string for the OS name
|
||||
* @param nMajor target OS major version integer
|
||||
* @param nMinor target OS minor version integer
|
||||
* @param nBits target OS number of bits (32 or 64) integer
|
||||
* @return false if any error occurred, false otherwise
|
||||
*/
|
||||
bool GfGetOSInfo(std::string& strName, int& nMajor, int& nMinor, int& nPatch, int& nBits)
|
||||
{
|
||||
if (GfOs.sysGetOSInfo) {
|
||||
return GfOs.sysGetOSInfo(strName, nMajor, nMinor, nPatch, nBits);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ typedef double (*tfTimeClock)(void);
|
|||
/* System interface */
|
||||
typedef unsigned (*tfSysGetNumberOfCPUs)(void);
|
||||
typedef bool (*tfSysSetThreadAffinity)(int nCPUId);
|
||||
typedef bool (*tfSysGetOSInfo)(std::string&, int&, int&, int&, int&);
|
||||
|
||||
typedef struct {
|
||||
tfModLoad modLoad;
|
||||
|
@ -53,6 +54,7 @@ typedef struct {
|
|||
tfTimeClock timeClock;
|
||||
tfSysSetThreadAffinity sysSetThreadAffinity;
|
||||
tfSysGetNumberOfCPUs sysGetNumberOfCPUs;
|
||||
tfSysGetOSInfo sysGetOSInfo;
|
||||
} tGfOs;
|
||||
|
||||
TGF_API extern tGfOs GfOs;
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
|
||||
#include "modinfo.h" // Don't move this include line : needs TGF_API definition.
|
||||
|
||||
#include <string>
|
||||
|
||||
/** Floating point type used everywhere.
|
||||
@ingroup definitions
|
||||
|
@ -508,6 +509,7 @@ TGF_API bool GfSetThreadAffinity(int nCPUId);
|
|||
|
||||
TGF_API void GfSleep(double seconds);
|
||||
|
||||
TGF_API bool GfGetOSInfo(std::string& strName, int& nMajor, int& nMinor, int& nPatch, int& nBits);
|
||||
|
||||
/***************************
|
||||
* Run-time dirs accessors *
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue