Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libpthread Use pthread_barrierattr_t and pthread_barrier...
details: https://anonhg.NetBSD.org/src/rev/da282817d78b
branches: trunk
changeset: 744313:da282817d78b
user: kamil <kamil%NetBSD.org@localhost>
date: Wed Jan 29 14:41:57 2020 +0000
description:
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.
diffstat:
lib/libpthread/pthread_barrier.c | 31 ++++++++++++++++++++-----------
1 files changed, 20 insertions(+), 11 deletions(-)
diffs (89 lines):
diff -r 7dcb2aeff720 -r da282817d78b lib/libpthread/pthread_barrier.c
--- a/lib/libpthread/pthread_barrier.c Wed Jan 29 13:54:41 2020 +0000
+++ b/lib/libpthread/pthread_barrier.c Wed Jan 29 14:41:57 2020 +0000
@@ -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 @@
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 @@
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_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 @@
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 @@
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 @@
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;
}
Home |
Main Index |
Thread Index |
Old Index