Re: [libcxx] r291331 - thread: implement sleep_for on Windows

2017-01-07 Thread Asiri Rathnayake via cfe-commits
Yup, that sounds better.

I'll put up a patch soon.

Cheers,

/ Asiri

On 7 Jan 2017 9:18 p.m., "Saleem Abdulrasool"  wrote:

> I would really rather not introduce a `__libcpp_thread_nanosleep`.
> Different systems may have different granularities for their sleep.  A
> `__libcpp_sleep_for(std::chrono::duration)` sounds reasonable however.
>
> On Fri, Jan 6, 2017 at 11:53 PM, Asiri Rathnayake <
> asiri.rathnay...@gmail.com> wrote:
>
>> Wouldn't it be better to introduce a __libcpp_thread_nanosleep() API call
>> here?
>>
>> I bumped into a similar issue with a custom thread implementation and
>> have a downstream patch like that.
>>
>> Cheers,
>>
>> / Asiri
>>
>>
>> On 7 Jan 2017 2:59 a.m., "Saleem Abdulrasool via cfe-commits" <
>> cfe-commits@lists.llvm.org> wrote:
>>
>> Author: compnerd
>> Date: Fri Jan  6 20:48:30 2017
>> New Revision: 291331
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=291331&view=rev
>> Log:
>> thread: implement sleep_for on Windows
>>
>> Windows does not provide an implementation of `nanosleep`.  Round up the
>> time duration to the nearest ms and use `Sleep`.  Although this may
>> over-sleep, there is no hard real-time guarantee on the wake, so
>> sleeping a bit more is better than under-sleeping as it within the
>> specification.
>>
>> Modified:
>> libcxx/trunk/src/thread.cpp
>>
>> Modified: libcxx/trunk/src/thread.cpp
>> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/thread.
>> cpp?rev=291331&r1=291330&r2=291331&view=diff
>> 
>> ==
>> --- libcxx/trunk/src/thread.cpp (original)
>> +++ libcxx/trunk/src/thread.cpp Fri Jan  6 20:48:30 2017
>> @@ -117,6 +117,12 @@ sleep_for(const chrono::nanoseconds& ns)
>>  using namespace chrono;
>>  if (ns > nanoseconds::zero())
>>  {
>> +#if defined(_LIBCPP_WIN32API)
>> +milliseconds ms = duration_cast(ns);
>> +if (ns > duration_cast(ms))
>> +  ++ms;
>> +Sleep(ms.count());
>> +#else
>>  seconds s = duration_cast(ns);
>>  timespec ts;
>>  typedef decltype(ts.tv_sec) ts_sec;
>> @@ -134,6 +140,7 @@ sleep_for(const chrono::nanoseconds& ns)
>>
>>  while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
>>  ;
>> +#endif
>>  }
>>  }
>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>>
>>
>
>
> --
> Saleem Abdulrasool
> compnerd (at) compnerd (dot) org
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxx] r291331 - thread: implement sleep_for on Windows

2017-01-07 Thread Saleem Abdulrasool via cfe-commits
I would really rather not introduce a `__libcpp_thread_nanosleep`.
Different systems may have different granularities for their sleep.  A
`__libcpp_sleep_for(std::chrono::duration)` sounds reasonable however.

On Fri, Jan 6, 2017 at 11:53 PM, Asiri Rathnayake <
asiri.rathnay...@gmail.com> wrote:

> Wouldn't it be better to introduce a __libcpp_thread_nanosleep() API call
> here?
>
> I bumped into a similar issue with a custom thread implementation and have
> a downstream patch like that.
>
> Cheers,
>
> / Asiri
>
>
> On 7 Jan 2017 2:59 a.m., "Saleem Abdulrasool via cfe-commits" <
> cfe-commits@lists.llvm.org> wrote:
>
> Author: compnerd
> Date: Fri Jan  6 20:48:30 2017
> New Revision: 291331
>
> URL: http://llvm.org/viewvc/llvm-project?rev=291331&view=rev
> Log:
> thread: implement sleep_for on Windows
>
> Windows does not provide an implementation of `nanosleep`.  Round up the
> time duration to the nearest ms and use `Sleep`.  Although this may
> over-sleep, there is no hard real-time guarantee on the wake, so
> sleeping a bit more is better than under-sleeping as it within the
> specification.
>
> Modified:
> libcxx/trunk/src/thread.cpp
>
> Modified: libcxx/trunk/src/thread.cpp
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/thread.
> cpp?rev=291331&r1=291330&r2=291331&view=diff
> 
> ==
> --- libcxx/trunk/src/thread.cpp (original)
> +++ libcxx/trunk/src/thread.cpp Fri Jan  6 20:48:30 2017
> @@ -117,6 +117,12 @@ sleep_for(const chrono::nanoseconds& ns)
>  using namespace chrono;
>  if (ns > nanoseconds::zero())
>  {
> +#if defined(_LIBCPP_WIN32API)
> +milliseconds ms = duration_cast(ns);
> +if (ns > duration_cast(ms))
> +  ++ms;
> +Sleep(ms.count());
> +#else
>  seconds s = duration_cast(ns);
>  timespec ts;
>  typedef decltype(ts.tv_sec) ts_sec;
> @@ -134,6 +140,7 @@ sleep_for(const chrono::nanoseconds& ns)
>
>  while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
>  ;
> +#endif
>  }
>  }
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
>


-- 
Saleem Abdulrasool
compnerd (at) compnerd (dot) org
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxx] r291331 - thread: implement sleep_for on Windows

2017-01-06 Thread Asiri Rathnayake via cfe-commits
Wouldn't it be better to introduce a __libcpp_thread_nanosleep() API call
here?

I bumped into a similar issue with a custom thread implementation and have
a downstream patch like that.

Cheers,

/ Asiri


On 7 Jan 2017 2:59 a.m., "Saleem Abdulrasool via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

Author: compnerd
Date: Fri Jan  6 20:48:30 2017
New Revision: 291331

URL: http://llvm.org/viewvc/llvm-project?rev=291331&view=rev
Log:
thread: implement sleep_for on Windows

Windows does not provide an implementation of `nanosleep`.  Round up the
time duration to the nearest ms and use `Sleep`.  Although this may
over-sleep, there is no hard real-time guarantee on the wake, so
sleeping a bit more is better than under-sleeping as it within the
specification.

Modified:
libcxx/trunk/src/thread.cpp

Modified: libcxx/trunk/src/thread.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/
thread.cpp?rev=291331&r1=291330&r2=291331&view=diff

==
--- libcxx/trunk/src/thread.cpp (original)
+++ libcxx/trunk/src/thread.cpp Fri Jan  6 20:48:30 2017
@@ -117,6 +117,12 @@ sleep_for(const chrono::nanoseconds& ns)
 using namespace chrono;
 if (ns > nanoseconds::zero())
 {
+#if defined(_LIBCPP_WIN32API)
+milliseconds ms = duration_cast(ns);
+if (ns > duration_cast(ms))
+  ++ms;
+Sleep(ms.count());
+#else
 seconds s = duration_cast(ns);
 timespec ts;
 typedef decltype(ts.tv_sec) ts_sec;
@@ -134,6 +140,7 @@ sleep_for(const chrono::nanoseconds& ns)

 while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
 ;
+#endif
 }
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r291331 - thread: implement sleep_for on Windows

2017-01-06 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Fri Jan  6 20:48:30 2017
New Revision: 291331

URL: http://llvm.org/viewvc/llvm-project?rev=291331&view=rev
Log:
thread: implement sleep_for on Windows

Windows does not provide an implementation of `nanosleep`.  Round up the
time duration to the nearest ms and use `Sleep`.  Although this may
over-sleep, there is no hard real-time guarantee on the wake, so
sleeping a bit more is better than under-sleeping as it within the
specification.

Modified:
libcxx/trunk/src/thread.cpp

Modified: libcxx/trunk/src/thread.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/thread.cpp?rev=291331&r1=291330&r2=291331&view=diff
==
--- libcxx/trunk/src/thread.cpp (original)
+++ libcxx/trunk/src/thread.cpp Fri Jan  6 20:48:30 2017
@@ -117,6 +117,12 @@ sleep_for(const chrono::nanoseconds& ns)
 using namespace chrono;
 if (ns > nanoseconds::zero())
 {
+#if defined(_LIBCPP_WIN32API)
+milliseconds ms = duration_cast(ns);
+if (ns > duration_cast(ms))
+  ++ms;
+Sleep(ms.count());
+#else
 seconds s = duration_cast(ns);
 timespec ts;
 typedef decltype(ts.tv_sec) ts_sec;
@@ -134,6 +140,7 @@ sleep_for(const chrono::nanoseconds& ns)
 
 while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
 ;
+#endif
 }
 }
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits