This is an archive of the discontinued LLVM Phabricator instance.

libc++abi: pave the road for Windows threading model
AbandonedPublic

Authored by compnerd on Mar 25 2016, 1:42 PM.

Details

Summary

Create an abstraction layer for the threading model. The signatures closely
resemble pthreads for now, since it makes it more obvious to see that this is
purely an indirection layer. In the future, it may turn out to change the
signature, but should be possible to create Win32 equivalents using the same
signatures.

The change to the test is benign as it assumed the pthread threading model;
defining _POSIX_THREADS simply specifies it rather than just including
pthread.h.

Diff Detail

Event Timeline

compnerd updated this revision to Diff 51682.Mar 25 2016, 1:42 PM
compnerd retitled this revision from to libc++abi: pave the road for Windows threading model.
compnerd updated this object.
compnerd added reviewers: mclow.lists, EricWF.
compnerd added a subscriber: jroelofs.
jroelofs added inline comments.Mar 25 2016, 2:52 PM
src/__cxa_thread.h
28

I think it'd be better to keep these out of the __cxa_* namespace, as they're implementation details of libc++abi, and not part of its official public interface (as defined here: https://mentorembedded.github.io/cxx-abi/abi.html).

Something like __libcxxabi_* perhaps?

That should reduce hassles if anyone wants to standardize one of these names later on.

compnerd marked an inline comment as done.Mar 26 2016, 9:56 AM
compnerd added inline comments.
src/__cxa_thread.h
28

That is a brilliant idea. Ill update the patch with an alternate prefix (__cxxabi_).

compnerd updated this revision to Diff 51717.Mar 26 2016, 9:57 AM
compnerd marked an inline comment as done.

Address naming suggestion from @jroelofs.

EricWF edited edge metadata.Apr 15 2016, 9:16 PM

Overall the patch seems like progress. However I know nothing about the Windows threading API's. Do you have experience with them? Are they even remotely similar to the POSIX ones? If not what to we gain by using POSIX API's under a different name?

include/__cxxabi_config.h
44

_value_ should be a reserved name.

44

__cxxabi_config.h is an installed header, but these macros are only used by the source files. They should probably live elsewhere.

src/__cxa_thread.h
32

This seems incorrect. Things like PTHREAD_ONCE_INIT are macros defined to be certain expressions. They don't think that's replacable using a named variable. For example on OS X the definition of 'PTHREAD_ONCE_INIT' is:

#define PTHREAD_ONCE_INIT {_PTHREAD_ONCE_SIG_init, {0}}

For that reason these new initializers will likely also have to be macros.

The names are just that: names. I just used similar names to make the change more obvious. There are equivalent operations for each one of these even though they may not be written the same. If you have opinions on the naming, Im not hard set on the naming scheme.

include/__cxxabi_config.h
44

Recommendations for where? I don't have a problem with moving them.

src/__cxa_thread.h
32

Okay, I can change them to macros.

EricWF added inline comments.Apr 16 2016, 6:44 PM
src/__cxa_thread.h
32

Nevermind, I'm wrong about this. So long as we always have constexpr this should work OK.

rmaprath added inline comments.Aug 19 2016, 5:11 AM
CMakeLists.txt
277–278

Perhaps do something similar to what is done in libcxx at the moment? There we provide an explicit cmake option to select pthreads in case the default selection mechanism (in include/__config) cannot figure out the thread implementation based on the platform.

src/__cxa_thread.h
23

May be update to follow the convention used in libcxx? I.e. something like _LIBCXXABI_HAS_THREAD_API_PTHREAD.

38

Perhaps define a macro for this? Similar to _LIBCPP_ALWAYS_INLINE in libcxx.

compnerd added inline comments.Aug 19 2016, 7:33 AM
src/__cxa_thread.h
23

_POSIX_THREADS is a better solution IMO. Its defined by the specification itself. Furthermore, on platforms where POSIX threads are available, it allows you to select between them and an alternate threading mechanism. Consider Solaris, you can use pthreads or Solaris threads.

Btw, this review isn't posted on cfe-commits, you might need a new review to fix this. IIRC, adding cfe-commits later on does not work. Perhaps one of the reason @mclow.lists missed it!

@compnerd: Pinged you on IRC a couple of times, not sure if you got them. Can I steal this patch and implement my own changes on top of it? Basically, turn this into the mirror image of what we did with libcxx.

@mclow.lists has approved the libc++ patch (and it has landed), so I think we can ask @EricWF to review the rest of the patches (libunwind and libc++abi).

WDYT?

Yeah, go ahead and commandeer the patch. I wouldn't be able to work on this outside of my spare time :)

I can review the unwind changes :)

compnerd abandoned this revision.Jan 2 2017, 8:36 PM

This is no longer needed with the external threading.