[libcxx-commits] [PATCH] D110093: [NFC][libcxxabi] In cxa_guard, split the InitByte classes into InitByte... and ...Guard

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 7 16:21:33 PST 2021


ldionne added inline comments.


================
Comment at: libcxxabi/src/cxa_guard_impl.h:174
 template <class Derived>
 struct GuardObject {
   GuardObject() = delete;
----------------
I was looking at this patch and I found that using CRTP for this was adding a lot of complexity. It it possible that using a free function (template) for implementing `cxa_guard_acquire`, `cxa_guard_release` and `cxa_guard_abort` would greatly simplify things? Imagine:

```
template <class Guard>
AcquireResult cxa_guard_acquire(Guard& guard) {
  AtomicInt<uint8_t> guard_byte(guard.get_init_byte()); // all types of guards need to answer to that
  if (guard_byte.load(std::_AO_Acquire) != UNSET)
    return INIT_IS_DONE;
  return derived()->acquire_init_byte();
}

// etc..
```

Then, for example `NoThreadsGuard` would become:

```
using NoThreadsGuard = InitByteNoThreads;
```

At that point we might want to simplify the whole thing and simply call `InitByteNoThreads` `NoThreadsGuard` directly.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110093/new/

https://reviews.llvm.org/D110093



More information about the libcxx-commits mailing list