| 1589 | std::atomic<bool> HostDBFileUpdateActive{false}; |
| 1590 | |
| 1591 | void |
| 1592 | UpdateHostsFile(swoc::file::path const &path, ts_seconds interval) |
| 1593 | { |
| 1594 | // Test and set for update in progress. |
| 1595 | bool flag = false; |
| 1596 | if (!HostDBFileUpdateActive.compare_exchange_strong(flag, true)) { |
| 1597 | Dbg(dbg_ctl_hostdb, "Skipped load of host file because update already in progress"); |
| 1598 | return; |
| 1599 | } |
| 1600 | |
| 1601 | std::shared_ptr<HostFile> hf = ParseHostFile(path, interval); |
| 1602 | |
| 1603 | // Swap the pointer |
| 1604 | if (hf) { |
| 1605 | std::unique_lock lock(hostDB.host_file_mutex); |
| 1606 | hostDB.host_file = std::move(hf); |
| 1607 | } |
| 1608 | hostdb_hostfile_update_timestamp = hostdb_current_timestamp; |
| 1609 | // Mark this one as completed, so we can allow another update to happen |
| 1610 | HostDBFileUpdateActive = false; |
| 1611 | } |
| 1612 | |
| 1613 | // |
| 1614 | // Regression tests |
no test coverage detected