PyInterpreterState * PyInterpreterState_New(void) { PyInterpreterState *interp = (PyInterpreterState *) PyMem_RawMalloc(sizeof(PyInterpreterState)); if (interp != NULL) { HEAD_INIT(); #ifdef WITH_THREAD if (head_mutex == NULL) Py_FatalError("Can't initialize threads for interpreter"); #endif interp->modules = NULL; interp->modules_by_index = NULL; interp->sysdict = NULL; interp->builtins = NULL; interp->builtins_copy = NULL; interp->tstate_head = NULL; interp->codec_search_path = NULL; interp->codec_search_cache = NULL; interp->codec_error_registry = NULL; interp->codecs_initialized = 0; interp->fscodec_initialized = 0; interp->importlib = NULL; interp->import_func = NULL; interp->eval_frame = _PyEval_EvalFrameDefault; #ifdef HAVE_DLOPEN #if HAVE_DECL_RTLD_NOW interp->dlopenflags = RTLD_NOW; #else interp->dlopenflags = RTLD_LAZY; #endif #endif #ifdef HAVE_FORK interp->before_forkers = NULL; interp->after_forkers_parent = NULL; interp->after_forkers_child = NULL; #endif HEAD_LOCK(); interp->next = interp_head; if (interp_main == NULL) { interp_main = interp; } interp_head = interp; if (_next_interp_id < 0) { /* overflow or Py_Initialize() not called! */ PyErr_SetString(PyExc_RuntimeError, "failed to get an interpreter ID"); interp = NULL; } else { interp->id = _next_interp_id; _next_interp_id += 1; } HEAD_UNLOCK(); } return interp; }
/* Reset the TLS key - called by PyOS_AfterFork_Child(). * This should not be necessary, but some - buggy - pthread implementations * don't reset TLS upon fork(), see issue #10517. */ void _PyGILState_Reinit(void) { #ifdef WITH_THREAD head_mutex = NULL; HEAD_INIT(); #endif PyThreadState *tstate = PyGILState_GetThisThreadState(); PyThread_delete_key(autoTLSkey); if ((autoTLSkey = PyThread_create_key()) == -1) Py_FatalError("Could not allocate TLS entry"); /* If the thread had an associated auto thread state, reassociate it with * the new key. */ if (tstate && PyThread_set_key_value(autoTLSkey, (void *)tstate) < 0) Py_FatalError("Couldn't create autoTLSkey mapping"); }
PyInterpreterState * PyInterpreterState_New(void) { PyInterpreterState *interp = (PyInterpreterState *) PyMem_RawMalloc(sizeof(PyInterpreterState)); if (interp != NULL) { HEAD_INIT(); #ifdef WITH_THREAD if (head_mutex == NULL) Py_FatalError("Can't initialize threads for interpreter"); #endif interp->modules = NULL; interp->modules_by_index = NULL; interp->sysdict = NULL; interp->builtins = NULL; interp->builtins_copy = NULL; interp->tstate_head = NULL; interp->codec_search_path = NULL; interp->codec_search_cache = NULL; interp->codec_error_registry = NULL; interp->codecs_initialized = 0; interp->fscodec_initialized = 0; interp->importlib = NULL; #ifdef HAVE_DLOPEN #ifdef RTLD_NOW interp->dlopenflags = RTLD_NOW; #else interp->dlopenflags = RTLD_LAZY; #endif #endif #ifdef WITH_TSC interp->tscdump = 0; #endif HEAD_LOCK(); interp->next = interp_head; interp_head = interp; HEAD_UNLOCK(); } return interp; }
#include <init.h> #include <string.h> #include <platform.h> static int match(struct device *dev, struct driver *drv); static struct bus platform_bus = { .name = "platform", .match = match, .dev_list = HEAD_INIT(platform_bus.dev_list), .drv_list = HEAD_INIT(platform_bus.drv_list), }; static int match(struct device *dev, struct driver *drv) { struct platform_device *plat_dev; // struct platform_driver *plat_drv; plat_dev = container_of(dev, struct platform_device, dev); // plat_drv = container_of(drv, struct platform_driver, drv); return !strcmp(plat_dev->name, drv->name); } static int platform_driver_init(struct device *dev) { struct platform_device *plat_dev; struct platform_driver *plat_drv; plat_dev = container_of(dev, struct platform_device, dev); plat_drv = container_of(dev->drv, struct platform_driver, drv);