Commit 8459ec96 authored by Xavier Thompson's avatar Xavier Thompson

Add a builtin macro to get current cypclass nogil refcount

parent 2bcc2325
......@@ -652,15 +652,17 @@ def init_builtin_structs():
name, "struct", scope, 1, None, cname = cname)
def inject_cypclass_refcount_macros():
reference_to_cy_object_type = PyrexTypes.CReferenceType(PyrexTypes.cy_object_type)
incref_macro_type = PyrexTypes.CFuncType(PyrexTypes.c_void_type, [PyrexTypes.CFuncTypeArg("obj", PyrexTypes.cy_object_type, None)], nogil = 1)
incref_type = PyrexTypes.CFuncType(PyrexTypes.c_void_type, [PyrexTypes.CFuncTypeArg("obj", PyrexTypes.cy_object_type, None)], nogil = 1)
# The decref macros set their argument to NULL when the counter reaches 0,
# so we pretend to Cython that it's a c++ function with the argument passed by reference.
# This keeps the compiler from using std::move when calling the macro for instance.
decref_macro_type = PyrexTypes.CFuncType(PyrexTypes.c_void_type, [PyrexTypes.CFuncTypeArg("obj", reference_to_cy_object_type, None)], nogil = 1)
reference_to_cy_object_type = PyrexTypes.CReferenceType(PyrexTypes.cy_object_type)
decref_type = PyrexTypes.CFuncType(PyrexTypes.c_void_type, [PyrexTypes.CFuncTypeArg("obj", reference_to_cy_object_type, None)], nogil = 1)
getref_type = PyrexTypes.CFuncType(PyrexTypes.c_int_type, [PyrexTypes.CFuncTypeArg("obj", PyrexTypes.cy_object_type, None)], nogil = 1)
for macro, macro_type in [("Cy_INCREF", incref_macro_type), ("Cy_DECREF", decref_macro_type), ("Cy_XDECREF", decref_macro_type)]:
for macro, macro_type in [("Cy_INCREF", incref_type), ("Cy_DECREF", decref_type), ("Cy_XDECREF", decref_type), ("Cy_GETREF", getref_type)]:
builtin_scope.declare_builtin_cfunction(macro, macro_type, macro)
def inject_cypclass_lock_macros():
......
......@@ -67,6 +67,7 @@
virtual ~CyObject();
void CyObject_INCREF();
int CyObject_DECREF();
int CyObject_GETREF();
void CyObject_RLOCK();
void CyObject_WLOCK();
void CyObject_UNLOCK();
......@@ -125,6 +126,10 @@
op->CyObject_INCREF();
}
static inline int _Cy_GETREF(CyObject *op) {
return op->CyObject_GETREF();
}
static inline void _Cy_RLOCK(CyObject *op) {
if (op != NULL) {
op->CyObject_RLOCK();
......@@ -227,6 +232,7 @@
#define Cy_INCREF(op) do {if (op != NULL) {_Cy_INCREF(_CyObject_CAST(op));}} while(0)
#define Cy_DECREF(op) do {if (_Cy_DECREF(_CyObject_CAST(op))) {op = NULL;}} while(0)
#define Cy_XDECREF(op) do {if (op != NULL) {Cy_DECREF(op);}} while(0)
#define Cy_GETREF(op) (_Cy_GETREF(_CyObject_CAST(op)))
#define Cy_GOTREF(op)
#define Cy_XGOTREF(op)
#define Cy_GIVEREF(op)
......@@ -469,6 +475,11 @@ int CyObject::CyObject_DECREF()
return 0;
}
int CyObject::CyObject_GETREF()
{
return this->nogil_ob_refcnt;
}
void CyObject::CyObject_RLOCK()
{
this->ob_lock.rlock();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment