diff options
author | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2011-09-19 20:21:38 +0000 |
---|---|---|
committer | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2011-09-19 20:21:38 +0000 |
commit | 7986630e01303bbaa4068775983d12e840a356e7 (patch) | |
tree | 7f344ccf5f1531d20378dbb447461d57917cc993 /lib/libX11 | |
parent | bb77efcbc6b5630b2a1579601fa3fb085b0bd3c1 (diff) |
Fix _Xthr_once_stub_() to call the init routine for each different id.
With tweaks from and ok ariane@
Diffstat (limited to 'lib/libX11')
-rw-r--r-- | lib/libX11/src/UIThrStubs.c | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/lib/libX11/src/UIThrStubs.c b/lib/libX11/src/UIThrStubs.c index 4386e7af3..28b2cc1e9 100644 --- a/lib/libX11/src/UIThrStubs.c +++ b/lib/libX11/src/UIThrStubs.c @@ -167,20 +167,40 @@ _Xthr_zero_stub_() return(0); } +#include <errno.h> + +#define XTHR_ONCE_KEYS_CHUNK 100 +static void**_Xthr_once_keys_ = NULL; +static unsigned int _Xthr_once_last_key_ = 0; + static int _Xthr_once_stub_(void *id, void (*routine)(void)) { - static int done = 0; - - if (!done) { - routine(); - done++; + void **tmp; + unsigned int i; + + /* look for the id */ + for (i = 0; i < _Xthr_once_last_key_; i++) + if (_Xthr_once_keys_[i] == id) + return 0; + /* allocate more room if needed */ + if ((_Xthr_once_last_key_ % XTHR_ONCE_KEYS_CHUNK) == 0) { + tmp = realloc(_Xthr_once_keys_, + (_Xthr_once_last_key_ + XTHR_ONCE_KEYS_CHUNK)*sizeof(void *)); + if (tmp == NULL) { + return ENOMEM; + } + for (i = 0; i < XTHR_ONCE_KEYS_CHUNK; i++) + tmp[_Xthr_once_last_key_ + i] = NULL; + _Xthr_once_keys_ = tmp; } + /* call the routine */ + routine(); + /* Mark it */ + _Xthr_once_keys_[_Xthr_once_last_key_++] = id; return 0; } -#include <errno.h> - #define XTHR_KEYS_CHUNK 100 static void **_Xthr_keys_ = NULL; @@ -196,11 +216,10 @@ _Xthr_key_create_stub_(unsigned int *key, void (*destructor)(void *)) tmp = realloc(_Xthr_keys_, (_Xthr_last_key_ + XTHR_KEYS_CHUNK)*sizeof(void *)); if (tmp == NULL) { - free(_Xthr_keys_); return ENOMEM; } for (i = 0; i < XTHR_KEYS_CHUNK; i++) - tmp[_Xthr_last_key_ + i] = 0; + tmp[_Xthr_last_key_ + i] = NULL; _Xthr_keys_ = tmp; } *key = _Xthr_last_key_++; |