Couchbase
view release on metacpan or search on metacpan
xs/opcontext.c view on Meta::CPAN
#include "perl-couchbase.h"
SV *
plcb_opctx_new(PLCB_t *parent, int flags)
{
plcb_OPCTX *ctx;
SV *blessed;
if (parent->curctx) {
ctx = NUM2PTR(plcb_OPCTX*,SvIVX(SvRV(parent->curctx)));
if (ctx->nremaining == 0) {
plcb_opctx_clear(parent);
} else {
die("Existing context found. Existing context must be waited for or cleared");
}
}
if (parent->cachectx && (flags & PLCB_OPCTXf_IMPLICIT)) {
blessed = parent->cachectx;
parent->cachectx = NULL;
ctx = NUM2PTR(plcb_OPCTX*,SvIVX(SvRV(blessed)));
} else {
Newxz(ctx, 1, plcb_OPCTX);
ctx->docs = newHV();
ctx->parent = newRV_inc(parent->selfobj);
sv_rvweaken(ctx->parent);
blessed = newRV_noinc(newSViv(PTR2IV(ctx)));
sv_bless(blessed, parent->opctx_sync_stash);
}
ctx->flags = flags;
ctx->nremaining = 0;
parent->curctx = blessed;
SvREFCNT_inc(parent->curctx);
lcb_sched_enter(parent->instance);
return blessed;
}
void
plcb_opctx_clear(PLCB_t *parent)
{
plcb_OPCTX *ctx;
if (!parent->curctx) {
return;
}
if (!SvROK(parent->curctx)) {
SvREFCNT_dec(parent->curctx);
parent->curctx = NULL;
return;
}
ctx = NUM2PTR(plcb_OPCTX*,SvIVX(SvRV(parent->curctx)));
hv_clear(ctx->docs);
if (ctx->multi) {
ctx->multi->fail(ctx->multi);
ctx->multi = NULL;
}
if ((ctx->flags & PLCB_OPCTXf_IMPLICIT) && parent->cachectx == NULL) {
parent->cachectx = parent->curctx;
} else {
SvREFCNT_dec(parent->curctx);
}
parent->curctx = NULL;
}
void
plcb_opctx_initop(plcb_SINGLEOP *so, PLCB_t *parent, SV *doc, SV *ctx, SV *options)
{
if (!plcb_doc_isa(parent, doc)) {
die("Must pass a " PLCB_RET_CLASSNAME);
}
so->docrv = doc;
so->docav = (AV *)SvRV(doc);
so->opctx = ctx;
so->parent = parent;
plcb_doc_set_err(parent, so->docav, -1);
/* Extract options for this command */
if (options && SvTYPE(options) != SVt_NULL) {
if (SvROK(options) == 0 || SvTYPE(SvRV(options)) != SVt_PVHV) {
die("options must be undef or a HASH reference");
( run in 1.910 second using v1.01-cache-2.11-cpan-5b529ec07f3 )