[hurd,commited,05/10] htl: Add support for semaphore maximum value
diff mbox series

Message ID 20200210010508.428251-5-samuel.thibault@ens-lyon.org
State New
Headers show
Series
  • [hurd,commited,01/10] htl: clean __pthread_get_cleanup_stack hidden proto
Related show

Commit Message

Samuel Thibault Feb. 10, 2020, 1:05 a.m. UTC
---
 sysdeps/htl/sem-post.c             | 7 +++++++
 sysdeps/mach/hurd/bits/local_lim.h | 3 +++
 2 files changed, 10 insertions(+)

Patch
diff mbox series

diff --git a/sysdeps/htl/sem-post.c b/sysdeps/htl/sem-post.c
index 77f297314e..2e0be8fc49 100644
--- a/sysdeps/htl/sem-post.c
+++ b/sysdeps/htl/sem-post.c
@@ -30,6 +30,13 @@  __sem_post (sem_t *sem)
   if (sem->__value > 0)
     /* Do a quick up.  */
     {
+      if (sem->__value == SEM_VALUE_MAX)
+	{
+	  __pthread_spin_unlock (&sem->__lock);
+	  errno = EOVERFLOW;
+	  return -1;
+	}
+
       assert (sem->__queue == NULL);
       sem->__value++;
       __pthread_spin_unlock (&sem->__lock);
diff --git a/sysdeps/mach/hurd/bits/local_lim.h b/sysdeps/mach/hurd/bits/local_lim.h
index 348eee74bb..8e781e4965 100644
--- a/sysdeps/mach/hurd/bits/local_lim.h
+++ b/sysdeps/mach/hurd/bits/local_lim.h
@@ -41,3 +41,6 @@ 
 
 /* The number of threads per process.  */
 #define _POSIX_THREAD_THREADS_MAX	64
+
+/* Maximum value the semaphore can have.  */
+#define SEM_VALUE_MAX   (2147483647)