当前位置: 首页>>代码示例>>C++>>正文


C++ SpinLockRelease函数代码示例

本文整理汇总了C++中SpinLockRelease函数的典型用法代码示例。如果您正苦于以下问题:C++ SpinLockRelease函数的具体用法?C++ SpinLockRelease怎么用?C++ SpinLockRelease使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SpinLockRelease函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ConditionVariableSignal

/*
 * Wake up the oldest process sleeping on the CV, if there is any.
 *
 * Note: it's difficult to tell whether this has any real effect: we know
 * whether we took an entry off the list, but the entry might only be a
 * sentinel.  Hence, think twice before proposing that this should return
 * a flag telling whether it woke somebody.
 */
void
ConditionVariableSignal(ConditionVariable *cv)
{
	PGPROC	   *proc = NULL;

	/* Remove the first process from the wakeup queue (if any). */
	SpinLockAcquire(&cv->mutex);
	if (!proclist_is_empty(&cv->wakeup))
		proc = proclist_pop_head_node(&cv->wakeup, cvWaitLink);
	SpinLockRelease(&cv->mutex);

	/* If we found someone sleeping, set their latch to wake them up. */
	if (proc != NULL)
		SetLatch(&proc->procLatch);
}
开发者ID:MasahikoSawada,项目名称:postgresql,代码行数:23,代码来源:condition_variable.c

示例2: SubscribeTerminate

void
SubscribeTerminate()
{
	LIST_ITEM *pTrapReferenceListItem;

	_DBG_ENTER_LVL(_DBG_LVL_FUNC_TRACE, SubscribeTerminate);

	SpinLockAcquire(&SubscribedTrapsListLock);
	SubscribeInitialized = 0;
	SpinLockRelease(&SubscribedTrapsListLock);

	iba_sd_deregister(SdClientHandle);

	/* no more SD callbacks will occur now, so OPQUEUED is not important */
	SpinLockAcquire(&SubscribedTrapsListLock);
	while ( NULL != (pTrapReferenceListItem = QListRemoveHead(&SubscribedTrapsList)))
	{
		TRAP_REFERENCE *pTrapReference = (TRAP_REFERENCE *)QListObj(pTrapReferenceListItem);

		ASSERT(pTrapReference != NULL);
		TimerStop(&pTrapReference->Timer);
		// release lock so TimerDestroy can wait for callback
		SpinLockRelease(&SubscribedTrapsListLock);
		TimerDestroy(&pTrapReference->Timer);

		MemoryDeallocate(pTrapReference);

		SpinLockAcquire(&SubscribedTrapsListLock);
	}
	SpinLockRelease(&SubscribedTrapsListLock);

	QListDestroy(&SubscribedTrapsList);
	SpinLockDestroy(&SubscribedTrapsListLock);

	_DBG_LEAVE_LVL( _DBG_LVL_FUNC_TRACE );
}
开发者ID:01org,项目名称:opa-ff,代码行数:36,代码来源:subscribe.c

示例3: shm_mq_set_receiver

/*
 * Set the identity of the process that will receive from a shared message
 * queue.
 */
void
shm_mq_set_receiver(shm_mq *mq, PGPROC *proc)
{
	volatile shm_mq *vmq = mq;
	PGPROC	   *sender;

	SpinLockAcquire(&mq->mq_mutex);
	Assert(vmq->mq_receiver == NULL);
	vmq->mq_receiver = proc;
	sender = vmq->mq_sender;
	SpinLockRelease(&mq->mq_mutex);

	if (sender != NULL)
		SetLatch(&sender->procLatch);
}
开发者ID:CrocdileChan,项目名称:postgres,代码行数:19,代码来源:shm_mq.c

示例4: GetWalRcvWriteRecPtr

/*
 * Returns the last+1 byte position that walreceiver has written.
 *
 * Optionally, returns the previous chunk start, that is the first byte
 * written in the most recent walreceiver flush cycle.	Callers not
 * interested in that value may pass NULL for latestChunkStart.
 */
XLogRecPtr
GetWalRcvWriteRecPtr(XLogRecPtr *latestChunkStart)
{
	/* use volatile pointer to prevent code rearrangement */
	volatile WalRcvData *walrcv = WalRcv;
	XLogRecPtr	recptr;

	SpinLockAcquire(&walrcv->mutex);
	recptr = walrcv->receivedUpto;
	if (latestChunkStart)
		*latestChunkStart = walrcv->latestChunkStart;
	SpinLockRelease(&walrcv->mutex);

	return recptr;
}
开发者ID:HunterChen,项目名称:postgres-xc,代码行数:22,代码来源:walreceiverfuncs.c

示例5: ReplicationSlotPersist

/*
 * Convert a slot that's marked as RS_EPHEMERAL to a RS_PERSISTENT slot,
 * guaranteeing it will be there after an eventual crash.
 */
void
ReplicationSlotPersist(void)
{
	ReplicationSlot *slot = MyReplicationSlot;

	Assert(slot != NULL);
	Assert(slot->data.persistency != RS_PERSISTENT);

	SpinLockAcquire(&slot->mutex);
	slot->data.persistency = RS_PERSISTENT;
	SpinLockRelease(&slot->mutex);

	ReplicationSlotMarkDirty();
	ReplicationSlotSave();
}
开发者ID:davidfetter,项目名称:postgresql_projects,代码行数:19,代码来源:slot.c

示例6: ConditionVariableCancelSleep

/*
 * Cancel any pending sleep operation.
 *
 * We just need to remove ourselves from the wait queue of any condition
 * variable for which we have previously prepared a sleep.
 *
 * Do nothing if nothing is pending; this allows this function to be called
 * during transaction abort to clean up any unfinished CV sleep.
 */
void
ConditionVariableCancelSleep(void)
{
	ConditionVariable *cv = cv_sleep_target;

	if (cv == NULL)
		return;

	SpinLockAcquire(&cv->mutex);
	if (proclist_contains(&cv->wakeup, MyProc->pgprocno, cvWaitLink))
		proclist_delete(&cv->wakeup, MyProc->pgprocno, cvWaitLink);
	SpinLockRelease(&cv->mutex);

	cv_sleep_target = NULL;
}
开发者ID:MasahikoSawada,项目名称:postgresql,代码行数:24,代码来源:condition_variable.c

示例7: LWLockWaitCancel

/*
 * LWLockWaitCancel - cancel currently waiting on LW lock
 *
 * Used to clean up before immediate exit in certain very special situations
 * like shutdown request to Filerep Resync Manger or Workers. Although this is
 * not the best practice it is necessary to avoid any starvation situations
 * during filerep transition situations (Resync Mode -> Changetracking mode)
 *
 * Note:- This function should not be used for normal situations. It is strictly
 * written for very special situations. If you need to use this, you may want
 * to re-think your design.
 */
void
LWLockWaitCancel(void)
{
	volatile PGPROC *proc = MyProc;
	volatile LWLock *lwWaitingLock = NULL;

	/* We better have a PGPROC structure */
	Assert(proc != NULL);

	/* If we're not waiting on any LWLock then nothing doing here */
	if (!proc->lwWaiting)
		return;

	lwWaitingLock = &(LWLockArray[lwWaitingLockId].lock);

	/* Protect from other modifiers */
	SpinLockAcquire(&lwWaitingLock->mutex);

	PGPROC *currProc = lwWaitingLock->head;

	/* Search our PROC in the waiters list and remove it */
	if (proc == lwWaitingLock->head)
	{
		lwWaitingLock->head = currProc = proc->lwWaitLink;
		proc->lwWaitLink = NULL;
	}
	else
	{
		while(currProc != NULL)
		{
			if (currProc->lwWaitLink == proc)
			{
				currProc->lwWaitLink = proc->lwWaitLink;
				proc->lwWaitLink = NULL;
				break;
			}
			currProc = currProc->lwWaitLink;
		}
	}

	if (lwWaitingLock->tail == proc)
		lwWaitingLock->tail = currProc;

	/* Done with modification */
	SpinLockRelease(&lwWaitingLock->mutex);

	return;
}
开发者ID:50wu,项目名称:gpdb,代码行数:60,代码来源:lwlock.c

示例8: ShmemAlloc

/*
 * ShmemAlloc -- allocate max-aligned chunk from shared memory
 *
 * Assumes ShmemLock and ShmemSegHdr are initialized.
 *
 * Returns: real pointer to memory or NULL if we are out
 *		of space.  Has to return a real pointer in order
 *		to be compatible with malloc().
 */
void *
ShmemAlloc(Size size)
{
    Size		newStart;
    Size		newFree;
    void	   *newSpace;

    /*
     * Ensure all space is adequately aligned.  We used to only MAXALIGN this
     * space but experience has proved that on modern systems that is not good
     * enough.  Many parts of the system are very sensitive to critical data
     * structures getting split across cache line boundaries.  To avoid that,
     * attempt to align the beginning of the allocation to a cache line
     * boundary.  The calling code will still need to be careful about how it
     * uses the allocated space - e.g. by padding each element in an array of
     * structures out to a power-of-two size - but without this, even that
     * won't be sufficient.
     */
    size = CACHELINEALIGN(size);

    Assert(ShmemSegHdr != NULL);

    SpinLockAcquire(ShmemLock);

    newStart = ShmemSegHdr->freeoffset;

    /* extra alignment for large requests, since they are probably buffers */
    if (size >= BLCKSZ)
        newStart = BUFFERALIGN(newStart);

    newFree = newStart + size;
    if (newFree <= ShmemSegHdr->totalsize)
    {
        newSpace = (void *) ((char *) ShmemBase + newStart);
        ShmemSegHdr->freeoffset = newFree;
    }
    else
        newSpace = NULL;

    SpinLockRelease(ShmemLock);

    if (!newSpace)
        ereport(WARNING,
                (errcode(ERRCODE_OUT_OF_MEMORY),
                 errmsg("out of shared memory")));

    return newSpace;
}
开发者ID:MohammadHabbab,项目名称:postgres,代码行数:57,代码来源:shmem.c

示例9: ReplicationSlotsComputeRequiredXmin

/*
 * Compute the oldest xmin across all slots and store it in the ProcArray.
 */
void
ReplicationSlotsComputeRequiredXmin(bool already_locked)
{
	int			i;
	TransactionId agg_xmin = InvalidTransactionId;
	TransactionId agg_catalog_xmin = InvalidTransactionId;

	Assert(ReplicationSlotCtl != NULL);

	if (!already_locked)
		LWLockAcquire(ReplicationSlotControlLock, LW_SHARED);

	for (i = 0; i < max_replication_slots; i++)
	{
		ReplicationSlot *s = &ReplicationSlotCtl->replication_slots[i];
		TransactionId effective_xmin;
		TransactionId effective_catalog_xmin;

		if (!s->in_use)
			continue;

		{
			volatile ReplicationSlot *vslot = s;

			SpinLockAcquire(&s->mutex);
			effective_xmin = vslot->effective_xmin;
			effective_catalog_xmin = vslot->effective_catalog_xmin;
			SpinLockRelease(&s->mutex);
		}

		/* check the data xmin */
		if (TransactionIdIsValid(effective_xmin) &&
			(!TransactionIdIsValid(agg_xmin) ||
			 TransactionIdPrecedes(effective_xmin, agg_xmin)))
			agg_xmin = effective_xmin;

		/* check the catalog xmin */
		if (TransactionIdIsValid(effective_catalog_xmin) &&
			(!TransactionIdIsValid(agg_catalog_xmin) ||
			 TransactionIdPrecedes(effective_catalog_xmin, agg_catalog_xmin)))
			agg_catalog_xmin = effective_catalog_xmin;
	}

	if (!already_locked)
		LWLockRelease(ReplicationSlotControlLock);

	ProcArraySetReplicationSlotXmin(agg_xmin, agg_catalog_xmin, already_locked);
}
开发者ID:dileep315,项目名称:postgres,代码行数:51,代码来源:slot.c

示例10: ReplicationSlotRelease

/*
 * Release a replication slot, this or another backend can ReAcquire it
 * later. Resources this slot requires will be preserved.
 */
void
ReplicationSlotRelease(void)
{
	ReplicationSlot *slot = MyReplicationSlot;

	Assert(slot != NULL && slot->active);

	/* Mark slot inactive.  We're not freeing it, just disconnecting. */
	{
		volatile ReplicationSlot *vslot = slot;
		SpinLockAcquire(&slot->mutex);
		vslot->active = false;
		SpinLockRelease(&slot->mutex);
		MyReplicationSlot = NULL;
	}
}
开发者ID:AlexHill,项目名称:postgres,代码行数:20,代码来源:slot.c

示例11: GetWalRcvWriteRecPtr

/*
 * Returns the last+1 byte position that walreceiver has written.
 *
 * Optionally, returns the previous chunk start, that is the first byte
 * written in the most recent walreceiver flush cycle.  Callers not
 * interested in that value may pass NULL for latestChunkStart. Same for
 * receiveTLI.
 */
XLogRecPtr
GetWalRcvWriteRecPtr(XLogRecPtr *latestChunkStart, TimeLineID *receiveTLI)
{
	WalRcvData *walrcv = WalRcv;
	XLogRecPtr	recptr;

	SpinLockAcquire(&walrcv->mutex);
	recptr = walrcv->receivedUpto;
	if (latestChunkStart)
		*latestChunkStart = walrcv->latestChunkStart;
	if (receiveTLI)
		*receiveTLI = walrcv->receivedTLI;
	SpinLockRelease(&walrcv->mutex);

	return recptr;
}
开发者ID:winlibs,项目名称:postgresql,代码行数:24,代码来源:walreceiverfuncs.c

示例12: ProcessTrapSubscribeResponse

// callback when SA query completes or fails
static void
ProcessTrapSubscribeResponse(void* Context, FABRIC_OPERATION_DATA* pFabOp, FSTATUS Status, uint32 MadStatus)
{
	TRAP_REFERENCE *pTrapReference = (TRAP_REFERENCE *)Context;

	_DBG_ENTER_LVL(_DBG_LVL_FUNC_TRACE, ProcessTrapSubscribeResponse);
	
	SpinLockAcquire(&SubscribedTrapsListLock);
	if (SubscribeInitialized == 0)
		goto unlock;	// we are shutting down, don't start anything new

	pTrapReference->Flags = (TRAP_REFERENCE_FLAGS)(pTrapReference->Flags & ~TRAP_REF_FLAGS_OPQUEUED);
	if (Status != FSUCCESS)
	{
		// our attempt failed
		if (pFabOp->Value.InformInfo.Subscribe == 0)
		{
			_DBG_WARN( ("Trap Unsubscribe Failure. Status = %s, MadStatus = 0x%x: %s.\n", 
                        _DBG_PTR(iba_fstatus_msg(Status)), MadStatus, _DBG_PTR(iba_sd_mad_status_msg(MadStatus))) );
		} else {
			_DBG_WARN( ("Trap Subscribe Failure. Status = %s, MadStatus = 0x%x: %s.\n", 
                        _DBG_PTR(iba_fstatus_msg(Status)), MadStatus, _DBG_PTR(iba_sd_mad_status_msg(MadStatus))) );
		}
		// delay any retry or adjustment so we don't beat on SA too hard
		if (MadStatus == MAD_STATUS_BUSY)
		{
			ProcessTrapStateChange(pTrapReference, (SystemGetRandom() % PORT_DOWN_DELAY));
			_DBG_PRINT(_DBG_LVL_INFO, ("SM Returned Busy. Delaying Subscription By %ld MS.\n", (SystemGetRandom() % PORT_DOWN_DELAY)));
		} else {
			ProcessTrapStateChange(pTrapReference, RETRY_DELAY);
		}
	} else {
		if (pFabOp->Value.InformInfo.Subscribe == 1)
		{
			/* We are now subscribed with the SA */
			pTrapReference->Flags = (TRAP_REFERENCE_FLAGS)(pTrapReference->Flags | TRAP_REF_FLAGS_SUBSCRIBED);
		} else {
			/* We are now completely unsubscribed from the SA */
			// flag was cleared when we issued unsubscribe request
		}
		ProcessTrapStateChange(pTrapReference, 0);
	}
unlock:
	SpinLockRelease(&SubscribedTrapsListLock);

	_DBG_LEAVE_LVL( _DBG_LVL_FUNC_TRACE );
}
开发者ID:01org,项目名称:opa-ff,代码行数:48,代码来源:subscribe.c

示例13: ConditionVariablePrepareToSleep

/*
 * Prepare to wait on a given condition variable.
 *
 * This can optionally be called before entering a test/sleep loop.
 * Doing so is more efficient if we'll need to sleep at least once.
 * However, if the first test of the exit condition is likely to succeed,
 * it's more efficient to omit the ConditionVariablePrepareToSleep call.
 * See comments in ConditionVariableSleep for more detail.
 *
 * Caution: "before entering the loop" means you *must* test the exit
 * condition between calling ConditionVariablePrepareToSleep and calling
 * ConditionVariableSleep.  If that is inconvenient, omit calling
 * ConditionVariablePrepareToSleep.
 */
void
ConditionVariablePrepareToSleep(ConditionVariable *cv)
{
	int			pgprocno = MyProc->pgprocno;

	/*
	 * If first time through in this process, create a WaitEventSet, which
	 * we'll reuse for all condition variable sleeps.
	 */
	if (cv_wait_event_set == NULL)
	{
		WaitEventSet *new_event_set;

		new_event_set = CreateWaitEventSet(TopMemoryContext, 2);
		AddWaitEventToSet(new_event_set, WL_LATCH_SET, PGINVALID_SOCKET,
						  MyLatch, NULL);
		AddWaitEventToSet(new_event_set, WL_EXIT_ON_PM_DEATH, PGINVALID_SOCKET,
						  NULL, NULL);
		/* Don't set cv_wait_event_set until we have a correct WES. */
		cv_wait_event_set = new_event_set;
	}

	/*
	 * If some other sleep is already prepared, cancel it; this is necessary
	 * because we have just one static variable tracking the prepared sleep,
	 * and also only one cvWaitLink in our PGPROC.  It's okay to do this
	 * because whenever control does return to the other test-and-sleep loop,
	 * its ConditionVariableSleep call will just re-establish that sleep as
	 * the prepared one.
	 */
	if (cv_sleep_target != NULL)
		ConditionVariableCancelSleep();

	/* Record the condition variable on which we will sleep. */
	cv_sleep_target = cv;

	/*
	 * Reset my latch before adding myself to the queue, to ensure that we
	 * don't miss a wakeup that occurs immediately.
	 */
	ResetLatch(MyLatch);

	/* Add myself to the wait queue. */
	SpinLockAcquire(&cv->mutex);
	proclist_push_tail(&cv->wakeup, pgprocno, cvWaitLink);
	SpinLockRelease(&cv->mutex);
}
开发者ID:MasahikoSawada,项目名称:postgresql,代码行数:61,代码来源:condition_variable.c

示例14: StrategySyncStart

/*
 * StrategySyncStart -- tell BufferSync where to start syncing
 *
 * The result is the buffer index of the best buffer to sync first.
 * BufferSync() will proceed circularly around the buffer array from there.
 *
 * In addition, we return the completed-pass count (which is effectively
 * the higher-order bits of nextVictimBuffer) and the count of recent buffer
 * allocs if non-NULL pointers are passed.  The alloc count is reset after
 * being read.
 */
int
StrategySyncStart(uint32 *complete_passes, uint32 *num_buf_alloc)
{
	int			result;

	SpinLockAcquire(&StrategyControl->buffer_strategy_lock);
	result = StrategyControl->nextVictimBuffer;
	if (complete_passes)
		*complete_passes = StrategyControl->completePasses;
	if (num_buf_alloc)
	{
		*num_buf_alloc = StrategyControl->numBufferAllocs;
		StrategyControl->numBufferAllocs = 0;
	}
	SpinLockRelease(&StrategyControl->buffer_strategy_lock);
	return result;
}
开发者ID:Orion7,项目名称:postgres,代码行数:28,代码来源:freelist.c

示例15: UnSetDistributedTransactionId

/*
 * UnSetDistributedTransactionId simply acquires the mutex and resets the backend's
 * distributed transaction data in shared memory to the initial values.
 */
void
UnSetDistributedTransactionId(void)
{
	/* backend does not exist if the extension is not created */
	if (MyBackendData)
	{
		SpinLockAcquire(&MyBackendData->mutex);

		MyBackendData->databaseId = 0;
		MyBackendData->transactionId.initiatorNodeIdentifier = 0;
		MyBackendData->transactionId.transactionOriginator = false;
		MyBackendData->transactionId.transactionNumber = 0;
		MyBackendData->transactionId.timestamp = 0;

		SpinLockRelease(&MyBackendData->mutex);
	}
}
开发者ID:dreamsxin,项目名称:citus,代码行数:21,代码来源:backend_data.c


注:本文中的SpinLockRelease函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。