File dp_interrupt_guard_procglobal.h¶
File List > dp_interrupt_guard > dp_interrupt_guard_procglobal.h
Go to the documentation of this file
/*
* dp_interrupt_guard_procglobal.h — generated by just-makeit (gh-1117). DO NOT EDIT.
*
* `dp_interrupt_guard` declares `process_global = true`: its file-scope state is
* one-per-PROCESS, not one-per-`.so`. CPython imports extensions RTLD_LOCAL
* and jm links this core statically into every module that needs it, so
* without a rendezvous each `.so` would hold its own copy — a flag set
* through one module is not the flag another module reads.
*
* jm generates that rendezvous into every module's PyInit. It cannot
* generate the two functions below: the state is yours, declared in
* dp_interrupt_guard_core.c and reached by your own code on every access, so nothing
* generated can allocate it or route reads through a pointer it does not
* own.
*
* Implement them in dp_interrupt_guard_core.c, holding the state behind one pointer:
*
* static dp_interrupt_guard_state_t g_own;
* static dp_interrupt_guard_state_t *g_cur = &g_own;
*
* void *dp_interrupt_guard_state_ptr(void) { return (void *)g_cur; }
* void dp_interrupt_guard_state_adopt(void *shared)
* { if (shared) g_cur = (dp_interrupt_guard_state_t *)shared; }
*
* and read through `g_cur` everywhere else. Adoption happens at import,
* before any of your code runs, so nothing has to be thread-safe here.
*/
#ifndef DP_INTERRUPT_GUARD_PROCGLOBAL_H
#define DP_INTERRUPT_GUARD_PROCGLOBAL_H
/* The address of this `.so`'s state — the OWNER module publishes it. */
void *dp_interrupt_guard_state_ptr(void);
/* Point this `.so` at the owner's state — every OTHER module calls it. */
void dp_interrupt_guard_state_adopt(void *shared);
/*
* The rendezvous, for a binding jm does NOT generate (a
* `no_generate` module). To ADOPT, in your PyInit_ once the module
* object exists (error handling omitted -- every pointer here can
* be NULL):
*
* PyObject *own = PyImport_ImportModule(DP_INTERRUPT_GUARD_PG_OWNER);
* PyObject *cap = PyObject_GetAttrString(own, DP_INTERRUPT_GUARD_PG_ATTR);
* dp_interrupt_guard_state_adopt(
* PyCapsule_GetPointer(cap, DP_INTERRUPT_GUARD_PG_CAPSULE));
*
* To PUBLISH, when this module owns the state:
*
* PyModule_AddObject(m, DP_INTERRUPT_GUARD_PG_ATTR,
* PyCapsule_New(dp_interrupt_guard_state_ptr(), DP_INTERRUPT_GUARD_PG_CAPSULE,
* NULL));
*/
#define DP_INTERRUPT_GUARD_PG_OWNER "doppler.interrupt.interrupt"
#define DP_INTERRUPT_GUARD_PG_ATTR "_jm_pg_dp_interrupt_guard"
#define DP_INTERRUPT_GUARD_PG_CAPSULE "doppler.dp_interrupt_guard._jm_procglobal"
#endif /* DP_INTERRUPT_GUARD_PROCGLOBAL_H */