2004-01-27 Jeff Johnston <jjohnstn@redhat.com>
* libc/stdlib/atexit.c: Protect global atexit list with a lock when newlib is multithreaded.
This commit is contained in:
parent
01e0a77749
commit
d5b6c23483
|
@ -1,3 +1,8 @@
|
|||
2004-01-27 Jeff Johnston <jjohnstn@redhat.com>
|
||||
|
||||
* libc/stdlib/atexit.c: Protect global atexit list with a
|
||||
lock when newlib is multithreaded.
|
||||
|
||||
2004-01-27 Artem B. Bityuckiy <abitytsky@softminecorp.com>
|
||||
|
||||
* configure.in: Add support to generate iconv converter flags
|
||||
|
|
|
@ -53,6 +53,7 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
|
|||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <reent.h>
|
||||
#include <sys/lock.h>
|
||||
|
||||
/*
|
||||
* Register a function to be performed at exit.
|
||||
|
@ -65,6 +66,12 @@ _DEFUN (atexit,
|
|||
{
|
||||
register struct _atexit *p;
|
||||
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__LOCK_INIT(static, lock);
|
||||
|
||||
__lock_acquire(lock);
|
||||
#endif
|
||||
|
||||
/* _REENT_SMALL atexit() doesn't allow more than the required 32 entries. */
|
||||
#ifndef _REENT_SMALL
|
||||
if ((p = _GLOBAL_REENT->_atexit) == NULL)
|
||||
|
@ -72,7 +79,12 @@ _DEFUN (atexit,
|
|||
if (p->_ind >= _ATEXIT_SIZE)
|
||||
{
|
||||
if ((p = (struct _atexit *) malloc (sizeof *p)) == NULL)
|
||||
return -1;
|
||||
{
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__lock_release(lock);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
p->_ind = 0;
|
||||
p->_on_exit_args._fntypes = 0;
|
||||
p->_next = _GLOBAL_REENT->_atexit;
|
||||
|
@ -81,8 +93,16 @@ _DEFUN (atexit,
|
|||
#else
|
||||
p = &_GLOBAL_REENT->_atexit;
|
||||
if (p->_ind >= _ATEXIT_SIZE)
|
||||
return -1;
|
||||
{
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__lock_release(lock);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
p->_fns[p->_ind++] = fn;
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__lock_release(lock);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue