本文整理汇总了C++中CCriticalSection::Lock方法的典型用法代码示例。如果您正苦于以下问题:C++ CCriticalSection::Lock方法的具体用法?C++ CCriticalSection::Lock怎么用?C++ CCriticalSection::Lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCriticalSection
的用法示例。
在下文中一共展示了CCriticalSection::Lock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例2: fopen
//unsigned int __stdcall Thread_SendMsg(void *data)
unsigned int __stdcall Thread_SendMsg(LPVOID lpParam)
{
//test for message comunicate
ThreadProcInfo* pInfo = (ThreadProcInfo*) lpParam;
FILE *fpMsg = fopen(dataFileName,"rb");
int readNum;
int counter = 0;
int nRet;
while(1)
{
//for pause control
critical_section.Lock();
if(exit_flag)
{
critical_section.Unlock();
fclose(fpMsg);
//shutdown(sockClient,SD_SEND);
shutdown(sockClient,SD_BOTH);
closesocket(sockClient);
ResetEvent(g_readyEvent_Send); //reset g_readyEvent_Send to no signal
return -1;
}
critical_section.Unlock();
WaitForSingleObject(g_readyEvent_Send, INFINITE);
uint8* recvBuffP = (uint8*)&headerBuf;
int readLen;
//step 1: read header length
readLen = sizeof(headerBuf.msgHeader.headerLen);
readNum = fread(&(headerBuf.msgHeader.headerLen), readLen, 1, fpMsg);
if(readNum != 1)
{
fseek(fpMsg, 0, SEEK_SET);
counter = 0;
continue;
}
//read header
recvBuffP += sizeof(headerBuf.msgHeader.headerLen);
readLen = headerBuf.msgHeader.headerLen - sizeof(headerBuf.msgHeader.headerLen);
readNum = fread(recvBuffP, readLen, 1, fpMsg);
if(readNum != 1)
{
fseek(fpMsg, 0, SEEK_SET);
counter = 0;
continue;
}
//read payload
readLen = headerBuf.msgHeader.payloadLen;
if(readLen != 0)
{
readNum = fread(payloadBuf, readLen,1,fpMsg);
if(readNum != 1)
{
fseek(fpMsg, 0, SEEK_SET);
counter = 0;
continue;
}
}
if(headerBuf.msgHeader.payloadLen != 0)
{
//printf("message Count = %d\n",counter);
//display message count
PostMessage(pInfo->hWnd,WM_DISPLAYCOUNT,NULL,counter);
counter++;
//send header
nRet = send(sockClient,(char*)&headerBuf,headerBuf.msgHeader.headerLen,0);
if ((nRet == SOCKET_ERROR) || (nRet == 0))
{
trySetConnectSocket(true);
}
else
{
if((headerBuf.msgHeader.payloadLen > 0))
{
nRet = send(sockClient,(char*)payloadBuf,headerBuf.msgHeader.payloadLen,0);
if ((nRet == SOCKET_ERROR) || (nRet == 0))
{
trySetConnectSocket(true);
}
}
}
Sleep(timeDelay);
}
}
fclose(fpMsg);
}
示例3: StatsAddTotalBytesSent
void StatsAddTotalBytesSent( size_t inLength )
{
ms_StatsCS.Lock();
ms_HttpTotalBytesSent += inLength;
ms_StatsCS.Unlock();
}
示例4: MessageHandler
//======================================================================================
// MessageHandler()
//
// Handles messages from DirectPlay.
//======================================================================================
HRESULT CDarkPeer::MessageHandler(void* pContext, DWORD messageType, void* pMessage)
{
switch (messageType)
{
case DPN_MSGID_CREATE_PLAYER:
{
HandleCreatePlayerMsg((DPNMSG_CREATE_PLAYER*)pMessage);
break;
}
case DPN_MSGID_DESTROY_PLAYER:
{
// Translate DPlay8's destroy player message to DPlay4
PDPNMSG_DESTROY_PLAYER pDestroyPlayer = (PDPNMSG_DESTROY_PLAYER) pMessage;
DPNID dpnidPlayer = pDestroyPlayer->dpnidPlayer;
DPMSG_DESTROYPLAYERORGROUP* pDP4DestroyPlayer = new DPMSG_DESTROYPLAYERORGROUP;
if (dpnidPlayer != m_dpnidLocal && g_pNetMan)
{
#if (GAME == GAME_THIEF)
#if 1
DPN_PLAYER_INFO* pPeerInfo = GetPeerInfo(pDestroyPlayer->dpnidPlayer);
if (pPeerInfo)
{
char playerName[kMaxPlayerName];
WideToAnsi(playerName, pPeerInfo->pwszName, sizeof(playerName));
const char* str = "%s has left the game.";
MessageMgr::Get()->AddLineFormat(true, str, playerName);
ConPrintF(str, playerName);
SAFE_DELETE_ARRAY(pPeerInfo);
}
#else
const char* playerName = Players.NameFromDPNID(pDestroyPlayer->dpnidPlayer);
const char* msg = "%s has left the game.";
MessageMgr::Get()->AddLineFormat(true, msg, playerName);
ConPrintF(msg, playerName);
#endif
#endif
ZeroMemory(pDP4DestroyPlayer, sizeof(DPMSG_DESTROYPLAYERORGROUP));
pDP4DestroyPlayer->lpLocalData = m_DP4PlayerData[dpnidPlayer];
pDP4DestroyPlayer->dpId = dpnidPlayer;
pDP4DestroyPlayer->dwType = DPSYS_DESTROYPLAYERORGROUP;
pDP4DestroyPlayer->dwPlayerType = DPPLAYERTYPE_PLAYER;
// send Thief the destroy player notification in the form it expects from DPlay 4
NetMessage* pMsg = new NetMessage;
pMsg->m_pMsgData = (BYTE*)pDP4DestroyPlayer;
pMsg->m_size = sizeof(DPMSG_DESTROYPLAYERORGROUP);
pMsg->m_dpnidSender = DPID_SYSMSG;
m_DarkQueue.Push(pMsg);
// find the player's index and destroy the player data
}
break;
}
case DPN_MSGID_INDICATE_CONNECT:
{
if (g_Net == STATE_Host)
{
#ifndef _RELEASE
if (Client.MissionStarted() && !Cfg.GetBool("AllowJoinsInProgress"))
#else
if (Client.MissionStarted())
#endif
return DPNERR_HOSTREJECTEDCONNECTION;
}
break;
}
case DPN_MSGID_CONNECT_COMPLETE:
{
PDPNMSG_CONNECT_COMPLETE pConnComplete = (PDPNMSG_CONNECT_COMPLETE)pMessage;
if (pConnComplete->hResultCode == DPN_OK)
{
#if (GAME == GAME_THIEF || GAME == GAME_DROMED)
m_dpnidLocal = (pConnComplete->dpnidLocal);
ConPrintF("Connected to session.");
_SFX_Play_Raw(1, 0, "pickloot.wav");
#endif
SetEvent(m_ConnectedEvent);
}
break;
}
case DPN_MSGID_ENUM_HOSTS_RESPONSE:
{
m_csEnumResponse.Lock();
DPNMSG_ENUM_HOSTS_RESPONSE* pResponse = (DPNMSG_ENUM_HOSTS_RESPONSE*)pMessage;
//.........这里部分代码省略.........
示例5: ThreadProc
UINT ThreadProc(LPVOID pParam)
{
HWND hwnd = AfxGetMainWnd()->GetSafeHwnd();
LPTHREADDATA pData = (LPTHREADDATA)pParam;
Mat dst_temp = Mat::zeros(pData->Roi_dst->size(), 16);
//Vec3b NullPixel = Vec3b(255, 255, 255);
float x_, y_;
Point StartPoint;
Point EndPoint;
StartPoint = pData->Roi->tl();
EndPoint = pData->Roi->br();
int x_s, x_l, y_s, y_l;
Vec3b* src_tl;
Vec3b* dst_;
float* xmap_;
float* ymap_;
unsigned char* mask_;
int CamIdx;
int i = 1;
while (TRUE)
{
//MessageBox(NULL, _T("checkpoint1"),NULL , MB_OK);
//WaitForSingleObject(g_event[pData->ID],INFINITE);
g_Semaphore.Lock();
//MessageBox(NULL, _T("checkpoint2"), NULL, MB_OK);
for (int y = StartPoint.y; y < EndPoint.y; y++)
{
//Vec3b* dst_ = pData->Obj->m_dst.ptr<Vec3b>(y - StartPoint.y);
dst_ = dst_temp.ptr<Vec3b>(y - StartPoint.y);
xmap_ = pData->Obj->m_xmap.ptr<float>(y);
ymap_ = pData->Obj->m_ymap.ptr<float>(y);
mask_ = pData->Obj->m_mask.ptr<unsigned char>(y);
for (int x = StartPoint.x; x < EndPoint.x; x++)
{
CamIdx = (int)mask_[x];
if (CamIdx == 255)
{
//dst_[x] = NullPixel;
dst_[x - StartPoint.x] = Vec3b(0, 0, 0);
}
else
{
x_ = xmap_[x];
y_ = ymap_[x];
x_s = (int)floor(x_);
x_l = (int)ceil(x_);
y_s = (int)floor(y_);
y_l = (int)ceil(y_);
//float n = y_ - y_s, m = x_ - x_s;
if (x_s < 0 || y_s < 0 || x_l>(*pData->Images)[CamIdx].cols - 1 || y_l>(*pData->Images)[CamIdx].rows - 1)
{
//cout << "out of range" << endl;
dst_[x - StartPoint.x] = Vec3b(0, 0, 0);
}
else
{
src_tl = (*pData->Images)[CamIdx].ptr<Vec3b>(y_s, x_s);
dst_[x - StartPoint.x] = *src_tl;
}
}
}
}
CCritical.Lock();
pData->Obj->m_dst = pData->Obj->m_dst | dst_temp;
//signal++;
::PostMessage(hwnd, WM_LOOP, NULL, NULL);
CCritical.Unlock();
//MessageBox(NULL, _T("threadend"), NULL, NULL);
//Sleep(10);
//i--;
}
dst_temp.release();
return 0;
};
示例6: ScanPostThread
// 扫描帖子线程
UINT AFX_CDECL ScanPostThread(LPVOID _threadID)
{
int threadID = (int)_threadID;
CTiebaManagerDlg* dlg = (CTiebaManagerDlg*)AfxGetApp()->m_pMainWnd;
// 初始化日志文档
CoInitializeEx(NULL, COINIT_MULTITHREADED);
CComPtr<IHTMLDocument2> document;
dlg->GetLogDocument(document);
CComPtr<IHTMLDocument2>* pDocument = (CComPtr<IHTMLDocument2>*)&(int&)document;
CString pageCount, src;
map<__int64, int>::iterator historyReplyIt;
g_threadIndexLock.Lock();
while (!g_stopScanFlag && g_threadIndex < (int)g_threads.size())
{
ThreadInfo& thread = g_threads[g_threadIndex++];
g_threadIndexLock.Unlock();
if (g_deletedTID.find(_ttoi64(thread.tid)) != g_deletedTID.end()) // 已删
goto next;
g_optionsLock.Lock();
if (g_trustedThread.find(thread.tid) != g_trustedThread.end()) // 信任
{
g_optionsLock.Unlock();
goto next;
}
g_optionsLock.Unlock();
__int64 tid = _ttoi64(thread.tid);
int reply = _ttoi(thread.reply);
historyReplyIt = g_reply.find(tid);
BOOL hasHistoryReply = historyReplyIt != g_reply.end();
if (hasHistoryReply && reply <= historyReplyIt->second) // 无新回复
{
historyReplyIt->second = reply;
goto next;
}
// 第一页
src = HTTPGet(_T("http://tieba.baidu.com/p/" + thread.tid), FALSE, &g_stopScanFlag);
if (src == NET_STOP_TEXT)
goto next;
if (src == NET_TIMEOUT_TEXT)
{
if (!g_briefLog)
dlg->Log(_T("<a href=\"http://tieba.baidu.com/p/") + thread.tid + _T("\">") + thread.title
+ _T("</a> <font color=red>获取贴子列表失败(超时),暂时跳过</font>"), pDocument);
goto next;
}
// 帖子页数
pageCount = GetStringBetween(src, PAGE_COUNT_LEFT, PAGE_COUNT_RIGHT);
if (pageCount == _T(""))
{
WriteString(src, _T("thread.txt"));
if (!g_briefLog)
dlg->Log(_T("<a href=\"http://tieba.baidu.com/p/") + thread.tid + _T("\">") + thread.title
+ _T("</a> <font color=red>获取贴子列表失败(可能已被删),暂时跳过</font>"), pDocument);
goto next;
}
// 扫描帖子页
int iPageCount = _ttoi(pageCount);
BOOL res = ScanPostPage(thread.tid, 1, thread.title, hasHistoryReply, 0, src, threadID, dlg, pDocument);
if (iPageCount > 1 && !g_stopScanFlag)
res = ScanPostPage(thread.tid, iPageCount, thread.title, hasHistoryReply, 0, _T(""), threadID, dlg, pDocument);
// 记录历史回复
if (res)
g_reply[tid] = reply;
next:
g_threadIndexLock.Lock();
}
g_threadIndexLock.Unlock();
CoUninitialize();
dlg->m_stateList.DeleteString(threadID);
dlg->m_stateList.InsertString(threadID, _T("线程结束"));
return 0;
}
示例7: StatsBytesDeallocated
void StatsBytesDeallocated( int nBodyLength )
{
ms_StatsCS.Lock();
ms_AllocationStats.uiActiveKBAllocated -= nBodyLength / 1024;
ms_StatsCS.Unlock();
}
示例8: Lock
Lock( CCriticalSection cs ) : m_cs(cs)
{
m_cs.Lock();
}
示例9: StatsNumResponsesDec
void StatsNumResponsesDec( void )
{
ms_StatsCS.Lock();
ms_AllocationStats.uiActiveNumResponses--;
ms_StatsCS.Unlock();
}
示例10: OptionsDialogProc
//.........这里部分代码省略.........
dc2.CreateCompatibleDC(&dcDesk);
CBitmap* bmpTmp=dc2.SelectObject(btLeft);
FitImageToRect(rt,szLeftSize);
dc.StretchBlt(ptLT.x+rt.left,ptLT.y+rt.top,rt.Width(),rt.Height(),&dc2,0,0,szLeftSize.cx,szLeftSize.cy,SRCCOPY);
dc2.SelectObject(bmpTmp);
}
}
if(sPathInRight!=""){
if(btRight){
CRect rt,rtw;
::GetClientRect(GetDlgItem(hwndDlg,IDC_IMGR),&rt);
::GetWindowRect(GetDlgItem(hwndDlg,IDC_IMGR),&rtw);
CPoint ptLT(rtw.left,rtw.top);
ScreenToClient(hwndDlg,&ptLT);
CDC dc2;
CDesktopDC dcDesk;
dc2.CreateCompatibleDC(&dcDesk);
CBitmap* bmpTmp=dc2.SelectObject(btRight);
FitImageToRect(rt,szLeftSize);
dc.StretchBlt(ptLT.x+rt.left,ptLT.y+rt.top,rt.Width(),rt.Height(),&dc2,0,0,szRightSize.cx,szRightSize.cy,SRCCOPY);
dc2.SelectObject(bmpTmp);
}
}
dc.Detach();
EndPaint(hwndDlg,&lpPaint);
return TRUE;
}
if(uMsg==WM_SYSCOMMAND && wParam==SC_CLOSE){
uMsg=WM_COMMAND;
wParam=IDOK;
}
if(uMsg==WM_COMMAND && wParam==IDOK){
bStopCheck=1;
csCheck.Lock();
csCheck.Unlock();
if(sListOfImagesToDelete.GetSize()>0){
if(dwDeleteOptions){
if(AfxMessageBox(Format("%s. %s: %i\n%s?",_l("Search for duplicated images: finished"),_l("Image(s) found"),sListOfImagesToDelete.GetSize(),_l("Do you really want to delete image(s)")),MB_YESNO|MB_ICONQUESTION)==IDYES){
for(int i=0;i<sListOfImagesToDelete.GetSize();i++){
char szPath[MAX_PATH+2]="";
memset(&szPath,0,sizeof(szPath));
strcpy(szPath,sListOfImagesToDelete[i]);
if(isFileExist(szPath)){
SHFILEOPSTRUCT str;
memset(&str,0,sizeof(str));
str.hwnd=hwndDlg;
str.wFunc=FO_DELETE;
str.pFrom=szPath;
str.pTo=NULL;
str.fFlags=FOF_ALLOWUNDO|FOF_NOCONFIRMATION|FOF_SILENT;
SHFileOperation(&str);
lDeletedFiles++;
}
}
}
}else{
lDeletedFiles+=sListOfImagesToDelete.GetSize();
}
}
if(bReplaceMode){
CString sDump;
int ik=0;
for(ik=0;ik<aClosestImage.GetSize();ik++){
sDump+=Format("%i -> %i, %i %s\n",ik,aClosestImage[ik],aClosestImageTaken[ik],sListOfImages[ik]);
aClosestImageTaken[ik]=0;
}
示例11: AddTickCount
// Debugging
void SharedUtil::AddTickCount( long long llTickCountAdd )
{
ms_criticalSection.Lock ();
ms_llTickCountAdd = llTickCountAdd;
ms_criticalSection.Unlock ();
}
示例12: InjectionEnterCriticalSection
/*
* Should be used to lock access to internal injection data.
* Only ne first thread that calls this function would continue
* to run until InjectionLeaveCriticalSection() is called.
* That thread can call InjectionEnterCriticalSection() any number
* of times.
*/
void InjectionEnterCriticalSection()
{
InjectionCriticalSectionVar.Lock();
}
示例13: ReadOptions
// 读方案
void ReadOptions(LPCTSTR path)
{
CString strBuf;
gzFile f = gzopen_w(path, "rb");
if (f == NULL)
goto UseDefaultOptions;
// 头部
char header[2];
gzread(f, header, sizeof(header));
if (header[0] != 'T' || header[1] != 'B')
{
gzclose(f);
goto UseDefaultOptions;
}
g_optionsLock.Lock();
// 违规内容
ReadRegexTexts(f, g_keywords);
// 屏蔽用户
ReadRegexTexts(f, g_blackList);
// 信任用户
int intBuf;
gzread(f, &intBuf, sizeof(int)); // 长度
for (int i = 0; i < intBuf; i++)
{
ReadText(f, strBuf);
g_whiteList.insert(strBuf);
}
// 信任内容
ReadRegexTexts(f, g_whiteContent);
gzread(f, &g_scanInterval, sizeof(int)); // 扫描间隔
gzread(f, &g_banID, sizeof(BOOL)); // 封ID
gzread(f, &g_banDuration, sizeof(int)); // 封禁时长
BOOL banIP;
gzread(f, &banIP, sizeof(BOOL)); // 封IP
gzread(f, &g_banTrigCount, sizeof(int)); // 封禁违规次数
gzread(f, &g_onlyScanTitle, sizeof(BOOL)); // 只扫描标题
gzread(f, &g_deleteInterval, sizeof(float));// 删帖间隔
gzread(f, &g_confirm, sizeof(BOOL)); // 操作前提示
gzread(f, &g_scanPageCount, sizeof(int)); // 扫描最后页数
gzread(f, &g_briefLog, sizeof(BOOL)); // 只输出删帖封号
if (gzread(f, &g_delete, sizeof(BOOL)) != sizeof(BOOL)) // 删帖
g_delete = TRUE;
if (gzread(f, &g_threadCount, sizeof(int)) != sizeof(int)) // 线程数
g_threadCount = 2;
ReadText(f, g_banReason); // 封禁原因
if (!ReadText(f, g_imageDir)) // 违规图片目录
g_images.clear();
else
ReadImages(g_imageDir); // 违规图片
if (gzread(f, &g_SSIMThreshold, sizeof(double)) != sizeof(double)) // 阈值
g_SSIMThreshold = 2.43;
// 信任主题
g_trustedThread.clear();
if (gzread(f, &intBuf, sizeof(int)) == sizeof(int)) // 长度
for (int i = 0; i < intBuf; i++)
{
ReadText(f, strBuf);
g_trustedThread.insert(strBuf);
}
if (gzread(f, &g_defriend, sizeof(BOOL)) != sizeof(BOOL)) // 拉黑
g_defriend = FALSE;
if (gzread(f, &g_defriendTrigCount, sizeof(int)) != sizeof(int)) // 拉黑违规次数
g_defriendTrigCount = 5;
if (gzread(f, &g_autoSaveLog, sizeof(BOOL)) != sizeof(BOOL)) // 自动保存日志
g_autoSaveLog = FALSE;
g_optionsLock.Unlock();
gzclose(f);
return;
UseDefaultOptions:
g_optionsLock.Lock();
g_keywords.clear(); // 违规内容
g_blackList.clear(); // 屏蔽用户
g_whiteList.clear(); // 信任用户
g_whiteContent.clear(); // 信任内容
g_scanInterval = 5; // 扫描间隔
g_banID = FALSE; // 封ID
g_banDuration = 1; // 封禁时长
g_banTrigCount = 1; // 封禁违规次数
g_onlyScanTitle = FALSE; // 只扫描标题
g_deleteInterval = 2.0f; // 删帖间隔
g_confirm = TRUE; // 操作前提示
g_scanPageCount = 1; // 扫描最后页数
g_briefLog = FALSE; // 只输出删帖封号
g_delete = TRUE; // 删帖
g_threadCount = 2; // 线程数
g_banReason = _T(""); // 封禁原因
//.........这里部分代码省略.........
示例14: StaticGetAllocationStats
void EHS::StaticGetAllocationStats ( SAllocationStats& outAllocationStats )
{
ms_StatsCS.Lock();
outAllocationStats = ms_AllocationStats;
ms_StatsCS.Unlock();
}
示例15: StatsNumRequestsDec
void StatsNumRequestsDec( void )
{
ms_StatsCS.Lock();
ms_AllocationStats.uiActiveNumRequests--;
ms_StatsCS.Unlock();
}