Skip to content

Commit

Permalink
Another POSIX thread destructor fix (Issue #293)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Jul 14, 2022
1 parent e1dd723 commit d32818a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
3 changes: 1 addition & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Changes in Mini-XML 3.3.1

- Fixed a POSIX thread cleanup bug on macOS - per-thread data destructor called
twice.
- Fixed POSIX thread cleanup bugs (Issue #293)


# Changes in Mini-XML 3.3
Expand Down
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Mini-XML

Copyright © 2003-2020 by Michael R Sweet
Copyright © 2003-2022 by Michael R Sweet


(Optional) Exceptions to the Apache 2.0 License:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ current version of this software, documentation, and Github issue tracking page.
Legal Stuff
-----------

Copyright © 2003-2021 by Michael R Sweet
Copyright © 2003-2022 by Michael R Sweet

The Mini-XML library is licensed under the Apache License Version 2.0 with an
*optional* exception to allow linking against GPL2/LGPL2-only software. See the
Expand Down
12 changes: 8 additions & 4 deletions mxml-private.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* https://www.msweet.org/mxml
*
* Copyright © 2003-2021 by Michael R Sweet.
* Copyright © 2003-2022 by Michael R Sweet.
*
* Licensed under Apache License v2.0. See the file "LICENSE" for more
* information.
Expand All @@ -26,7 +26,7 @@
* be unloaded safely, although since there is no standard way to do so I
* can't even provide any guarantees that you can do it safely on all platforms.
*
* This code currently supports AIX, HP-UX, Linux, Mac OS X, Solaris, and
* This code currently supports AIX, HP-UX, Linux, macOS, Solaris, and
* Windows. It might work on the BSDs and IRIX, but I haven't tested that.
*/

Expand All @@ -36,7 +36,7 @@
#elif defined(__hpux)
# pragma FINI _mxml_fini
# define _MXML_FINI _mxml_fini
#elif defined(__GNUC__) /* Linux and Mac OS X */
#elif defined(__GNUC__) /* Linux and macOS */
# define _MXML_FINI __attribute((destructor)) _mxml_fini
#else
# define _MXML_FINI _fini
Expand Down Expand Up @@ -140,6 +140,8 @@ mxml_real_cb(mxml_node_t *node) /* I - Current node */
#ifdef HAVE_PTHREAD_H /**** POSIX threading ****/
# include <pthread.h>

static int _mxml_initialized = 0;
/* Have we been initialized? */
static pthread_key_t _mxml_key; /* Thread local storage key */
static pthread_once_t _mxml_key_once = PTHREAD_ONCE_INIT;
/* One-time initialization object */
Expand All @@ -165,7 +167,8 @@ _mxml_destructor(void *g) /* I - Global data */
static void
_MXML_FINI(void)
{
pthread_key_delete(_mxml_key);
if (_mxml_initialized)
pthread_key_delete(_mxml_key);
}


Expand Down Expand Up @@ -202,6 +205,7 @@ _mxml_global(void)
static void
_mxml_init(void)
{
_mxml_initialized = 1;
pthread_key_create(&_mxml_key, _mxml_destructor);
}

Expand Down

0 comments on commit d32818a

Please sign in to comment.