comparison Python/thread.c @ 48217:eefe4450f773 2.5

Backport r60148 and r65481: sanity checks to avoid infinite loops.
author Georg Brandl <georg@python.org>
date Tue, 12 Aug 2008 08:46:02 +0000
parents 7c09b66f04bd
children 8d902c513ba0
comparison
equal deleted inserted replaced
48216:ef41dae30f35 48217:eefe4450f773
262 * segfaults. Now we lock the whole routine. 262 * segfaults. Now we lock the whole routine.
263 */ 263 */
264 static struct key * 264 static struct key *
265 find_key(int key, void *value) 265 find_key(int key, void *value)
266 { 266 {
267 struct key *p; 267 struct key *p, *prev_p;
268 long id = PyThread_get_thread_ident(); 268 long id = PyThread_get_thread_ident();
269 269
270 if (!keymutex) 270 if (!keymutex)
271 return NULL; 271 return NULL;
272 PyThread_acquire_lock(keymutex, 1); 272 PyThread_acquire_lock(keymutex, 1);
273 prev_p = NULL;
273 for (p = keyhead; p != NULL; p = p->next) { 274 for (p = keyhead; p != NULL; p = p->next) {
274 if (p->id == id && p->key == key) 275 if (p->id == id && p->key == key)
275 goto Done; 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(!)");
276 } 286 }
277 if (value == NULL) { 287 if (value == NULL) {
278 assert(p == NULL); 288 assert(p == NULL);
279 goto Done; 289 goto Done;
280 } 290 }