Browse Source

AP_Param: make count_parameters() thread safe

master
Andrew Tridgell 8 years ago
parent
commit
60e4c0eb98
  1. 12
      libraries/AP_Param/AP_Param.cpp

12
libraries/AP_Param/AP_Param.cpp

@ -1984,21 +1984,25 @@ void AP_Param::send_parameter(const char *name, enum ap_var_type var_type, uint8 @@ -1984,21 +1984,25 @@ void AP_Param::send_parameter(const char *name, enum ap_var_type var_type, uint8
}
/*
return count of all scalar parameters
return count of all scalar parameters.
Note that this function may be called from the IO thread, so needs
to be thread safe
*/
uint16_t AP_Param::count_parameters(void)
{
// if we haven't cached the parameter count yet...
if (0 == _parameter_count) {
uint16_t ret = _parameter_count;
if (0 == ret) {
AP_Param *vp;
AP_Param::ParamToken token;
vp = AP_Param::first(&token, nullptr);
do {
_parameter_count++;
ret++;
} while (nullptr != (vp = AP_Param::next_scalar(&token, nullptr)));
_parameter_count = ret;
}
return _parameter_count;
return ret;
}
/*

Loading…
Cancel
Save