summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/findfp.c
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2009-10-22 01:23:17 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2009-10-22 01:23:17 +0000
commitbe40cf4f6608dcb8157ec353ae0fc6e449a06a2d (patch)
tree29977358369874429c14c743243db3114f2dc01d /lib/libc/stdio/findfp.c
parente990becb683185ae6d8df39ba534ec5200132b04 (diff)
Back out previous commit, as it caused too much growth for the install
media to fit
Diffstat (limited to 'lib/libc/stdio/findfp.c')
-rw-r--r--lib/libc/stdio/findfp.c36
1 files changed, 7 insertions, 29 deletions
diff --git a/lib/libc/stdio/findfp.c b/lib/libc/stdio/findfp.c
index f3e000c3591..2be93a56c74 100644
--- a/lib/libc/stdio/findfp.c
+++ b/lib/libc/stdio/findfp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: findfp.c,v 1.10 2009/10/21 16:04:23 guenther Exp $ */
+/* $OpenBSD: findfp.c,v 1.11 2009/10/22 01:23:16 guenther Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -39,7 +39,6 @@
#include <string.h>
#include "local.h"
#include "glue.h"
-#include "thread_private.h"
int __sdidinit;
@@ -55,8 +54,6 @@ int __sdidinit;
static FILE usual[FOPEN_MAX - 3];
static struct __sfileext usualext[FOPEN_MAX - 3];
static struct glue uglue = { 0, FOPEN_MAX - 3, usual };
-static struct glue *lastglue = &uglue;
-_THREAD_PRIVATE_MUTEX(__sfp_mutex);
struct __sfileext __sFext[3];
FILE __sF[3] = {
@@ -107,25 +104,16 @@ __sfp(void)
if (!__sdidinit)
__sinit();
-
- _THREAD_PRIVATE_MUTEX_LOCK(__sfp_mutex);
- for (g = &__sglue; g != NULL; g = g->next) {
+ for (g = &__sglue;; g = g->next) {
for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)
if (fp->_flags == 0)
goto found;
+ if (g->next == NULL && (g->next = moreglue(NDYNAMIC)) == NULL)
+ break;
}
-
- /* release lock while mallocing */
- _THREAD_PRIVATE_MUTEX_UNLOCK(__sfp_mutex);
- if ((g = moreglue(NDYNAMIC)) == NULL)
- return (NULL);
- _THREAD_PRIVATE_MUTEX_LOCK(__sfp_mutex);
- lastglue->next = g;
- lastglue = g;
- fp = g->iobs;
+ return (NULL);
found:
fp->_flags = 1; /* reserve this slot; caller sets real flags */
- _THREAD_PRIVATE_MUTEX_UNLOCK(__sfp_mutex);
fp->_p = NULL; /* no current pointer */
fp->_w = 0; /* nothing to read or write */
fp->_r = 0;
@@ -155,12 +143,8 @@ f_prealloc(void)
n = getdtablesize() - FOPEN_MAX + 20; /* 20 for slop. */
for (g = &__sglue; (n -= g->niobs) > 0 && g->next; g = g->next)
/* void */;
- if (n > 0 && ((g = moreglue(n)) != NULL)) {
- _THREAD_PRIVATE_MUTEX_LOCK(__sfp_mutex);
- lastglue->next = g;
- lastglue = g;
- _THREAD_PRIVATE_MUTEX_UNLOCK(__sfp_mutex);
- }
+ if (n > 0)
+ g->next = moreglue(n);
}
/*
@@ -184,18 +168,12 @@ _cleanup(void)
void
__sinit(void)
{
- _THREAD_PRIVATE_MUTEX(__sinit_mutex);
int i;
- _THREAD_PRIVATE_MUTEX_LOCK(__sinit_mutex);
- if (__sdidinit)
- goto out; /* bail out if caller lost the race */
for (i = 0; i < FOPEN_MAX - 3; i++) {
_FILEEXT_SETUP(usual+i, usualext+i);
}
/* make sure we clean up on exit */
__atexit_register_cleanup(_cleanup); /* conservative */
__sdidinit = 1;
-out:
- _THREAD_PRIVATE_MUTEX_UNLOCK(__sinit_mutex);
}