Show
Ignore:
Timestamp:
09/21/07 14:15:18 (7 years ago)
Author:
khali
Message:

Scan chip features only once at initialization time, rather than on
each update. The chip list and chip features do not change until
sensors_cleanup() is called, so there's no point in doing the
same work over and over again.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/rrd.c

    r4817 r4828  
    142142  for (j = 0; (ret == 0) && (j < numChipNames); ++ j) { 
    143143    while ((ret == 0) && ((chip = sensors_get_detected_chips (&chipNames[j], &i)) != NULL)) { 
    144       ChipDescriptor *descriptor; 
    145       descriptor = generateChipDescriptor (chip); 
    146       if (descriptor) { 
     144      int index0, chipindex = -1; 
     145      for (index0 = 0; knownChips[index0].features; ++ index0) 
     146        /* Trick: we compare addresses here. We know it works because both 
     147           pointers were returned by sensors_get_detected_chips(), so they 
     148           refer to libsensors internal structures, which do not move. */ 
     149        if (knownChips[index0].name == chip) { 
     150          chipindex = index0; 
     151          break; 
     152        } 
     153      if (chipindex >= 0) { 
     154        const ChipDescriptor *descriptor = &knownChips[chipindex]; 
    147155        const FeatureDescriptor *features = descriptor->features; 
    148         int index0; 
    149156 
    150157        for (index0 = 0; (ret == 0) && (num < MAX_RRD_SENSORS) && features[index0].format; ++ index0) { 
     
    168175            free (label); 
    169176        } 
    170         free (descriptor->features); 
    171         free (descriptor); 
    172177      } 
    173178    }