本文整理汇总了C++中Lck_Lock函数的典型用法代码示例。如果您正苦于以下问题:C++ Lck_Lock函数的具体用法?C++ Lck_Lock怎么用?C++ Lck_Lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Lck_Lock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bes_conn_try
static int
bes_conn_try(const struct sess *sp, struct backend *bp)
{
int s;
Lck_Lock(&bp->mtx);
bp->refcount++;
bp->n_conn++; /* It mostly works */
Lck_Unlock(&bp->mtx);
s = -1;
assert(bp->ipv6 != NULL || bp->ipv4 != NULL);
/* release lock during stuff that can take a long time */
if (params->prefer_ipv6 && bp->ipv6 != NULL)
s = VBE_TryConnect(sp, PF_INET6, bp->ipv6, bp->ipv6len, bp);
if (s == -1 && bp->ipv4 != NULL)
s = VBE_TryConnect(sp, PF_INET, bp->ipv4, bp->ipv4len, bp);
if (s == -1 && !params->prefer_ipv6 && bp->ipv6 != NULL)
s = VBE_TryConnect(sp, PF_INET6, bp->ipv6, bp->ipv6len, bp);
if (s < 0) {
Lck_Lock(&bp->mtx);
bp->n_conn--;
bp->refcount--; /* Only keep ref on success */
Lck_Unlock(&bp->mtx);
}
return (s);
}
示例2: VBO_DerefBusyObj
void
VBO_DerefBusyObj(struct worker *wrk, struct busyobj **pbo)
{
struct busyobj *bo;
struct objcore *oc = NULL;
unsigned r;
CHECK_OBJ_ORNULL(wrk, WORKER_MAGIC);
AN(pbo);
bo = *pbo;
*pbo = NULL;
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
CHECK_OBJ_ORNULL(bo->fetch_objcore, OBJCORE_MAGIC);
CHECK_OBJ_ORNULL(bo->fetch_obj, OBJECT_MAGIC);
if (bo->fetch_objcore != NULL) {
oc = bo->fetch_objcore;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
CHECK_OBJ_NOTNULL(oc->objhead, OBJHEAD_MAGIC);
Lck_Lock(&oc->objhead->mtx);
assert(bo->refcount > 0);
r = --bo->refcount;
Lck_Unlock(&oc->objhead->mtx);
} else {
Lck_Lock(&bo->mtx);
assert(bo->refcount > 0);
r = --bo->refcount;
Lck_Unlock(&bo->mtx);
}
if (r)
return;
VSLb(bo->vsl, SLT_BereqAcct, "%ju %ju %ju %ju %ju %ju",
(uintmax_t)bo->acct.bereq_hdrbytes,
(uintmax_t)bo->acct.bereq_bodybytes,
(uintmax_t)(bo->acct.bereq_hdrbytes + bo->acct.bereq_bodybytes),
(uintmax_t)bo->acct.beresp_hdrbytes,
(uintmax_t)bo->acct.beresp_bodybytes,
(uintmax_t)(bo->acct.beresp_hdrbytes + bo->acct.beresp_bodybytes));
VSL_End(bo->vsl);
if (bo->fetch_objcore != NULL) {
AN(wrk);
(void)HSH_DerefObjCore(&wrk->stats, &bo->fetch_objcore);
}
VCL_Rel(&bo->vcl);
if (bo->vary != NULL)
free(bo->vary);
memset(&bo->refcount, 0,
sizeof *bo - offsetof(struct busyobj, refcount));
if (cache_param->bo_cache && wrk != NULL && wrk->nbo == NULL)
wrk->nbo = bo;
else
VBO_Free(&bo);
}
示例3: SES_Delete
void
SES_Delete(struct sess *sp)
{
struct acct *b = &sp->acct_ses;
struct sessmem *sm;
static char noaddr[] = "-";
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
sm = sp->mem;
CHECK_OBJ_NOTNULL(sm, SESSMEM_MAGIC);
AZ(sp->obj);
AZ(sp->vcl);
assert(!isnan(b->first));
assert(!isnan(sp->t_end));
if (sp->addr == NULL)
sp->addr = noaddr;
if (sp->port == NULL)
sp->port = noaddr;
VSL(SLT_StatSess, sp->id, "%s %s %.0f %ju %ju %ju %ju %ju %ju %ju",
sp->addr, sp->port, sp->t_end - b->first,
b->sess, b->req, b->pipe, b->pass,
b->fetch, b->hdrbytes, b->bodybytes);
if (sm->workspace != params->sess_workspace) {
free(sm);
sm = NULL;
} else {
/* Clean and prepare for reuse */
ses_setup(sm);
Lck_Lock(&ses_mem_mtx);
VTAILQ_INSERT_HEAD(&ses_free_mem[1 - ses_qp], sm, list);
Lck_Unlock(&ses_mem_mtx);
}
SES_ClearReqBodyCache(sp);
/* Update statistics */
Lck_Lock(&stat_mtx);
if (sm == NULL)
VSC_C_main->n_sess_mem--;
n_sess_rel++;
VSC_C_main->n_sess = n_sess_grab - n_sess_rel;
Lck_Unlock(&stat_mtx);
/* Try to precreate some ses-mem so the acceptor will not have to */
if (VSC_C_main->n_sess_mem < VSC_C_main->n_sess + 10) {
sm = ses_sm_alloc();
if (sm != NULL) {
ses_setup(sm);
Lck_Lock(&ses_mem_mtx);
VTAILQ_INSERT_HEAD(&ses_free_mem[1 - ses_qp], sm, list);
Lck_Unlock(&ses_mem_mtx);
}
}
}
示例4: Pool_Task_Arg
int
Pool_Task_Arg(struct worker *wrk, task_func_t *func,
const void *arg, size_t arg_len)
{
struct pool *pp;
struct worker *wrk2;
int retval;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
AN(arg);
AN(arg_len);
pp = wrk->pool;
CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
Lck_Lock(&pp->mtx);
wrk2 = pool_getidleworker(pp);
if (wrk2 != NULL) {
VTAILQ_REMOVE(&pp->idle_queue, &wrk2->task, list);
retval = 1;
} else {
wrk2 = wrk;
retval = 0;
}
Lck_Unlock(&pp->mtx);
AZ(wrk2->task.func);
assert(arg_len <= WS_Reserve(wrk2->aws, arg_len));
memcpy(wrk2->aws->f, arg, arg_len);
wrk2->task.func = func;
wrk2->task.priv = wrk2->aws->f;
if (retval)
AZ(pthread_cond_signal(&wrk2->cond));
return (retval);
}
示例5: VDI_RecycleFd
void
VDI_RecycleFd(struct vbc **vbp)
{
struct backend *bp;
struct vbc *vc;
AN(vbp);
vc = *vbp;
*vbp = NULL;
CHECK_OBJ_NOTNULL(vc, VBC_MAGIC);
CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC);
assert(vc->fd >= 0);
bp = vc->backend;
VSLb(vc->vsl, SLT_BackendReuse, "%s", bp->display_name);
/* XXX: revisit this hack */
VSL_Flush(vc->vsl, 0);
vc->vsl = NULL;
Lck_Lock(&bp->mtx);
VSC_C_main->backend_recycle++;
VTAILQ_INSERT_HEAD(&bp->connlist, vc, list);
VBE_DropRefLocked(bp);
}
示例6: ban_cleantail
static void
ban_cleantail(void)
{
struct ban *b;
do {
Lck_Lock(&ban_mtx);
b = VTAILQ_LAST(&ban_head, banhead_s);
if (b != VTAILQ_FIRST(&ban_head) && b->refcount == 0) {
if (b->flags & BANS_FLAG_COMPLETED)
VSC_C_main->bans_completed--;
if (b->flags & BANS_FLAG_OBJ)
VSC_C_main->bans_obj--;
if (b->flags & BANS_FLAG_REQ)
VSC_C_main->bans_req--;
VSC_C_main->bans--;
VSC_C_main->bans_deleted++;
VTAILQ_REMOVE(&ban_head, b, list);
VSC_C_main->bans_persisted_fragmentation +=
ban_len(b->spec);
ban_info(BI_DROP, b->spec, ban_len(b->spec));
} else {
b = NULL;
}
Lck_Unlock(&ban_mtx);
if (b != NULL)
BAN_Free(b);
} while (b != NULL);
}
示例7: ban_lurker
ban_lurker(struct worker *wrk, void *priv)
{
struct vsl_log vsl;
volatile double d;
unsigned gen = ban_generation + 1;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
AZ(priv);
VSL_Setup(&vsl, NULL, 0);
while (!ban_shutdown) {
d = ban_lurker_work(wrk, &vsl);
ban_cleantail();
if (DO_DEBUG(DBG_LURKER))
VSLb(&vsl, SLT_Debug, "lurker: sleep = %lf", d);
d += VTIM_real();
Lck_Lock(&ban_mtx);
if (gen == ban_generation) {
(void)Lck_CondWait(&ban_lurker_cond, &ban_mtx, d);
ban_batch = 0;
}
gen = ban_generation;
Lck_Unlock(&ban_mtx);
}
pthread_exit(0);
NEEDLESS_RETURN(NULL);
}
示例8: VFP_GetStorage
struct storage *
VFP_GetStorage(struct busyobj *bo, ssize_t sz)
{
ssize_t l;
struct storage *st;
struct object *obj;
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
obj = bo->fetch_obj;
CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC);
st = VTAILQ_LAST(&obj->store, storagehead);
if (st != NULL && st->len < st->space)
return (st);
AN(bo->stats);
l = fetchfrag;
if (l == 0)
l = sz;
if (l == 0)
l = cache_param->fetch_chunksize;
st = STV_alloc(bo, l);
if (st == NULL) {
(void)VFP_Error(bo, "Could not get storage");
} else {
AZ(st->len);
Lck_Lock(&bo->mtx);
VTAILQ_INSERT_TAIL(&obj->store, st, list);
Lck_Unlock(&bo->mtx);
}
return (st);
}
示例9: VDI_RecycleFd
void
VDI_RecycleFd(struct worker *wrk, struct vbc **vbp)
{
struct backend *bp;
struct vbc *vc;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
AN(vbp);
vc = *vbp;
*vbp = NULL;
CHECK_OBJ_NOTNULL(vc, VBC_MAGIC);
CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC);
assert(vc->fd >= 0);
bp = vc->backend;
WSL(wrk, SLT_BackendReuse, vc->vsl_id, "%s", bp->display_name);
/*
* Flush the shmlog, so that another session reusing this backend
* will log chronologically later than our use of it.
*/
WSL_Flush(wrk, 0);
Lck_Lock(&bp->mtx);
VSC_C_main->backend_recycle++;
VTAILQ_INSERT_HEAD(&bp->connlist, vc, list);
VBE_DropRefLocked(bp);
}
示例10: MPL_Free
void
MPL_Free(struct mempool *mpl, void *item)
{
struct memitem *mi;
CHECK_OBJ_NOTNULL(mpl, MEMPOOL_MAGIC);
AN(item);
mi = (void*)((uintptr_t)item - sizeof(*mi));
CHECK_OBJ_NOTNULL(mi, MEMITEM_MAGIC);
memset(item, 0, mi->size);
Lck_Lock(&mpl->mtx);
mpl->vsc->frees++;
mpl->vsc->live = --mpl->live;
if (mi->size < *mpl->cur_size) {
mpl->vsc->toosmall++;
VTAILQ_INSERT_HEAD(&mpl->surplus, mi, list);
} else {
mpl->vsc->pool = ++mpl->n_pool;
mi->touched = mpl->t_now;
VTAILQ_INSERT_HEAD(&mpl->list, mi, list);
}
Lck_Unlock(&mpl->mtx);
}
示例11: smu_alloc
static struct storage *
smu_alloc(const struct stevedore *st, size_t size)
{
struct smu *smu;
Lck_Lock(&smu_mtx);
VSC_C_main->sma_nreq++;
if (VSC_C_main->sma_nbytes + size > smu_max)
size = 0;
else {
VSC_C_main->sma_nobj++;
VSC_C_main->sma_nbytes += size;
VSC_C_main->sma_balloc += size;
}
Lck_Unlock(&smu_mtx);
if (size == 0)
return (NULL);
smu = umem_zalloc(sizeof *smu, UMEM_DEFAULT);
if (smu == NULL)
return (NULL);
smu->sz = size;
smu->s.priv = smu;
smu->s.ptr = umem_alloc(size, UMEM_DEFAULT);
XXXAN(smu->s.ptr);
smu->s.len = 0;
smu->s.space = size;
smu->s.fd = -1;
smu->s.stevedore = st;
smu->s.magic = STORAGE_MAGIC;
return (&smu->s);
}
示例12: EXP_Insert
void
EXP_Insert(struct object *o)
{
struct objcore *oc;
struct objcore_head *lru;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
AN(o->objhead);
AN(ObjIsBusy(o));
assert(o->cacheable);
HSH_Ref(o);
CHECK_OBJ_NOTNULL(o->objcore, OBJCORE_MAGIC);
oc = o->objcore;
assert(o->entered != 0 && !isnan(o->entered));
o->last_lru = o->entered;
Lck_Lock(&exp_mtx);
assert(oc->timer_idx == BINHEAP_NOIDX);
(void)update_object_when(o);
binheap_insert(exp_heap, oc);
assert(oc->timer_idx != BINHEAP_NOIDX);
lru = STV_lru(o->objstore);
if (lru != NULL) {
VTAILQ_INSERT_TAIL(lru, oc, lru_list);
oc->flags |= OC_F_ONLRU;
}
Lck_Unlock(&exp_mtx);
if (o->smp_object != NULL)
SMP_TTLchanged(o);
}
示例13: VRT_DelDirector
void
VRT_DelDirector(VCL_BACKEND *bp)
{
struct vcl *vcl;
struct vcldir *vdir;
VCL_BACKEND d;
TAKE_OBJ_NOTNULL(d, bp, DIRECTOR_MAGIC);
vdir = d->vdir;
CHECK_OBJ_NOTNULL(vdir, VCLDIR_MAGIC);
vcl = vdir->vcl;
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
Lck_Lock(&vcl_mtx);
VTAILQ_REMOVE(&vcl->director_list, vdir, list);
Lck_Unlock(&vcl_mtx);
AZ(errno=pthread_rwlock_rdlock(&vcl->temp_rwl));
if (VCL_WARM(vcl))
VDI_Event(d, VCL_EVENT_COLD);
AZ(errno=pthread_rwlock_unlock(&vcl->temp_rwl));
if(vdir->methods->destroy != NULL)
vdir->methods->destroy(d);
free(vdir->cli_name);
FREE_OBJ(vdir->dir);
FREE_OBJ(vdir);
}
示例14: vbp_has_poked
static void
vbp_has_poked(struct vbp_target *vt)
{
unsigned i, j;
uint64_t u;
const char *logmsg;
char bits[10];
CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC);
/* Calculate exponential average */
if (vt->happy & 1) {
if (vt->rate < AVG_RATE)
vt->rate += 1.0;
vt->avg += (vt->last - vt->avg) / vt->rate;
}
i = 0;
#define BITMAP(n, c, t, b) bits[i++] = (vt->n & 1) ? c : '-';
#include "tbl/backend_poll.h"
#undef BITMAP
bits[i] = '\0';
u = vt->happy;
for (i = j = 0; i < vt->probe.window; i++) {
if (u & 1)
j++;
u >>= 1;
}
vt->good = j;
Lck_Lock(&vt->mtx);
if (vt->backend != NULL) {
if (vt->good >= vt->probe.threshold) {
if (vt->backend->healthy)
logmsg = "Still healthy";
else {
logmsg = "Back healthy";
vt->backend->health_changed = VTIM_real();
}
vt->backend->healthy = 1;
} else {
if (vt->backend->healthy) {
logmsg = "Went sick";
vt->backend->health_changed = VTIM_real();
} else
logmsg = "Still sick";
vt->backend->healthy = 0;
}
VSL(SLT_Backend_health, 0, "%s %s %s %u %u %u %.6f %.6f %s",
vt->backend->display_name, logmsg, bits,
vt->good, vt->probe.threshold, vt->probe.window,
vt->last, vt->avg, vt->resp_buf);
if (!vt->disable) {
AN(vt->backend->vsc);
vt->backend->vsc->happy = vt->happy;
}
}
Lck_Unlock(&vt->mtx);
}
示例15: VRT_rel_vcl
void
VRT_rel_vcl(VRT_CTX, struct vclref **refp)
{
struct vcl *vcl;
struct vclref *ref;
AN(refp);
ref = *refp;
*refp = NULL;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ref, VCLREF_MAGIC);
vcl = ctx->vcl;
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
assert(vcl == ref->vcl);
/* NB: A VCL may be released by a VMOD at any time, but it must happen
* after a warmup and before the end of a cooldown. The release may or
* may not happen while the same thread holds the temperature lock, so
* instead we check that all references are gone in VCL_Nuke.
*/
Lck_Lock(&vcl_mtx);
assert(!VTAILQ_EMPTY(&vcl->ref_list));
VTAILQ_REMOVE(&vcl->ref_list, ref, list);
vcl->nrefs--;
/* No garbage collection here, for the same reasons as in VCL_Rel. */
Lck_Unlock(&vcl_mtx);
FREE_OBJ(ref);
}