Fix carrier mapping concurrency issue

This commit is contained in:
Xavier Arteaga 2021-05-28 17:05:44 +02:00 committed by Xavier Arteaga
parent 93b35676e7
commit 3c93d5ba43
3 changed files with 21 additions and 16 deletions

View File

@ -93,10 +93,10 @@ public:
void set_channels(const std::list<channel_cfg_t>& channels_) { available_channels = channels_; }
/**
* Finds an unused physical channel that supports the provided frequency and assigns it to logical channel
* logical_ch
* It deallocates the logical channel if it has been already allocated and it is not suitable, then finds an unused
* physical channel that supports the provided frequency and assigns it to logical channel logical_ch
* @param logical_ch logical channel index
* @param freq Frequency (in Hz) that we want to receive/transmitt
* @param freq Frequency (in Hz) that we want to receive/transmit
* @return true if a physical channel supporting this frequency was found or false otherwise
*/
bool allocate_freq(const uint32_t& logical_ch, const float& freq);
@ -138,6 +138,8 @@ private:
mutable std::mutex mutex = {};
uint32_t nof_antennas = 1;
uint32_t nof_channels_x_dev = 1;
void release_freq_(const uint32_t& logical_ch);
};
} // namespace srsran

View File

@ -26,11 +26,15 @@ bool channel_mapping::allocate_freq(const uint32_t& logical_ch, const float& fre
{
std::lock_guard<std::mutex> lock(mutex);
if (allocated_channels.count(logical_ch)) {
ERROR("allocate_freq: Carrier logical_ch=%d already allocated to channel=%d",
logical_ch,
allocated_channels[logical_ch].carrier_idx);
return false;
// Check if the logical channel has already been allocated
if (allocated_channels.count(logical_ch) > 0) {
// If the current channel contains the frequency, do nothing else
if (allocated_channels[logical_ch].band.contains(freq)) {
return true;
}
// Otherwise, release logical channel before searching for a new available channel
release_freq_(logical_ch);
}
// Find first available channel that supports this frequency and allocated it
@ -45,12 +49,17 @@ bool channel_mapping::allocate_freq(const uint32_t& logical_ch, const float& fre
return false;
}
void channel_mapping::release_freq_(const uint32_t& logical_ch)
{
available_channels.push_back(allocated_channels[logical_ch]);
allocated_channels.erase(logical_ch);
}
bool channel_mapping::release_freq(const uint32_t& logical_ch)
{
std::lock_guard<std::mutex> lock(mutex);
if (allocated_channels.count(logical_ch)) {
available_channels.push_back(allocated_channels[logical_ch]);
allocated_channels.erase(logical_ch);
release_freq_(logical_ch);
return true;
}
return false;

View File

@ -622,9 +622,6 @@ void radio::set_rx_freq(const uint32_t& carrier_idx, const double& freq)
return;
}
// First release mapping
rx_channel_mapping.release_freq(carrier_idx);
// Map carrier index to physical channel
if (rx_channel_mapping.allocate_freq(carrier_idx, freq)) {
channel_mapping::device_mapping_t device_mapping = rx_channel_mapping.get_device_mapping(carrier_idx);
@ -740,9 +737,6 @@ void radio::set_tx_freq(const uint32_t& carrier_idx, const double& freq)
return;
}
// First release mapping
tx_channel_mapping.release_freq(carrier_idx);
// Map carrier index to physical channel
if (tx_channel_mapping.allocate_freq(carrier_idx, freq)) {
channel_mapping::device_mapping_t device_mapping = tx_channel_mapping.get_device_mapping(carrier_idx);