@@ -574,81 +574,6 @@ _PyRWMutex_Unlock(_PyRWMutex *rwmutex)
574574 }
575575}
576576
577- #define SEQLOCK_IS_UPDATING (sequence ) (sequence & 0x01)
578-
579- void _PySeqLock_LockWrite (_PySeqLock * seqlock )
580- {
581- // lock by moving to an odd sequence number
582- uint32_t prev = _Py_atomic_load_uint32_relaxed (& seqlock -> sequence );
583- while (1 ) {
584- if (SEQLOCK_IS_UPDATING (prev )) {
585- // Someone else is currently updating the cache
586- _Py_yield ();
587- prev = _Py_atomic_load_uint32_relaxed (& seqlock -> sequence );
588- }
589- else if (_Py_atomic_compare_exchange_uint32 (& seqlock -> sequence , & prev , prev + 1 )) {
590- // We've locked the cache
591- _Py_atomic_fence_release ();
592- break ;
593- }
594- else {
595- _Py_yield ();
596- }
597- }
598- }
599-
600- void _PySeqLock_AbandonWrite (_PySeqLock * seqlock )
601- {
602- uint32_t new_seq = _Py_atomic_load_uint32_relaxed (& seqlock -> sequence ) - 1 ;
603- assert (!SEQLOCK_IS_UPDATING (new_seq ));
604- _Py_atomic_store_uint32 (& seqlock -> sequence , new_seq );
605- }
606-
607- void _PySeqLock_UnlockWrite (_PySeqLock * seqlock )
608- {
609- uint32_t new_seq = _Py_atomic_load_uint32_relaxed (& seqlock -> sequence ) + 1 ;
610- assert (!SEQLOCK_IS_UPDATING (new_seq ));
611- _Py_atomic_store_uint32 (& seqlock -> sequence , new_seq );
612- }
613-
614- uint32_t _PySeqLock_BeginRead (_PySeqLock * seqlock )
615- {
616- uint32_t sequence = _Py_atomic_load_uint32_acquire (& seqlock -> sequence );
617- while (SEQLOCK_IS_UPDATING (sequence )) {
618- _Py_yield ();
619- sequence = _Py_atomic_load_uint32_acquire (& seqlock -> sequence );
620- }
621-
622- return sequence ;
623- }
624-
625- int _PySeqLock_EndRead (_PySeqLock * seqlock , uint32_t previous )
626- {
627- // gh-121368: We need an explicit acquire fence here to ensure that
628- // this load of the sequence number is not reordered before any loads
629- // within the read lock.
630- _Py_atomic_fence_acquire ();
631-
632- if (_Py_atomic_load_uint32_relaxed (& seqlock -> sequence ) == previous ) {
633- return 1 ;
634- }
635-
636- _Py_yield ();
637- return 0 ;
638- }
639-
640- int _PySeqLock_AfterFork (_PySeqLock * seqlock )
641- {
642- // Synchronize again and validate that the entry hasn't been updated
643- // while we were readying the values.
644- if (SEQLOCK_IS_UPDATING (seqlock -> sequence )) {
645- seqlock -> sequence = 0 ;
646- return 1 ;
647- }
648-
649- return 0 ;
650- }
651-
652577#undef PyMutex_Lock
653578void
654579PyMutex_Lock (PyMutex * m )
0 commit comments