diff options
Diffstat (limited to 'Python/thread.c')
| -rw-r--r-- | Python/thread.c | 40 | 
1 files changed, 17 insertions, 23 deletions
| diff --git a/Python/thread.c b/Python/thread.c index e55d342..4e695ae 100644 --- a/Python/thread.c +++ b/Python/thread.c @@ -91,10 +91,6 @@ static size_t _pythread_stacksize = 0;  #include "thread_nt.h"  #endif -#ifdef OS2_THREADS -#define PYTHREAD_NAME "os2" -#include "thread_os2.h" -#endif  /*  #ifdef FOOBAR_THREADS @@ -209,7 +205,7 @@ static int nkeys = 0;  /* PyThread_create_key() hands out nkeys+1 next */   * segfaults.  Now we lock the whole routine.   */  static struct key * -find_key(int key, void *value) +find_key(int set_value, int key, void *value)  {      struct key *p, *prev_p;      long id = PyThread_get_thread_ident(); @@ -219,10 +215,13 @@ find_key(int key, void *value)      PyThread_acquire_lock(keymutex, 1);      prev_p = NULL;      for (p = keyhead; p != NULL; p = p->next) { -        if (p->id == id && p->key == key) +        if (p->id == id && p->key == key) { +            if (set_value) +                p->value = value;              goto Done; +        }          /* Sanity check.  These states should never happen but if -         * they do we must abort.  Otherwise we'll end up spinning in +         * they do we must abort.  Otherwise we'll end up spinning           * in a tight loop with the lock held.  A similar check is done           * in pystate.c tstate_delete_common().  */          if (p == prev_p) @@ -231,11 +230,11 @@ find_key(int key, void *value)          if (p->next == keyhead)              Py_FatalError("tls find_key: circular list(!)");      } -    if (value == NULL) { +    if (!set_value && value == NULL) {          assert(p == NULL);          goto Done;      } -    p = (struct key *)malloc(sizeof(struct key)); +    p = (struct key *)PyMem_RawMalloc(sizeof(struct key));      if (p != NULL) {          p->id = id;          p->key = key; @@ -274,7 +273,7 @@ PyThread_delete_key(int key)      while ((p = *q) != NULL) {          if (p->key == key) {              *q = p->next; -            free((void *)p); +            PyMem_RawFree((void *)p);              /* NB This does *not* free p->value! */          }          else @@ -283,19 +282,12 @@ PyThread_delete_key(int key)      PyThread_release_lock(keymutex);  } -/* Confusing:  If the current thread has an association for key, - * value is ignored, and 0 is returned.  Else an attempt is made to create - * an association of key to value for the current thread.  0 is returned - * if that succeeds, but -1 is returned if there's not enough memory - * to create the association.  value must not be NULL. - */  int  PyThread_set_key_value(int key, void *value)  {      struct key *p; -    assert(value != NULL); -    p = find_key(key, value); +    p = find_key(1, key, value);      if (p == NULL)          return -1;      else @@ -308,7 +300,7 @@ PyThread_set_key_value(int key, void *value)  void *  PyThread_get_key_value(int key)  { -    struct key *p = find_key(key, NULL); +    struct key *p = find_key(0, key, NULL);      if (p == NULL)          return NULL; @@ -328,7 +320,7 @@ PyThread_delete_key_value(int key)      while ((p = *q) != NULL) {          if (p->key == key && p->id == id) {              *q = p->next; -            free((void *)p); +            PyMem_RawFree((void *)p);              /* NB This does *not* free p->value! */              break;          } @@ -361,7 +353,7 @@ PyThread_ReInitTLS(void)      while ((p = *q) != NULL) {          if (p->id != id) {              *q = p->next; -            free((void *)p); +            PyMem_RawFree((void *)p);              /* NB This does *not* free p->value! */          }          else @@ -403,8 +395,10 @@ PyThread_GetInfo(void)      int len;  #endif -    if (ThreadInfoType.tp_name == 0) -        PyStructSequence_InitType(&ThreadInfoType, &threadinfo_desc); +    if (ThreadInfoType.tp_name == 0) { +        if (PyStructSequence_InitType2(&ThreadInfoType, &threadinfo_desc) < 0) +            return NULL; +    }      threadinfo = PyStructSequence_New(&ThreadInfoType);      if (threadinfo == NULL) | 
