本文整理汇总了C++中InterlockedExchange函数的典型用法代码示例。如果您正苦于以下问题:C++ InterlockedExchange函数的具体用法?C++ InterlockedExchange怎么用?C++ InterlockedExchange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了InterlockedExchange函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clip
/// <summary>
/// processes incoming image
/// </summary>
/// <returns>error code, refer to AL_XXX codes</returns>
/// <remarks>
/// working parallel code with single loop, using active waits to protect data dependencies
/// [Filter processing of full resolution image] in [1.131 seconds]
/// </remarks>
int CParallelActiveWaitAltaLuxFilter::Run()
{
if (ClipLimit == 1.0)
return AL_OK; //< is OK, immediately returns original image
PixelType *pImage = (PixelType *)ImageBuffer;
/// pulMapArray is pointer to mappings
unsigned int *pulMapArray = new unsigned int[NumHorRegions * NumVertRegions * NUM_GRAY_LEVELS];
if (pulMapArray == 0)
return AL_OUT_OF_MEMORY; //< not enough memory
/// region pixel count
unsigned int NumPixels = (unsigned int)RegionWidth * (unsigned int)RegionHeight; //< region pixel count
unsigned int ulClipLimit; //< clip limit
if (ClipLimit > 0.0)
{
/// calculate actual cliplimit
ulClipLimit = (unsigned int) (ClipLimit * (RegionWidth * RegionHeight) / NUM_GRAY_LEVELS);
ulClipLimit = (ulClipLimit < 1UL) ? 1UL : ulClipLimit;
}
else
ulClipLimit = 1UL<<14; //< large value, do not clip (AHE)
/// Interpolate greylevel mappings to get CLAHE image
// create events for signaling that the first phase is completed
__declspec(align(32)) volatile LONG FirstPhaseCompleted[MAX_VERT_REGIONS+1];
for (int i = 0; i <= NumVertRegions; i++)
InterlockedExchange((volatile LONG*)&FirstPhaseCompleted[i], -1);
concurrency::parallel_for((LONG)0, (LONG)(NumVertRegions + 1), [&](LONG uiY)
{
// first half
PixelType* pImPointer = pImage;
if (uiY > 0)
pImPointer += ((RegionHeight >> 1) + ((uiY - 1) * RegionHeight)) * OriginalImageWidth;
if (uiY < NumVertRegions)
{
/// calculate greylevel mappings for each contextual region
for (LONG uiX = 0; uiX < NumHorRegions; uiX++, pImPointer += RegionWidth)
{
unsigned int *pHistogram = &pulMapArray[NUM_GRAY_LEVELS * (uiY * NumHorRegions + uiX)];
MakeHistogram(pImPointer, pHistogram);
ClipHistogram(pHistogram, ulClipLimit);
MapHistogram(pHistogram, NumPixels);
InterlockedExchange((volatile LONG*) &FirstPhaseCompleted[uiY], uiX);
}
}
// second half
unsigned int uiSubX, uiSubY; //< size of subimages
unsigned int uiXL, uiXR, uiYU, uiYB; //< auxiliary variables interpolation routine
pImPointer = pImage;
if (uiY > 0)
pImPointer += ((RegionHeight >> 1) + ((uiY - 1) * RegionHeight)) * OriginalImageWidth;
if (uiY == 0)
{
/// special case: top row
uiSubY = RegionHeight >> 1;
uiYU = 0;
uiYB = 0;
} else {
示例2: DCamSurpriseRemoval
//.........这里部分代码省略.........
Return Value:
None.
--*/
{
PIRP pIrp;
PIRB pIrb;
PDCAM_EXTENSION pDevExt;
PSTREAMEX pStrmEx;
NTSTATUS Status;
PAGED_CODE();
pIrb = (PIRB) pSrb->SRBExtension;
ASSERT(pIrb);
pDevExt = (PDCAM_EXTENSION) pSrb->HwDeviceExtension;
ASSERT(pDevExt);
//
// Set this to stop accepting incoming read.
//
pDevExt->bDevRemoved = TRUE;
//
// Wait until all pending work items are completed!
//
KeWaitForSingleObject( &pDevExt->PendingWorkItemEvent, Executive, KernelMode, FALSE, NULL );
//
// Wait for currect read to be attached so we cancel them all.
//
pStrmEx = pDevExt->pStrmEx;
if(pStrmEx) {
// Make sure that this structure is still valid.
if(pStrmEx->pVideoInfoHeader) {
KeWaitForSingleObject( &pStrmEx->hMutex, Executive, KernelMode, FALSE, 0 );
KeReleaseMutex(&pStrmEx->hMutex, FALSE);
}
}
pIrp = IoAllocateIrp(pDevExt->BusDeviceObject->StackSize, FALSE);
if(!pIrp) {
ERROR_LOG(("DCamSurpriseRemovalPacket: faile to get resource; pIrb=%p, pDevExt=%p, pIrp\n", pIrb, pDevExt));
pSrb->Status = STATUS_INSUFFICIENT_RESOURCES;
StreamClassDeviceNotification(DeviceRequestComplete, pSrb->HwDeviceExtension, pSrb);
return;
}
//
// un-register a bus reset callback notification
//
pIrb->FunctionNumber = REQUEST_BUS_RESET_NOTIFICATION;
pIrb->Flags = 0;
pIrb->u.BusResetNotification.fulFlags = DEREGISTER_NOTIFICATION_ROUTINE;
pIrb->u.BusResetNotification.ResetRoutine = (PBUS_BUS_RESET_NOTIFICATION) DCamBusResetNotification;
pIrb->u.BusResetNotification.ResetContext = 0;
Status = DCamSubmitIrpSynch(pDevExt, pIrp, pIrb);
if(Status) {
ERROR_LOG(("DCamSurpriseRemoval: Status %x while trying to deregister bus reset notification.\n", Status));
}
if(pStrmEx && pStrmEx->pVideoInfoHeader) {
//
// Stop isoch transmission so we can detach buffers and cancel pending SRBs
//
pIrb->FunctionNumber = REQUEST_ISOCH_STOP;
pIrb->Flags = 0;
pIrb->u.IsochStop.hResource = pDevExt->hResource;
pIrb->u.IsochStop.fulFlags = 0;
Status = DCamSubmitIrpSynch(pDevExt, pIrp, pIrb);
if(Status) {
ERROR_LOG(("DCamSurpriseRemoval: Status %x while trying to ISOCH_STOP.\n", Status));
}
IoFreeIrp(pIrp);
if( InterlockedExchange((PLONG)&pStrmEx->CancelToken, 1 ) == 0 ) {
DCamCancelAllPackets(
pDevExt,
&pDevExt->PendingReadCount );
}
COMPLETE_SRB( pSrb );
} else {
IoFreeIrp(pIrp);
StreamClassDeviceNotification(DeviceRequestComplete, pSrb->HwDeviceExtension, pSrb);
}
}
示例3: InterlockedExchange
AtomicCounter& AtomicCounter::operator = (AtomicCounter::ValueType value)
{
InterlockedExchange(&_counter, value);
return *this;
}
示例4: slrelease
/* Release spin lock */
static int slrelease (LOCKLONG *sl)
{
InterlockedExchange ((volatile LONG*)sl, 0);
return 0;
}
示例5: _MANAGER
//.........这里部分代码省略.........
}
if (ModalStackCount)
{
ActivateFrame(ModalStack[ModalStackCount-1]);
}
}
for (int i=0; i<FrameCount; i++)
{
if (FrameList[i]->FrameToBack==DeletedFrame)
{
FrameList[i]->FrameToBack=CtrlObject->Cp();
}
}
int FrameIndex=IndexOf(DeletedFrame);
if (-1!=FrameIndex)
{
DeletedFrame->DestroyAllModal();
for (int j=FrameIndex; j<FrameCount-1; j++)
{
FrameList[j]=FrameList[j+1];
}
FrameCount--;
if (FramePos >= FrameCount)
{
FramePos=0;
}
if (DeletedFrame->FrameToBack==CtrlObject->Cp())
{
ActivateFrame(FrameList[FramePos]);
}
else
{
ActivateFrame(DeletedFrame->FrameToBack);
}
}
/* $ 14.05.2002 SKV
Долго не мог понять, нужен всё же этот код или нет.
Но вроде как нужен.
SVS> Когда понадобится - в некоторых местах расскомментить куски кода
помеченные скобками <ifDoubleInstance>
if (ifDoubI && IsSemiModalBackFrame(ActivatedFrame)){
for(int i=0;i<ModalStackCount;i++)
{
if(ModalStack[i]==ActivatedFrame)
{
break;
}
}
if(i==ModalStackCount)
{
if (ModalStackCount == ModalStackSize){
ModalStack = (Frame **) xf_realloc (ModalStack, ++ModalStackSize * sizeof (Frame *));
}
ModalStack[ModalStackCount++]=ActivatedFrame;
}
}
*/
DeletedFrame->OnDestroy();
if (CurrentFrame==DeletedFrame)
{
CurrentFrame=0;
InterlockedExchange(&CurrentWindowType,-1);
}
if (DeletedFrame->GetDynamicallyBorn())
{
_MANAGER(SysLog(L"delete DeletedFrame %p", DeletedFrame));
/* $ 14.05.2002 SKV
Так как в деструкторе фрэйма неявно может быть
вызван commit, то надо подстраховаться.
*/
Frame *tmp=DeletedFrame;
DeletedFrame=nullptr;
delete tmp;
}
// Полагаемся на то, что в ActevateFrame не будет переписан уже
// присвоенный ActivatedFrame
if (ModalStackCount)
{
ActivateFrame(ModalStack[ModalStackCount-1]);
}
else
{
ActivateFrame(FramePos);
}
}
示例6: LurnRecordFault
//
// Add fault to Lurn fault list for future analysys
//
// ErrorCode is dependent on fault type. It can be custom error code.
//
// Param is Type dependent parameter.
// Param is CCB if / Ccb is valid only for fault type LURN_ERR_IO, LURN_ERR_LOCK
//
NTSTATUS
LurnRecordFault(PLURELATION_NODE Lurn, LURN_FAULT_TYPE Type, UINT32 ErrorCode, PVOID Param)
{
PLURN_FAULT_INFO fInfo = &Lurn->FaultInfo;
LONG count;
LURN_FAULT_TYPE LastFaultType;
LONG LastErrorCode;
PLURN_FAULT_IO pLfi= (PLURN_FAULT_IO) Param;
LastFaultType = fInfo->LastFaultType;
LastErrorCode = fInfo->LastErrorCode[LastFaultType];
//
// To do: Recognize some indirect error patterns.
//
#if 0
//
// Check accesing same range failed.
//
if ((Type == LURN_ERR_READ || Type == LURN_ERR_WRITE || Type == LURN_ERR_VERIFY) && pLfi &&
(ErrorCode == LURN_FAULT_COMMUNICATION)) {
if (fInfo->LastIoOperation) {
//
// Check accesing same range failed and error occured multiple times.
//
if (fInfo->LastIoAddr + fInfo->LastIoLength > pLfi->Address
&& pLfi->Address+pLfi->Length > fInfo->LastIoAddr &&
fInfo->ErrorCount[Type] > 5) {
KDPrintM(NDASSCSI_DBG_LUR_ERROR, ("IO failed on same location. Marking error\n"));
ErrorCode = LURN_FAULT_BAD_SECTOR;
}
} else {
// no previous IO error recorded.
}
}
#endif
//
// to do: handle disk hang after bad sector..
//
//
// Update internal fault record.
//
switch(Type) {
case LURN_ERR_SUCCESS:
count = InterlockedIncrement(&fInfo->ErrorCount[Type]);
if (count == 128) {
KDPrintM(NDASSCSI_DBG_LUR_TRACE, ("Resetting error count\n"));
//
// If some IO operation completed without any error, clear all other errors.
//
LurnResetFaultInfo(Lurn);
InterlockedExchange(&fInfo->ErrorCount[Type], count);
}
break;
case LURN_ERR_CONNECT:
case LURN_ERR_LOGIN:
case LURN_ERR_NDAS_OP:
case LURN_ERR_DISK_OP:
case LURN_ERR_READ:
case LURN_ERR_WRITE:
case LURN_ERR_VERIFY:
case LURN_ERR_UNKNOWN:
case LURN_ERR_FLUSH:
default:
// Error occured. Reset success count
InterlockedExchange(&fInfo->ErrorCount[LURN_ERR_SUCCESS], 0);
InterlockedIncrement(&fInfo->ErrorCount[Type]);
InterlockedExchange(&fInfo->LastErrorCode[Type], ErrorCode);
fInfo->LastFaultType = Type;
KeQuerySystemTime(&fInfo->LastFaultTime);
break;
}
if (Type == LURN_ERR_READ || Type == LURN_ERR_WRITE) {
if (pLfi) {
fInfo->LastIoOperation = Type;
fInfo->LastIoAddr = pLfi->Address;
fInfo->LastIoLength = pLfi->Length;
}
}
//
// Update error causes.
//
//
// Guess error cause. Be cautious when setting error because this can mark a disk as defective permanently.
//
if (Type == LURN_ERR_CONNECT) {
//.........这里部分代码省略.........
示例7: wince_clock_gettime_threaded
/*
* Monotonic and real time functions
*/
unsigned __stdcall wince_clock_gettime_threaded(void* param)
{
LARGE_INTEGER hires_counter, li_frequency;
LONG nb_responses;
int timer_index;
// Init - find out if we have access to a monotonic (hires) timer
if (!QueryPerformanceFrequency(&li_frequency)) {
usbi_dbg("no hires timer available on this platform");
hires_frequency = 0;
hires_ticks_to_ps = UINT64_C(0);
} else {
hires_frequency = li_frequency.QuadPart;
// The hires frequency can go as high as 4 GHz, so we'll use a conversion
// to picoseconds to compute the tv_nsecs part in clock_gettime
hires_ticks_to_ps = UINT64_C(1000000000000) / hires_frequency;
usbi_dbg("hires timer available (Frequency: %"PRIu64" Hz)", hires_frequency);
}
// Signal wince_init() that we're ready to service requests
if (ReleaseSemaphore(timer_response, 1, NULL) == 0) {
usbi_dbg("unable to release timer semaphore: %s", windows_error_str(0));
}
// Main loop - wait for requests
while (1) {
timer_index = WaitForMultipleObjects(2, timer_request, FALSE, INFINITE) - WAIT_OBJECT_0;
if ( (timer_index != 0) && (timer_index != 1) ) {
usbi_dbg("failure to wait on requests: %s", windows_error_str(0));
continue;
}
if (request_count[timer_index] == 0) {
// Request already handled
ResetEvent(timer_request[timer_index]);
// There's still a possiblity that a thread sends a request between the
// time we test request_count[] == 0 and we reset the event, in which case
// the request would be ignored. The simple solution to that is to test
// request_count again and process requests if non zero.
if (request_count[timer_index] == 0)
continue;
}
switch (timer_index) {
case 0:
WaitForSingleObject(timer_mutex, INFINITE);
// Requests to this thread are for hires always
if (QueryPerformanceCounter(&hires_counter) != 0) {
timer_tp.tv_sec = (long)(hires_counter.QuadPart / hires_frequency);
timer_tp.tv_nsec = (long)(((hires_counter.QuadPart % hires_frequency)/1000) * hires_ticks_to_ps);
} else {
// Fallback to real-time if we can't get monotonic value
// Note that real-time clock does not wait on the mutex or this thread.
wince_clock_gettime(USBI_CLOCK_REALTIME, &timer_tp);
}
ReleaseMutex(timer_mutex);
nb_responses = InterlockedExchange((LONG*)&request_count[0], 0);
if ( (nb_responses)
&& (ReleaseSemaphore(timer_response, nb_responses, NULL) == 0) ) {
usbi_dbg("unable to release timer semaphore: %s", windows_error_str(0));
}
continue;
case 1: // time to quit
usbi_dbg("timer thread quitting");
return 0;
}
}
usbi_dbg("ERROR: broken timer thread");
return 1;
}
示例8: while
//.........这里部分代码省略.........
{
hWaitEvents[nEventCount ++] = ::CreateThread(NULL, 0, _WorkerThreadProc, pThis, 0, NULL);
}
// 下面进入无限循环,处理事件对象数组中的事件
while(TRUE)
{
int nIndex = ::WSAWaitForMultipleEvents(nEventCount, hWaitEvents, FALSE, 1000, FALSE);
// 首先检查是否要停止服务
if(pThis->m_bShutDown || nIndex == WSA_WAIT_FAILED)
{
// 关闭所有连接
pThis->CloseAllConnections();
::Sleep(0); // 给I/O工作线程一个执行的机会
// 关闭监听套节字
::closesocket(pThis->m_sListen);
pThis->m_sListen = INVALID_SOCKET;
::Sleep(0); // 给I/O工作线程一个执行的机会
// 通知所有I/O处理线程退出
for(int i=2; i<MAX_THREAD + 2; i++)
{
::PostQueuedCompletionStatus(pThis->m_hCompletion, -1, 0, NULL);
}
// 等待I/O处理线程退出
::WaitForMultipleObjects(MAX_THREAD, &hWaitEvents[2], TRUE, 5*1000);
for(i=2; i<MAX_THREAD + 2; i++)
{
::CloseHandle(hWaitEvents[i]);
}
::CloseHandle(pThis->m_hCompletion);
pThis->FreeBuffers();
pThis->FreeContexts();
::ExitThread(0);
}
// 1)定时检查所有未返回的AcceptEx I/O的连接建立了多长时间
if(nIndex == WSA_WAIT_TIMEOUT)
{
pBuffer = pThis->m_pPendingAccepts;
while(pBuffer != NULL)
{
int nSeconds;
int nLen = sizeof(nSeconds);
// 取得连接建立的时间
::getsockopt(pBuffer->sClient,
SOL_SOCKET, SO_CONNECT_TIME, (char *)&nSeconds, &nLen);
// 如果超过10秒钟客户还不发送初始数据,就让这个客户go away
if(nSeconds != -1 && nSeconds >= 10)
{
closesocket(pBuffer->sClient);
pBuffer->sClient = INVALID_SOCKET;
}
pBuffer = pBuffer->pNext;
}
}
else
{
nIndex = nIndex - WAIT_OBJECT_0;
WSANETWORKEVENTS ne;
int nLimit=0;
if(nIndex == 0) // 2)m_hAcceptEvent事件对象受信,说明投递的Accept请求不够,需要增加
{
::WSAEnumNetworkEvents(pThis->m_sListen, hWaitEvents[nIndex], &ne);
if(ne.lNetworkEvents & FD_ACCEPT)
{
nLimit = 50; // 增加的个数,这里设为50个
}
}
else if(nIndex == 1) // 3)m_hRepostEvent事件对象受信,说明处理I/O的线程接受到新的客户
{
nLimit = InterlockedExchange(&pThis->m_nRepostCount, 0);
}
else if(nIndex > 1) // I/O服务线程退出,说明有错误发生,关闭服务器
{
pThis->m_bShutDown = TRUE;
continue;
}
// 投递nLimit个AcceptEx I/O请求
int i = 0;
while(i++ < nLimit && pThis->m_nPendingAcceptCount < pThis->m_nMaxAccepts)
{
pBuffer = pThis->AllocateBuffer(BUFFER_SIZE);
if(pBuffer != NULL)
{
pThis->InsertPendingAccept(pBuffer);
pThis->PostAccept(pBuffer);
}
}
}
}
return 0;
}
示例9: CmBattGetBatteryStatus
NTSTATUS
NTAPI
CmBattGetBatteryStatus(IN PCMBATT_DEVICE_EXTENSION DeviceExtension,
IN ULONG Tag)
{
ULONG PsrData = 0;
NTSTATUS Status;
ULONG BstState;
ULONG DesignVoltage, PresentRate, RemainingCapacity;
PAGED_CODE();
if (CmBattDebug & CMBATT_GENERIC_INFO)
DbgPrint("CmBattGetBatteryStatus - CmBatt (%08x) Tag (%d)\n", DeviceExtension, Tag);
/* Validate ACPI data */
Status = CmBattVerifyStaticInfo(DeviceExtension, Tag);
if (!NT_SUCCESS(Status)) return Status;
/* Check for delayed status notifications */
if (DeviceExtension->DelayNotification)
{
/* Process them now and don't do any other work */
CmBattNotifyHandler(DeviceExtension, ACPI_BATT_NOTIFY_STATUS);
return Status;
}
/* Get _BST from ACPI */
Status = CmBattGetBstData(DeviceExtension, &DeviceExtension->BstData);
if (!NT_SUCCESS(Status))
{
/* Fail */
InterlockedExchange(&DeviceExtension->ArLockValue, 0);
return Status;
}
/* Clear current BST information */
DeviceExtension->State = 0;
DeviceExtension->RemainingCapacity = 0;
DeviceExtension->PresentVoltage = 0;
DeviceExtension->Rate = 0;
/* Get battery state */
BstState = DeviceExtension->BstData.State;
/* Is the battery both charging and discharging? */
if ((BstState & ACPI_BATT_STAT_DISCHARG) && (BstState & ACPI_BATT_STAT_CHARGING) &&
(CmBattDebug & (CMBATT_ACPI_WARNING | CMBATT_GENERIC_WARNING)))
DbgPrint("************************ ACPI BIOS BUG ********************\n* "
"CmBattGetBatteryStatus: Invalid state: _BST method returned 0x%08x for Battery State.\n"
"* One battery cannot be charging and discharging at the same time.\n",
BstState);
/* Is the battery discharging? */
if (BstState & ACPI_BATT_STAT_DISCHARG)
{
/* Set power state and check if it just started discharging now */
DeviceExtension->State |= BATTERY_DISCHARGING;
if (!(DeviceExtension->State & ACPI_BATT_STAT_DISCHARG))
{
/* Remember the time when the state changed */
DeviceExtension->InterruptTime = KeQueryInterruptTime();
}
}
else if (BstState & ACPI_BATT_STAT_CHARGING)
{
/* Battery is charging, update power state */
DeviceExtension->State |= (BATTERY_CHARGING | BATTERY_POWER_ON_LINE);
}
/* Is the battery in a critical state? */
if (BstState & ACPI_BATT_STAT_CRITICAL) DeviceExtension->State |= BATTERY_CRITICAL;
/* Read the voltage data */
DeviceExtension->PresentVoltage = DeviceExtension->BstData.PresentVoltage;
/* Check if we have an A/C adapter */
if (AcAdapterPdo)
{
/* Query information on it */
CmBattGetPsrData(AcAdapterPdo, &PsrData);
}
else
{
/* Otherwise, check if the battery is charging */
if (BstState & ACPI_BATT_STAT_CHARGING)
{
/* Then we'll assume there's a charger */
PsrData = 1;
}
else
{
/* Assume no charger */
PsrData = 0;
}
}
/* Is there a charger? */
if (PsrData)
{
/* Set the power state flag to reflect this */
DeviceExtension->State |= BATTERY_POWER_ON_LINE;
//.........这里部分代码省略.........
示例10: xaudio2_do_reset_playback
//.........这里部分代码省略.........
SourceType.Format.nChannels = 2;
SourceType.dwChannelMask = STEREO;
break;
case DevFmtQuad:
SourceType.Format.nChannels = 4;
SourceType.dwChannelMask = QUAD;
break;
case DevFmtX51:
SourceType.Format.nChannels = 6;
SourceType.dwChannelMask = X5DOT1;
break;
case DevFmtX51Side:
SourceType.Format.nChannels = 6;
SourceType.dwChannelMask = X5DOT1SIDE;
break;
case DevFmtX61:
SourceType.Format.nChannels = 7;
SourceType.dwChannelMask = X6DOT1;
break;
case DevFmtX71:
SourceType.Format.nChannels = 8;
SourceType.dwChannelMask = X7DOT1;
break;
}
switch (device->FmtType)
{
case DevFmtByte:
device->FmtType = DevFmtUByte;
/* fall-through */
case DevFmtUByte:
SourceType.Format.wBitsPerSample = 8;
SourceType.Samples.wValidBitsPerSample = 8;
SourceType.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
break;
case DevFmtUShort:
device->FmtType = DevFmtShort;
/* fall-through */
case DevFmtShort:
SourceType.Format.wBitsPerSample = 16;
SourceType.Samples.wValidBitsPerSample = 16;
SourceType.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
break;
case DevFmtFloat:
SourceType.Format.wBitsPerSample = 32;
SourceType.Samples.wValidBitsPerSample = 32;
SourceType.SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
break;
}
SourceType.Format.cbSize = (sizeof(SourceType) - sizeof(WAVEFORMATEX));
SourceType.Format.nSamplesPerSec = device->Frequency;
SourceType.Format.nBlockAlign = SourceType.Format.nChannels *
SourceType.Format.wBitsPerSample / 8;
SourceType.Format.nAvgBytesPerSec = SourceType.Format.nSamplesPerSec *
SourceType.Format.nBlockAlign;
SourceType.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
/*-----------create source voice-------------*/
data->sourceVoiceCallback = new (std::nothrow) XAudio2SourceVoiceCallback(device);
if (data->sourceVoiceCallback == NULL)
{
ERR("create XAudio2SourceVoiceCallback() failed\n");
return ALC_FALSE;
}
data->sourceVoiceCallback->callbackEvent = CreateEventEx(NULL, NULL, 0, EVENT_ACCESS_MASK);
if (data->sourceVoiceCallback->callbackEvent == NULL)
{
ERR("create callback event failed\n");
return ALC_FALSE;
}
hr = data->xAudioObj->CreateSourceVoice(&data->sourceVoice, &SourceType.Format, 0,
XAUDIO2_DEFAULT_FREQ_RATIO, data->sourceVoiceCallback);
if (FAILED(hr))
{
ERR("CreateSourceVoice() failed: 0x%08lx\n", hr);
return ALC_FALSE;
}
/*---------create buffer--------------*/
//calculate frame size
data->frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
//start playing the audio engine
data->sourceVoice->Start();
//wait for the buffer to be created
WaitForSingleObjectEx(data->sourceVoiceCallback->callbackEvent, INFINITE, FALSE);
device->UpdateSize = data->bufferSize / data->frameSize;
device->NumUpdates = 1;
//set the running flag
InterlockedExchange(&data->running, TRUE);
return ALC_TRUE;
}
示例11: CmBattWakeDpc
VOID
NTAPI
CmBattWakeDpc(IN PKDPC Dpc,
IN PCMBATT_DEVICE_EXTENSION FdoExtension,
IN PVOID SystemArgument1,
IN PVOID SystemArgument2)
{
PDEVICE_OBJECT CurrentObject;
BOOLEAN AcNotify = FALSE;
PCMBATT_DEVICE_EXTENSION DeviceExtension;
ULONG ArFlag;
if (CmBattDebug & 2) DbgPrint("CmBattWakeDpc: Entered.\n");
/* Loop all device objects */
for (CurrentObject = FdoExtension->DeviceObject;
CurrentObject;
CurrentObject = CurrentObject->NextDevice)
{
/* Turn delay flag off, we're back in S0 */
DeviceExtension = CurrentObject->DeviceExtension;
DeviceExtension->DelayNotification = 0;
/* Check if this is an AC adapter */
if (DeviceExtension->FdoType == CmBattAcAdapter)
{
/* Was there a pending notify? */
if (DeviceExtension->ArFlag & CMBATT_AR_NOTIFY)
{
/* We'll send a notify on the next pass */
AcNotify = TRUE;
DeviceExtension->ArFlag = 0;
if (CmBattDebug & 0x20)
DbgPrint("CmBattWakeDpc: AC adapter notified\n");
}
}
}
/* Loop the device objects again */
for (CurrentObject = FdoExtension->DeviceObject;
CurrentObject;
CurrentObject = CurrentObject->NextDevice)
{
/* Check if this is a battery */
DeviceExtension = CurrentObject->DeviceExtension;
if (DeviceExtension->FdoType == CmBattBattery)
{
/* Check what ARs are pending */
ArFlag = DeviceExtension->ArFlag;
if (CmBattDebug & 0x20)
DbgPrint("CmBattWakeDpc: Performing delayed ARs: %01x\n", ArFlag);
/* Insert notification, clear the lock value */
if (ArFlag & CMBATT_AR_INSERT) InterlockedExchange(&DeviceExtension->ArLockValue, 0);
/* Removal, clear the battery tag */
if (ArFlag & CMBATT_AR_REMOVE) DeviceExtension->Tag = 0;
/* Notification (or AC/DC adapter change from first pass above) */
if ((ArFlag & CMBATT_AR_NOTIFY) || (AcNotify))
{
/* Notify the class driver */
BatteryClassStatusNotify(DeviceExtension->ClassData);
}
}
}
}
示例12: CmBattNotifyHandler
VOID
NTAPI
CmBattNotifyHandler(IN PCMBATT_DEVICE_EXTENSION DeviceExtension,
IN ULONG NotifyValue)
{
ULONG ArFlag;
PCMBATT_DEVICE_EXTENSION FdoExtension;
PDEVICE_OBJECT DeviceObject;
if (CmBattDebug & (CMBATT_ACPI_ASSERT | CMBATT_PNP_INFO))
DbgPrint("CmBattNotifyHandler: CmBatt 0x%08x Type %d Number %d Notify Value: %x\n",
DeviceExtension,
DeviceExtension->FdoType,
DeviceExtension->DeviceId,
NotifyValue);
/* Check what kind of notification was received */
switch (NotifyValue)
{
/* ACPI Specification says is sends a "Bus Check" when power source changes */
case ACPI_BUS_CHECK:
/* We treat it as possible physical change */
DeviceExtension->ArFlag |= (CMBATT_AR_NOTIFY | CMBATT_AR_INSERT);
if ((DeviceExtension->Tag) &&
(CmBattDebug & (CMBATT_ACPI_WARNING | CMBATT_GENERIC_WARNING)))
DbgPrint("CmBattNotifyHandler: Received battery #%x insertion, but tag was not invalid.\n",
DeviceExtension->DeviceId);
break;
/* Status of the battery has changed */
case ACPI_BATT_NOTIFY_STATUS:
/* All we'll do is notify the class driver */
DeviceExtension->ArFlag |= CMBATT_AR_NOTIFY;
break;
/* Information on the battery has changed, such as physical presence */
case ACPI_DEVICE_CHECK:
case ACPI_BATT_NOTIFY_INFO:
/* Reset all state and let the class driver re-evaluate it all */
DeviceExtension->ArFlag |= (CMBATT_AR_NOTIFY |
CMBATT_AR_INSERT |
CMBATT_AR_REMOVE);
break;
default:
if (CmBattDebug & CMBATT_PNP_INFO)
DbgPrint("CmBattNotifyHandler: Unknown Notify Value: %x\n", NotifyValue);
}
/* Check if we're supposed to delay the notification till later */
if (DeviceExtension->DelayNotification)
{
/* We'll handle this when we get a status query later on */
if (CmBattDebug & CMBATT_PNP_INFO)
DbgPrint("CmBattNotifyHandler: Notification delayed: ARs = %01x\n",
DeviceExtension->ArFlag);
return;
}
/* We're going to handle this now */
if (CmBattDebug & CMBATT_PNP_INFO)
DbgPrint("CmBattNotifyHandler: Performing ARs: %01x\n", DeviceExtension->ArFlag);
/* Check if this is a battery or AC adapter notification */
if (DeviceExtension->FdoType == CmBattBattery)
{
/* Reset the current trip point */
DeviceExtension->TripPointValue = BATTERY_UNKNOWN_CAPACITY;
/* Check what ARs have to be done */
ArFlag = DeviceExtension->ArFlag;
/* New battery inserted, reset lock value */
if (ArFlag & CMBATT_AR_INSERT) InterlockedExchange(&DeviceExtension->ArLockValue, 0);
/* Check if the battery may have been removed */
if (ArFlag & CMBATT_AR_REMOVE) DeviceExtension->Tag = 0;
/* Check if there's been any sort of change to the battery */
if (ArFlag & CMBATT_AR_NOTIFY)
{
/* We'll probably end up re-evaluating _BIF and _BST */
DeviceExtension->NotifySent = TRUE;
BatteryClassStatusNotify(DeviceExtension->ClassData);
}
}
else if (DeviceExtension->ArFlag & CMBATT_AR_NOTIFY)
{
/* The only known notification is AC/DC change. Loop device objects. */
for (DeviceObject = DeviceExtension->FdoDeviceObject->DriverObject->DeviceObject;
DeviceObject;
DeviceObject = DeviceObject->NextDevice)
{
/* Is this a battery? */
FdoExtension = DeviceObject->DeviceExtension;
if (FdoExtension->FdoType == CmBattBattery)
//.........这里部分代码省略.........
示例13: nonzero
//.........这里部分代码省略.........
// Use the most recent server for the connection attempt
serverIndex = dbIndex;
server = &dbConfigServers[serverIndex];
TRACE("Connecting to server #%d [%s] on attempt %lu/%lu.",
serverIndex, server->name, attempt+1, attemptMax);
// Set connection options
optTimeout = (UINT)dbConfigGlobal.connTimeout;
if (mysql_options(db->handle, MYSQL_OPT_CONNECT_TIMEOUT, &optTimeout) != 0) {
TRACE("Failed to set connection timeout option.");
}
optReconnect = FALSE;
if (mysql_options(db->handle, MYSQL_OPT_RECONNECT, &optReconnect) != 0) {
TRACE("Failed to set reconnection option.");
}
if (server->compression) {
if (mysql_options(db->handle, MYSQL_OPT_COMPRESS, 0) != 0) {
TRACE("Failed to set compression option.");
}
}
if (server->sslEnable) {
//
// This function always returns 0. If the SSL setup is incorrect,
// the call to mysql_real_connect() will return an error.
//
mysql_ssl_set(db->handle, server->sslKeyFile, server->sslCertFile,
server->sslCAFile, server->sslCAPath, server->sslCiphers);
}
// Attempt connection with server
connection = mysql_real_connect(db->handle,
server->host, server->user, server->password,
server->database, server->port, NULL, CLIENT_INTERACTIVE);
if (connection == NULL) {
LOG_ERROR("Unable to connect to server [%s]: %s",
server->name, mysql_error(db->handle));
} else if (mysql_get_server_version(db->handle) < 50019) {
LOG_ERROR("Unsupported version of MySQL Server [%s]: running v%s, must be v5.0.19 or newer.",
server->name, mysql_get_server_info(db->handle));
} else {
// Pointer values should be the same as from mysql_init()
ASSERT(connection == db->handle);
// Allocate pre-compiled statement structures
for (i = 0; i < ELEMENT_COUNT(db->stmt); i++) {
db->stmt[i] = mysql_stmt_init(db->handle);
if (db->stmt[i] == NULL) {
LOG_ERROR("Unable to allocate memory for statement structure.");
error = ERROR_NOT_ENOUGH_MEMORY;
goto failed;
}
}
// Successfully connected, set the global server index
InterlockedExchange(&dbIndex, serverIndex);
// Update context's server index and time stamps
db->index = serverIndex;
GetSystemTimeAsFileTime(&db->created.fileTime);
db->used.value = db->created.value;
LOG_INFO("Connected to %s [%s], running MySQL Server v%s.",
mysql_get_host_info(db->handle), server->name,
mysql_get_server_info(db->handle));
*data = db;
return TRUE;
}
// Unsuccessful connection, continue to the next server
serverNextIndex = serverIndex + 1;
if (serverNextIndex >= (LONG)dbConfigServerCount) {
serverNextIndex = 0;
}
//
// Compare the current server index before swapping values in the
// event that another thread has already changed the index.
//
InterlockedCompareExchange(&dbIndex, serverNextIndex, serverIndex);
}
// Unable to connect to any servers
error = ERROR_CONNECTION_REFUSED;
failed:
if (db != NULL) {
ConnectionClose(NULL, db);
}
SetLastError(error);
return FALSE;
}
示例14: memset
int GitRev::SafeFetchFullInfo(CGit *git)
{
if(InterlockedExchange(&m_IsUpdateing,TRUE) == FALSE)
{
this->m_Files.Clear();
git->CheckAndInitDll();
GIT_COMMIT commit;
GIT_COMMIT_LIST list;
GIT_HASH parent;
memset(&commit,0,sizeof(GIT_COMMIT));
CAutoLocker lock(g_Git.m_critGitDllSec);
try
{
if (git_get_commit_from_hash(&commit, this->m_CommitHash.m_hash))
return -1;
}
catch (char *)
{
return -1;
}
int i=0;
git_get_commit_first_parent(&commit,&list);
bool isRoot = (list==NULL);
while(git_get_commit_next_parent(&list,parent) == 0 || isRoot)
{
GIT_FILE file=0;
int count=0;
try
{
if (isRoot)
git_root_diff(git->GetGitDiff(), this->m_CommitHash.m_hash, &file, &count, 1);
else
git_diff(git->GetGitDiff(), parent, commit.m_hash, &file, &count, 1);
}
catch (char *)
{
git_free_commit(&commit);
return -1;
}
isRoot = false;
CTGitPath path;
CString strnewname;
CString stroldname;
for (int j = 0; j < count; ++j)
{
path.Reset();
char *newname;
char *oldname;
strnewname.Empty();
stroldname.Empty();
int mode,IsBin,inc,dec;
git_get_diff_file(git->GetGitDiff(),file,j,&newname,&oldname,
&mode,&IsBin,&inc,&dec);
git->StringAppend(&strnewname, (BYTE*)newname, CP_UTF8);
git->StringAppend(&stroldname, (BYTE*)oldname, CP_UTF8);
path.SetFromGit(strnewname,&stroldname);
path.ParserAction((BYTE)mode);
path.m_ParentNo = i;
this->m_Action|=path.m_Action;
if(IsBin)
{
path.m_StatAdd=_T("-");
path.m_StatDel=_T("-");
}
else
{
path.m_StatAdd.Format(_T("%d"),inc);
path.m_StatDel.Format(_T("%d"),dec);
}
m_Files.AddPath(path);
}
git_diff_flush(git->GetGitDiff());
++i;
}
InterlockedExchange(&m_IsUpdateing,FALSE);
InterlockedExchange(&m_IsFull,TRUE);
git_free_commit(&commit);
}
return 0;
}
示例15: juce_InterlockedExchange
// In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
// older ones we have to actually call the ops as win32 functions..
long juce_InterlockedExchange (volatile long* a, long b) noexcept { return InterlockedExchange (a, b); }