[PATCH] D19415: [libcxx][rfc] Externalized threading support

Asiri Rathnayake via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 26 16:48:49 PDT 2016


rmaprath updated this revision to Diff 55127.
rmaprath added a comment.

Addressing review comments from @bcraig:

Adjusted according to the changes of http://reviews.llvm.org/D19412. This patch is now mostly trivial.

There is a small catch in that, this version of the API takes pointer-to-pointer type arguments for most `__os_xxx` functions. This is partly because we need to use opaque pointer types to hide the underlying implementation details from libcxx internals. This can be worked-around by using some template hackery (along the lines of `is_pointer`), but I thought to leave it as it is to avoid cluttering up the sources for the normal use case.


http://reviews.llvm.org/D19415

Files:
  include/__os_support

Index: include/__os_support
===================================================================
--- include/__os_support
+++ include/__os_support
@@ -186,7 +186,71 @@
     pthread_setspecific(__key, __p);
 }
 
-#else // !_LIBCPP_THREAD_API_PTHREAD
+#elif defined(_LIBCPP_THREAD_API_EXTERNAL)
+
+// Mutex
+#define __OS_MUTEX_INITIALIZER 0
+struct __libcpp_mutex_external;
+typedef __libcpp_mutex_external* __libcpp_mutex;
+
+int __os_mutex_init(__libcpp_mutex* __m, bool is_recursive);
+
+int __os_mutex_lock(__libcpp_mutex* __m);
+
+int __os_mutex_trylock(__libcpp_mutex* __m);
+
+int __os_mutex_unlock(__libcpp_mutex* __m);
+
+int __os_mutex_destroy(__libcpp_mutex* __m);
+
+// Condition variable
+#define __OS_COND_INITIALIZER 0
+struct __libcpp_condvar_external;
+typedef __libcpp_condvar_external* __libcpp_condvar;
+
+int __os_condvar_signal(__libcpp_condvar* __cv);
+
+int __os_condvar_broadcast(__libcpp_condvar* __cv);
+
+int __os_condvar_wait(__libcpp_condvar* __cv, __libcpp_mutex* __m);
+
+int __os_condvar_timedwait(__libcpp_condvar* __cv, __libcpp_mutex* __m, timespec* __ts);
+
+int __os_condvar_destroy(__libcpp_condvar* __cv);
+
+// Thread id
+typedef unsigned long __libcpp_thread_id;
+
+int __os_thread_id_compare(__libcpp_thread_id t1, __libcpp_thread_id t2);
+
+// Thread
+struct __libcpp_thread_external;
+typedef __libcpp_thread_external* __libcpp_thread;
+
+template<class _Func, class _Arg>
+int __os_thread_create(__libcpp_thread* __t, _Func&& __f, _Arg&& __arg);
+
+__libcpp_thread_id __os_thread_get_current_id();
+
+__libcpp_thread_id __os_thread_get_id(const __libcpp_thread* __t);
+
+int __os_thread_join(__libcpp_thread* __t);
+
+int __os_thread_detach(__libcpp_thread* __t);
+
+void __os_thread_yield();
+
+// Thread local storage
+typedef unsigned long __libcpp_tl_key;
+
+template<class _Func>
+int __os_tl_create(__libcpp_tl_key* __key, _Func&& __at_exit);
+
+void* __os_tl_get(__libcpp_tl_key __key);
+
+void __os_tl_set(__libcpp_tl_key __key, void* __p);
+
+#else
   #error "No thread API selected."
 #endif
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19415.55127.patch
Type: text/x-patch
Size: 2047 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160426/0b6c9126/attachment.bin>


More information about the cfe-commits mailing list