Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Python/thread.c

    r2 r388  
    2525
    2626#ifdef __sgi
    27 #ifndef HAVE_PTHREAD_H /* XXX Need to check in configure.in */
     27#ifndef HAVE_PTHREAD_H /* XXX Need to check in configure.ac */
    2828#undef _POSIX_THREADS
    2929#endif
     
    4747
    4848/* Check if we're running on HP-UX and _SC_THREADS is defined. If so, then
    49    enough of the Posix threads package is implimented to support python
     49   enough of the Posix threads package is implemented to support python
    5050   threads.
    5151
     
    6565#ifdef Py_DEBUG
    6666static int thread_debug = 0;
    67 #define dprintf(args)   (void)((thread_debug & 1) && printf args)
    68 #define d2printf(args)  ((thread_debug & 8) && printf args)
     67#define dprintf(args)   (void)((thread_debug & 1) && printf args)
     68#define d2printf(args)  ((thread_debug & 8) && printf args)
    6969#else
    7070#define dprintf(args)
     
    8080{
    8181#ifdef Py_DEBUG
    82         char *p = Py_GETENV("PYTHONTHREADDEBUG");
    83 
    84         if (p) {
    85                 if (*p)
    86                         thread_debug = atoi(p);
    87                 else
    88                         thread_debug = 1;
    89         }
     82    char *p = Py_GETENV("PYTHONTHREADDEBUG");
     83
     84    if (p) {
     85        if (*p)
     86            thread_debug = atoi(p);
     87        else
     88            thread_debug = 1;
     89    }
    9090#endif /* Py_DEBUG */
    91         if (initialized)
    92                 return;
    93         initialized = 1;
    94         dprintf(("PyThread_init_thread called\n"));
    95         PyThread__init_thread();
     91    if (initialized)
     92        return;
     93    initialized = 1;
     94    dprintf(("PyThread_init_thread called\n"));
     95    PyThread__init_thread();
    9696}
    9797
     
    138138#endif
    139139
    140 #ifdef WINCE_THREADS
    141 #include "thread_wince.h"
    142 #endif
    143 
    144140#ifdef PLAN9_THREADS
    145141#include "thread_plan9.h"
     
    160156PyThread_get_stacksize(void)
    161157{
    162         return _pythread_stacksize;
     158    return _pythread_stacksize;
    163159}
    164160
     
    166162   in thread_<platform>.h support changing the stack size.
    167163   Return 0 if stack size is valid,
    168           -1 if stack size value is invalid,
    169           -2 if setting stack size is not supported. */
     164      -1 if stack size value is invalid,
     165      -2 if setting stack size is not supported. */
    170166int
    171167PyThread_set_stacksize(size_t size)
    172168{
    173169#if defined(THREAD_SET_STACKSIZE)
    174         return THREAD_SET_STACKSIZE(size);
     170    return THREAD_SET_STACKSIZE(size);
    175171#else
    176         return -2;
     172    return -2;
    177173#endif
    178174}
     
    226222 */
    227223struct key {
    228         /* Next record in the list, or NULL if this is the last record. */
    229         struct key *next;
    230 
    231         /* The thread id, according to PyThread_get_thread_ident(). */
    232         long id;
    233 
    234         /* The key and its associated value. */
    235         int key;
    236         void *value;
     224    /* Next record in the list, or NULL if this is the last record. */
     225    struct key *next;
     226
     227    /* The thread id, according to PyThread_get_thread_ident(). */
     228    long id;
     229
     230    /* The key and its associated value. */
     231    int key;
     232    void *value;
    237233};
    238234
     
    265261find_key(int key, void *value)
    266262{
    267         struct key *p, *prev_p;
    268         long id = PyThread_get_thread_ident();
    269 
    270         if (!keymutex)
    271                 return NULL;
    272         PyThread_acquire_lock(keymutex, 1);
    273         prev_p = NULL;
    274         for (p = keyhead; p != NULL; p = p->next) {
    275                 if (p->id == id && p->key == key)
    276                         goto Done;
    277                 /* Sanity check.  These states should never happen but if
    278                 * they do we must abort.  Otherwise we'll end up spinning in
    279                 * in a tight loop with the lock held.  A similar check is done
    280                 * in pystate.c tstate_delete_common().  */
    281                 if (p == prev_p)
    282                         Py_FatalError("tls find_key: small circular list(!)");
    283                 prev_p = p;
    284                 if (p->next == keyhead)
    285                         Py_FatalError("tls find_key: circular list(!)");
    286         }
    287         if (value == NULL) {
    288                 assert(p == NULL);
    289                 goto Done;
    290         }
    291         p = (struct key *)malloc(sizeof(struct key));
    292         if (p != NULL) {
    293                 p->id = id;
    294                 p->key = key;
    295                 p->value = value;
    296                 p->next = keyhead;
    297                 keyhead = p;
    298         }
     263    struct key *p, *prev_p;
     264    long id = PyThread_get_thread_ident();
     265
     266    if (!keymutex)
     267        return NULL;
     268    PyThread_acquire_lock(keymutex, 1);
     269    prev_p = NULL;
     270    for (p = keyhead; p != NULL; p = p->next) {
     271        if (p->id == id && p->key == key)
     272            goto Done;
     273        /* Sanity check.  These states should never happen but if
     274        * they do we must abort.  Otherwise we'll end up spinning in
     275        * in a tight loop with the lock held.  A similar check is done
     276        * in pystate.c tstate_delete_common().  */
     277        if (p == prev_p)
     278            Py_FatalError("tls find_key: small circular list(!)");
     279        prev_p = p;
     280        if (p->next == keyhead)
     281            Py_FatalError("tls find_key: circular list(!)");
     282    }
     283    if (value == NULL) {
     284        assert(p == NULL);
     285        goto Done;
     286    }
     287    p = (struct key *)malloc(sizeof(struct key));
     288    if (p != NULL) {
     289        p->id = id;
     290        p->key = key;
     291        p->value = value;
     292        p->next = keyhead;
     293        keyhead = p;
     294    }
    299295 Done:
    300         PyThread_release_lock(keymutex);
    301         return p;
     296    PyThread_release_lock(keymutex);
     297    return p;
    302298}
    303299
     
    309305PyThread_create_key(void)
    310306{
    311         /* All parts of this function are wrong if it's called by multiple
    312         * threads simultaneously.
    313         */
    314         if (keymutex == NULL)
    315                 keymutex = PyThread_allocate_lock();
    316         return ++nkeys;
     307    /* All parts of this function are wrong if it's called by multiple
     308    * threads simultaneously.
     309    */
     310    if (keymutex == NULL)
     311        keymutex = PyThread_allocate_lock();
     312    return ++nkeys;
    317313}
    318314
     
    321317PyThread_delete_key(int key)
    322318{
    323         struct key *p, **q;
    324 
    325         PyThread_acquire_lock(keymutex, 1);
    326         q = &keyhead;
    327         while ((p = *q) != NULL) {
    328                 if (p->key == key) {
    329                         *q = p->next;
    330                         free((void *)p);
    331                         /* NB This does *not* free p->value! */
    332                 }
    333                 else
    334                         q = &p->next;
    335         }
    336         PyThread_release_lock(keymutex);
     319    struct key *p, **q;
     320
     321    PyThread_acquire_lock(keymutex, 1);
     322    q = &keyhead;
     323    while ((p = *q) != NULL) {
     324        if (p->key == key) {
     325            *q = p->next;
     326            free((void *)p);
     327            /* NB This does *not* free p->value! */
     328        }
     329        else
     330            q = &p->next;
     331    }
     332    PyThread_release_lock(keymutex);
    337333}
    338334
     
    346342PyThread_set_key_value(int key, void *value)
    347343{
    348         struct key *p;
    349 
    350         assert(value != NULL);
    351         p = find_key(key, value);
    352         if (p == NULL)
    353                 return -1;
    354         else
    355                 return 0;
     344    struct key *p;
     345
     346    assert(value != NULL);
     347    p = find_key(key, value);
     348    if (p == NULL)
     349        return -1;
     350    else
     351        return 0;
    356352}
    357353
     
    362358PyThread_get_key_value(int key)
    363359{
    364         struct key *p = find_key(key, NULL);
    365 
    366         if (p == NULL)
    367                 return NULL;
    368         else
    369                 return p->value;
     360    struct key *p = find_key(key, NULL);
     361
     362    if (p == NULL)
     363        return NULL;
     364    else
     365        return p->value;
    370366}
    371367
     
    374370PyThread_delete_key_value(int key)
    375371{
    376         long id = PyThread_get_thread_ident();
    377         struct key *p, **q;
    378 
    379         PyThread_acquire_lock(keymutex, 1);
    380         q = &keyhead;
    381         while ((p = *q) != NULL) {
    382                 if (p->key == key && p->id == id) {
    383                         *q = p->next;
    384                         free((void *)p);
    385                         /* NB This does *not* free p->value! */
    386                         break;
    387                 }
    388                 else
    389                         q = &p->next;
    390         }
    391         PyThread_release_lock(keymutex);
     372    long id = PyThread_get_thread_ident();
     373    struct key *p, **q;
     374
     375    PyThread_acquire_lock(keymutex, 1);
     376    q = &keyhead;
     377    while ((p = *q) != NULL) {
     378        if (p->key == key && p->id == id) {
     379            *q = p->next;
     380            free((void *)p);
     381            /* NB This does *not* free p->value! */
     382            break;
     383        }
     384        else
     385            q = &p->next;
     386    }
     387    PyThread_release_lock(keymutex);
    392388}
    393389
     
    400396PyThread_ReInitTLS(void)
    401397{
    402         long id = PyThread_get_thread_ident();
    403         struct key *p, **q;
    404 
    405         if (!keymutex)
    406                 return;
    407        
    408         /* As with interpreter_lock in PyEval_ReInitThreads()
    409            we just create a new lock without freeing the old one */
    410         keymutex = PyThread_allocate_lock();
    411 
    412         /* Delete all keys which do not match the current thread id */
    413         q = &keyhead;
    414         while ((p = *q) != NULL) {
    415                 if (p->id != id) {
    416                         *q = p->next;
    417                         free((void *)p);
    418                         /* NB This does *not* free p->value! */
    419                 }
    420                 else
    421                         q = &p->next;
    422         }
     398    long id = PyThread_get_thread_ident();
     399    struct key *p, **q;
     400
     401    if (!keymutex)
     402        return;
     403
     404    /* As with interpreter_lock in PyEval_ReInitThreads()
     405       we just create a new lock without freeing the old one */
     406    keymutex = PyThread_allocate_lock();
     407
     408    /* Delete all keys which do not match the current thread id */
     409    q = &keyhead;
     410    while ((p = *q) != NULL) {
     411        if (p->id != id) {
     412            *q = p->next;
     413            free((void *)p);
     414            /* NB This does *not* free p->value! */
     415        }
     416        else
     417            q = &p->next;
     418    }
    423419}
    424420
Note: See TracChangeset for help on using the changeset viewer.