Skip to content

Commit 3121623

Browse files
committed
Simplify start failure path
1 parent c486503 commit 3121623

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

Modules/_threadmodule.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,6 @@ force_done(ThreadHandle *handle)
376376
return 0;
377377
}
378378

379-
static void
380-
start_failed(ThreadHandle *handle)
381-
{
382-
_PyOnceFlag_CallOnce(&handle->once, (_Py_once_fn_t *)force_done, handle);
383-
}
384-
385379
static int
386380
ThreadHandle_start(ThreadHandle *self, PyObject *func, PyObject *args,
387381
PyObject *kwargs)
@@ -405,8 +399,7 @@ ThreadHandle_start(ThreadHandle *self, PyObject *func, PyObject *args,
405399
struct bootstate *boot = PyMem_RawMalloc(sizeof(struct bootstate));
406400
if (boot == NULL) {
407401
PyErr_NoMemory();
408-
start_failed(self);
409-
return -1;
402+
goto start_failed;
410403
}
411404
PyInterpreterState *interp = _PyInterpreterState_GET();
412405
boot->tstate = _PyThreadState_New(interp, _PyThreadState_WHENCE_THREADING);
@@ -415,8 +408,7 @@ ThreadHandle_start(ThreadHandle *self, PyObject *func, PyObject *args,
415408
if (!PyErr_Occurred()) {
416409
PyErr_NoMemory();
417410
}
418-
start_failed(self);
419-
return -1;
411+
goto start_failed;
420412
}
421413
boot->func = Py_NewRef(func);
422414
boot->args = Py_NewRef(args);
@@ -430,9 +422,8 @@ ThreadHandle_start(ThreadHandle *self, PyObject *func, PyObject *args,
430422
if (PyThread_start_joinable_thread(thread_run, boot, &ident, &os_handle)) {
431423
PyThreadState_Clear(boot->tstate);
432424
thread_bootstate_free(boot, 1);
433-
start_failed(self);
434425
PyErr_SetString(ThreadError, "can't start new thread");
435-
return -1;
426+
goto start_failed;
436427
}
437428

438429
// Mark the handle running
@@ -448,6 +439,10 @@ ThreadHandle_start(ThreadHandle *self, PyObject *func, PyObject *args,
448439
_PyEvent_Notify(&boot->handle_ready);
449440

450441
return 0;
442+
443+
start_failed:
444+
_PyOnceFlag_CallOnce(&self->once, (_Py_once_fn_t *)force_done, self);
445+
return -1;
451446
}
452447

453448
static int

0 commit comments

Comments
 (0)