smbios: more convenient interface that avoids having to check if the structures pointer is null (can still detect failure by checking whether all/guaranteed member pointers are zero)

This was SVN commit r9200.
This commit is contained in:
janwas 2011-04-07 19:35:45 +00:00
parent b5c6868ac2
commit 5b7dbe6bc9
3 changed files with 9 additions and 12 deletions

View File

@ -50,7 +50,7 @@ double os_cpu_ClockFrequency()
#endif
const SMBIOS::Structures* structures = SMBIOS::GetStructures();
if(structures && structures->Processor_)
if(structures->Processor_)
return clockFrequency = structures->Processor_->maxFrequency * 1e6;
return clockFrequency = -1.0; // unknown
@ -70,9 +70,8 @@ size_t os_cpu_MemorySize()
{
const SMBIOS::Structures* structures = SMBIOS::GetStructures();
u64 memorySizeBytes = 0;
if(structures)
for(const SMBIOS::MemoryDevice* p = structures->MemoryDevice_; p; p = p->next)
memorySizeBytes += p->size;
for(const SMBIOS::MemoryDevice* p = structures->MemoryDevice_; p; p = p->next)
memorySizeBytes += p->size;
const size_t memorySize2 = memorySizeBytes/MiB;
if(9*memorySize/10 <= memorySize2 && memorySize2 <= 11*memorySize/10)
memorySize = memorySize2;

View File

@ -663,8 +663,9 @@ const Structures* GetStructures()
{
static ModuleInitState initState;
LibError ret = ModuleInit(&initState, InitStructures);
if(ret < 0) // failed (success is either INFO::OK or INFO::SKIPPED)
return 0;
// (callers have to check if member pointers are nonzero anyway, so
// we always return a valid pointer to simplify most use cases.)
UNUSED2(ret);
return &structures;
}
@ -682,9 +683,6 @@ void StringizeStructure(const char* name, Structure* p, std::stringstream& ss)
std::string StringizeStructures(const Structures* structures)
{
if(!structures)
return "(null)";
std::stringstream ss;
#define STRUCTURE(name, id) StringizeStructure(#name, structures->name##_, ss);
STRUCTURES

View File

@ -1038,9 +1038,9 @@ struct Structures
//-----------------------------------------------------------------------------
/**
* @return 0 on failure or a pointer to a static Structures (i.e. always
* valid), with its member pointers non-zero iff the SMBIOS includes the
* corresponding structure.
* @return a pointer to a static Structures (i.e. always valid), with its
* member pointers non-zero iff SMBIOS information is available and includes
* the corresponding structure.
*
* thread-safe; return value should be cached (if possible) to avoid an
* atomic comparison.