@@ -1484,12 +1484,12 @@ class Notifications {
1484
1484
// / @brief Maps a trace type to its associated callback entries.
1485
1485
// / @details This unordered map uses a uint16_t as the key to represent the
1486
1486
// / trace point type, and cb_entries_t to store the associated callbacks.
1487
- using cb_t = emhash7::HashMap <uint16_t , cb_entries_t >;
1487
+ using cb_t = phmap::flat_hash_map <uint16_t , cb_entries_t >;
1488
1488
1489
1489
// / @typedef stream_cb_t
1490
1490
// / @brief Maps a stream ID to its corresponding callbacks for different
1491
1491
// / trace types
1492
- // / @details This unordered map uses the xpti::strem_id_t as the key for the
1492
+ // / @details This unordered map uses the xpti::stream_id_t as the key for the
1493
1493
// / stream ID, and cb_t to map the stream to registered callbacks for each
1494
1494
// / trace type
1495
1495
using stream_cb_t = emhash7::HashMap<xpti::stream_id_t , cb_t >;
@@ -1507,7 +1507,7 @@ class Notifications {
1507
1507
// / @details This unordered map uses a uint16_t as the key for the trace
1508
1508
// / type, and a boolean value to indicate whether callbacks are registered
1509
1509
// / for this trace type (e.g., registered or unregisterted/no callback).
1510
- using trace_flags_t = emhash7::HashMap <uint16_t , bool >;
1510
+ using trace_flags_t = phmap::flat_hash_map <uint16_t , bool >;
1511
1511
1512
1512
// / @typedef stream_flags_t
1513
1513
// / @brief Maps a stream ID to its corresponding trace flags for different
@@ -1518,6 +1518,9 @@ class Notifications {
1518
1518
// / the given stream.
1519
1519
using stream_flags_t = emhash7::HashMap<xpti::stream_id_t , trace_flags_t >;
1520
1520
1521
+ Notifications (size_t size = 512 )
1522
+ : MCallbacksByStream(size), MStreamFlags(size) {}
1523
+
1521
1524
// / @brief Registers a callback function for a specific trace type and stream
1522
1525
// / ID.
1523
1526
// /
@@ -1562,12 +1565,15 @@ class Notifications {
1562
1565
}
1563
1566
}
1564
1567
#endif
1568
+ {
1569
+ std::unique_lock<std::shared_mutex> Lock (MFlagsLock);
1570
+ // Get the flags for the stream
1571
+ auto &TraceFlags = MStreamFlags[StreamID];
1572
+ TraceFlags[TraceType] = true ; // Set the trace type flag to true
1573
+ }
1565
1574
// If reader-writer locks were emplyed, this is where the writer lock can
1566
1575
// be used
1567
1576
std::unique_lock<std::shared_mutex> Lock (MCBsLock);
1568
- auto &TraceFlags = MStreamFlags[StreamID]; // Get the trace flags for the
1569
- // stream ID
1570
- TraceFlags[TraceType] = true ; // Set the trace type flag to true
1571
1577
1572
1578
auto &StreamCBs =
1573
1579
MCallbacksByStream[StreamID]; // thread-safe
@@ -1637,14 +1643,16 @@ class Notifications {
1637
1643
if (!cbFunc)
1638
1644
return xpti::result_t ::XPTI_RESULT_INVALIDARG;
1639
1645
1646
+ {
1647
+ std::unique_lock<std::shared_mutex> Lock (MFlagsLock);
1648
+ auto &TraceFlags = MStreamFlags[StreamID]; // Get the trace flags for the
1649
+ // stream ID
1650
+ TraceFlags[TraceType] = false ; // Set the trace type flag to false
1651
+ }
1640
1652
// Since we do not remove the callback function when they are unregistered
1641
1653
// and only reset the flag, the writer lock is not held for very long; use
1642
1654
// writer lock here.
1643
1655
std::unique_lock<std::shared_mutex> Lock (MCBsLock);
1644
- auto &TraceFlags = MStreamFlags[StreamID]; // Get the trace flags for the
1645
- // stream ID
1646
- TraceFlags[TraceType] = false ; // Set the trace type flag to false
1647
-
1648
1656
auto &StreamCBs =
1649
1657
MCallbacksByStream[StreamID]; // thread-safe
1650
1658
// What we get is a concurrent_hash_map
@@ -1691,16 +1699,18 @@ class Notifications {
1691
1699
// / use reader-writer locks, a reader lock should be used where appropriate.
1692
1700
1693
1701
xpti::result_t unregisterStream (xpti::stream_id_t StreamID) {
1702
+ {
1703
+ std::unique_lock<std::shared_mutex> Lock (MFlagsLock);
1704
+ // Get the trace flags for the stream
1705
+ MStreamFlags.erase (StreamID);
1706
+ }
1694
1707
// If there are no callbacks registered for the requested stream ID, we
1695
1708
// return not found; use reader lock here if the implementation moves to
1696
1709
// reader-writer locks.
1697
1710
std::unique_lock<std::shared_mutex> Lock (MCBsLock);
1698
1711
if (MCallbacksByStream.count (StreamID) == 0 )
1699
1712
return xpti::result_t ::XPTI_RESULT_NOTFOUND;
1700
1713
1701
- // Get the trace flags for the stream
1702
- MStreamFlags.erase (StreamID);
1703
-
1704
1714
auto &StreamCBs = MCallbacksByStream[StreamID]; // thread-safe
1705
1715
// Disable all callbacks registered for the stream represented by StreamID
1706
1716
for (auto &Item : StreamCBs) {
@@ -1732,6 +1742,7 @@ class Notifications {
1732
1742
if (StreamID == 0 )
1733
1743
return false ;
1734
1744
1745
+ std::shared_lock<std::shared_mutex> Lock (MFlagsLock);
1735
1746
// Instead of checking the MCallbacksByStream to see if there are
1736
1747
// registered callbacks for a given stream/trace type query, we check
1737
1748
// this against a shadow data structure that sets a boolean flag equals
@@ -1899,6 +1910,7 @@ class Notifications {
1899
1910
#endif
1900
1911
stream_cb_t MCallbacksByStream;
1901
1912
mutable std::shared_mutex MCBsLock;
1913
+ mutable std::shared_mutex MFlagsLock;
1902
1914
std::mutex MStatsLock;
1903
1915
statistics_t MStats;
1904
1916
stream_flags_t MStreamFlags;
0 commit comments