// The GlobalCounter provides a synchronization mechanism between threads for // safe memory reclamation and other ABA problems. All readers must call // critical_section_begin before reading the volatile data and // critical_section_end afterwards. Such read-side critical sections may // be properly nested. The write side must call write_synchronize // before reclaming the memory. The read-path only does an uncontended store // to a thread-local-storage and fence to stop any loads from floating up, thus // light weight and wait-free. The write-side is more heavy since it must check // all readers and wait until they have left the generation. (a system memory // barrier can be used on write-side to remove fence in read-side, // not implemented). class GlobalCounter : public AllStatic { private: // Since do not know what we will end up next to in BSS, we make sure the // counter is on a separate cacheline. struct PaddedCounter {
DEFINE_PAD_MINUS_SIZE(0, DEFAULT_CACHE_LINE_SIZE, 0); volatile uintx _counter;
DEFINE_PAD_MINUS_SIZE(1, DEFAULT_CACHE_LINE_SIZE, sizeof(volatile uintx));
};
// The global counter static PaddedCounter _global_counter;
// Bit 0 is active bit. staticconst uintx COUNTER_ACTIVE = 1; // Thus we increase counter by 2. staticconst uintx COUNTER_INCREMENT = 2;
// The per thread scanning closure. class CounterThreadCheck;
public:
// The type of the critical section context passed from // critical_section_begin() to critical_section_end().
enum class CSContext : uintx {};
// Must be called before accessing the data. The result must be passed // to the associated call to critical_section_end(). Acts as a full // memory barrier before the code within the critical section. static CSContext critical_section_begin(Thread *thread);
// Must be called after finished accessing the data. The context // must be the result of the associated initiating critical_section_begin(). // Acts as a release memory barrier after the code within the critical // section. staticvoid critical_section_end(Thread *thread, CSContext context);
// Make the data inaccessible to readers before calling. When this call // returns it's safe to reclaim the data. Acts as a full memory barrier. staticvoid write_synchronize();
// A scoped object for a read-side critical-section. class CriticalSection;
};
#endif// SHARE_UTILITIES_GLOBALCOUNTER_HPP
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-09-04)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.