[Lldb-commits] [PATCH] D29288: Switch std::call_once to llvm::call_once

Kamil Rytarowski via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sat Feb 4 19:38:08 PST 2017


krytarowski added a comment.

I've tried to build the LLDB code with mechanically * replaced `std::call_once` -> `llvm::call_once` and `std::once_flag` -> `llvm::once_flag`:

  --- /public/llvm/include/llvm/Support/Threading.h	2017-02-05 00:15:00.769574623 +0100
  +++ /usr/pkg/include/llvm/Support/Threading.h	2017-02-05 04:14:03.334251557 +0100
  @@ -62,12 +62,16 @@
   
     /// This macro is the only way you should define your once flag for LLVM's
     /// call_once.
  -#define LLVM_DEFINE_ONCE_FLAG(flag) static ::llvm::once_flag flag
  +#define LLVM_DEFINE_ONCE_FLAG(flag) static once_flag flag
   
   #else
   
     enum InitStatus { Uninitialized = 0, Wait = 1, Done = 2 };
  -  typedef volatile sys::cas_flag once_flag;
  +  class once_flag {
  +  public:
  +    once_flag() : status(::llvm::Uninitialized) {};
  +    volatile ::llvm::sys::cas_flag status;
  +  };
   
     /// This macro is the only way you should define your once flag for LLVM's
     /// call_once.
  @@ -96,24 +100,24 @@
   #else
       // For other platforms we use a generic (if brittle) version based on our
       // atomics.
  -    sys::cas_flag old_val = sys::CompareAndSwap(&flag, Wait, Uninitialized);
  +    sys::cas_flag old_val = sys::CompareAndSwap(&flag.status, Wait, Uninitialized);
       if (old_val == Uninitialized) {
         std::forward<Function>(F)(std::forward<Args>(ArgList)...);
         sys::MemoryFence();
         TsanIgnoreWritesBegin();
  -      TsanHappensBefore(&flag);
  -      flag = Done;
  +      TsanHappensBefore(&flag.status);
  +      flag.status = Done;
         TsanIgnoreWritesEnd();
       } else {
         // Wait until any thread doing the call has finished.
  -      sys::cas_flag tmp = flag;
  +      sys::cas_flag tmp = flag.status;
         sys::MemoryFence();
         while (tmp != Done) {
  -        tmp = flag;
  +        tmp = flag.status;
           sys::MemoryFence();
         }
       }
  -    TsanHappensAfter(&flag);
  +    TsanHappensAfter(&flag.status);
   #endif
     }
   



- there is one exception, I don't understand:

  const DWARFDataExtractor &
  SymbolFileDWARF::GetCachedSectionData(lldb::SectionType sect_type,
                                        DWARFDataSegment &data_segment) {
  #if 0
    llvm::call_once(data_segment.m_flag, &SymbolFileDWARF::LoadSectionData, this,
                   sect_type, std::ref(data_segment.m_data));
  #else
    llvm::call_once(data_segment.m_flag,
      [this, sect_type, &data_segment] {
        this->LoadSectionData(sect_type, std::ref(data_segment.m_data));
      }
    );
  #endif
    return data_segment.m_data;
  }

This exception is valid for so far all versions of switches out of `std::once_flag`.


Repository:
  rL LLVM

https://reviews.llvm.org/D29288





More information about the lldb-commits mailing list