Module Name: src Committed By: kamil Date: Wed Jan 29 14:41:57 UTC 2020
Modified Files: src/lib/libpthread: pthread_barrier.c Log Message: Use pthread_barrierattr_t and pthread_barrier_t magic fields Set respectively _PT_BARRIER_DEAD for pthread_barrier_destroy() and _PT_BARRIERATTR_DEAD for pthread_barrierattr_destroy(). Validate _PT_BARRIER_MAGIC in pthread_barrier_t and _PT_BARRIERATTR_MAGIC in pthread_barrierattr_t accordingly. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/lib/libpthread/pthread_barrier.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libpthread/pthread_barrier.c diff -u src/lib/libpthread/pthread_barrier.c:1.20 src/lib/libpthread/pthread_barrier.c:1.21 --- src/lib/libpthread/pthread_barrier.c:1.20 Sun Jul 3 14:24:58 2016 +++ src/lib/libpthread/pthread_barrier.c Wed Jan 29 14:41:57 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_barrier.c,v 1.20 2016/07/03 14:24:58 christos Exp $ */ +/* $NetBSD: pthread_barrier.c,v 1.21 2020/01/29 14:41:57 kamil Exp $ */ /*- * Copyright (c) 2001, 2003, 2006, 2007, 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread_barrier.c,v 1.20 2016/07/03 14:24:58 christos Exp $"); +__RCSID("$NetBSD: pthread_barrier.c,v 1.21 2020/01/29 14:41:57 kamil Exp $"); #include <errno.h> @@ -41,9 +41,9 @@ int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count) { - - if (attr != NULL && attr->ptba_magic != _PT_BARRIERATTR_MAGIC) - return EINVAL; + + pthread__error(EINVAL, "Invalid barrier attribute", + attr == NULL || attr->ptba_magic == _PT_BARRIERATTR_MAGIC); if (count == 0) return EINVAL; @@ -59,10 +59,13 @@ int pthread_barrier_destroy(pthread_barrier_t *barrier) { - if (barrier->ptb_magic != _PT_BARRIER_MAGIC) - return EINVAL; + pthread__error(EINVAL, "Invalid barrier", + barrier->ptb_magic == _PT_BARRIER_MAGIC); if (barrier->ptb_curcount != 0) return EBUSY; + + barrier->ptb_magic = _PT_BARRIER_DEAD; + return 0; } @@ -73,8 +76,8 @@ pthread_barrier_wait(pthread_barrier_t * pthread_t self; unsigned int gen; - if (barrier->ptb_magic != _PT_BARRIER_MAGIC) - return EINVAL; + pthread__error(EINVAL, "Invalid barrier", + barrier->ptb_magic == _PT_BARRIER_MAGIC); /* * A single arbitrary thread is supposed to return @@ -123,6 +126,9 @@ pthread_barrierattr_getpshared(const pth int * __restrict pshared) { + pthread__error(EINVAL, "Invalid barrier attribute", + attr->ptba_magic == _PT_BARRIERATTR_MAGIC); + *pshared = PTHREAD_PROCESS_PRIVATE; return 0; } @@ -131,6 +137,9 @@ int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, int pshared) { + pthread__error(EINVAL, "Invalid barrier attribute", + attr->ptba_magic == _PT_BARRIERATTR_MAGIC); + switch(pshared) { case PTHREAD_PROCESS_PRIVATE: return 0; @@ -153,8 +162,8 @@ int pthread_barrierattr_destroy(pthread_barrierattr_t *attr) { - if (attr->ptba_magic != _PT_BARRIERATTR_MAGIC) - return EINVAL; + pthread__error(EINVAL, "Invalid barrier attribute", + attr->ptba_magic == _PT_BARRIERATTR_MAGIC); attr->ptba_magic = _PT_BARRIERATTR_DEAD; return 0; }