Re: [PATCH v3] Cygwin: Implement sched_[gs]etaffinity()

2019-06-24 Thread Corinna Vinschen
Hi Mark,

On Jun 23 14:51, Mark Geisert wrote:
> This patch set implements the Linux syscalls sched_getaffinity,
> sched_setaffinity, pthread_getaffinity_np, and pthread_setaffinity_np.
> Linux has a straightforward view of the cpu sets used in affinity masks.
> They are simply long (1024-bit) bit masks.  This code emulates that view
> while internally dealing with Windows' distribution of available CPUs among
> processor groups.
> ---
>  newlib/libc/include/sched.h|  23 ++
>  winsup/cygwin/common.din   |   4 +
>  winsup/cygwin/include/cygwin/version.h |   4 +-
>  winsup/cygwin/include/pthread.h|   2 +
>  winsup/cygwin/miscfuncs.cc |  20 +-
>  winsup/cygwin/miscfuncs.h  |   1 +
>  winsup/cygwin/release/3.1.0|   3 +
>  winsup/cygwin/sched.cc | 308 +
>  winsup/cygwin/thread.cc|  19 ++
>  winsup/doc/new-features.xml|   6 +
>  winsup/doc/posix.xml   |   4 +
>  11 files changed, 389 insertions(+), 5 deletions(-)

This looks great!  I pushed it.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer


signature.asc
Description: PGP signature


[PATCH] Cygwin: timerfd: avoid a deadlock

2019-06-24 Thread Ken Brown
If a timer expires while the timerfd thread is in its inner loop,
check for the thread cancellation event before trying to enter
a_critical_section.  It's possible that timerfd_tracker::dtor has
entered its critical section and is trying to cancel the thread.  See
http://www.cygwin.org/ml/cygwin/2019-06/msg00096.html.
---
 winsup/cygwin/timerfd.cc | 5 +
 1 file changed, 5 insertions(+)

diff --git a/winsup/cygwin/timerfd.cc b/winsup/cygwin/timerfd.cc
index 8e4c94e66..e8261ef2e 100644
--- a/winsup/cygwin/timerfd.cc
+++ b/winsup/cygwin/timerfd.cc
@@ -137,6 +137,11 @@ timerfd_tracker::thread_func ()
  continue;
}
 
+ /* Avoid a deadlock if dtor has just entered its critical
+section and is trying to cancel the thread. */
+ if (IsEventSignalled (cancel_evt))
+   goto canceled;
+
  if (!enter_critical_section ())
continue;
  /* Make sure we haven't been abandoned and/or disarmed
-- 
2.21.0



Re: [PATCH] Cygwin: timerfd: avoid a deadlock

2019-06-24 Thread Ken Brown
On 6/24/2019 4:19 PM, Ken Brown wrote:
> If a timer expires while the timerfd thread is in its inner loop,
> check for the thread cancellation event before trying to enter
> a_critical_section.  It's possible that timerfd_tracker::dtor has
> entered its critical section and is trying to cancel the thread.  See
> http://www.cygwin.org/ml/cygwin/2019-06/msg00096.html.

There's a stupid typo ("a_critical_section") above.  I'll fix it before 
committing, if the patch is accepted.

Ken


[PATCH] Cygwin: Fix return value of sched_getaffinity

2019-06-24 Thread Mark Geisert
Return what the documentation says, instead of a misreading of it.
---
 winsup/cygwin/sched.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/winsup/cygwin/sched.cc b/winsup/cygwin/sched.cc
index e7b44d319..8f24bf80d 100644
--- a/winsup/cygwin/sched.cc
+++ b/winsup/cygwin/sched.cc
@@ -608,7 +608,7 @@ done:
   else
 {
   /* Emulate documented Linux kernel behavior on successful return */
-  status = wincap.cpu_count ();
+  status = sizeof (cpu_set_t);
 }
   return status;
 }
-- 
2.21.0