本文整理汇总了C++中CEvent::Lock方法的典型用法代码示例。如果您正苦于以下问题:C++ CEvent::Lock方法的具体用法?C++ CEvent::Lock怎么用?C++ CEvent::Lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CEvent
的用法示例。
在下文中一共展示了CEvent::Lock方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DataProcess
/*
*********************************************************
* PROCESS THE DATA AND SHARE THEM WITH OTHER SOFTWARE.
*********************************************************
*/
void CDataProcess::DataProcess(){
if(COMM_SHAREDMEM == g_CommunicationSel){
//USING SHARED MEMERY.
BOOL bTimeout = gEventRecv.Lock(INFINITE);
UploadData();
gEventRecv.Unlock();
gEventSend.SetEvent();//SEND DATA.
}
else if(COMM_NETWORK == g_CommunicationSel){
//USING TCP
//UploadData();
//gEventSend.SetEvent();
//TELL THE SERVER TO SEND THE DATA
SetEvent(h_eSingleSpectraSending);
}
else if(COMM_NONE == g_CommunicationSel){
//SetEvent(h_eSingleSpectraSending);
global.series_fifo.append(rq);
}
}
示例2: IfEntry
//.........这里部分代码省略.........
//ifOrderRtn.erase(iOrderRtn);
/*
isBreakIn = true;
break;//终止内循环
*/
}
}
/*
if(isBreakIn){
isBreakIn = false;
lastpos = -1;//重新设置
::LeaveCriticalSection(&ifDealRtn);
continue;
}
*/
//lastpos = size - 1;
//iOrderRtn->second.clear();//清空就可以从0头开始检索
::LeaveCriticalSection(&ifDealRtn);
//}
}
else{
//还没生成消息队列,表示指令还未生效,返回继续搜索队列
::LeaveCriticalSection(&ifDealRtn);
TRACE("%s\r\n","还没生成消息队列,返回");
continue;
}
//成交返回处理
::EnterCriticalSection(&ifDealRtn);
if(endVolumeThisTrade == 0){
return 0;
}
else{
iTradeRtn = ifTradeRtn.find(thisSysId);
//证明已经有成交信息返回
if(iTradeRtn != ifTradeRtn.end()){
for(iTradeRtnVec = iTradeRtn->second.begin();iTradeRtnVec != iTradeRtn->second.end();iTradeRtnVec++){
TRACE("%s报单编号是%s\r\n","成交,从TradeRtn返回,",iTradeRtn->second.begin()->OrderSysID);
::EnterCriticalSection(&avgPriceOfIf);
valueTraded = valueTraded + iTradeRtnVec->Price * iTradeRtnVec->Volume;
volumeTraded = volumeTraded + iTradeRtnVec->Volume;
if(volumeTraded == data->numif){//全部成交
avgpIf avg(volumeTraded,valueTraded / volumeTraded);
avgPriceIf.push_back(avg);
::LeaveCriticalSection(&avgPriceOfIf);
//删除键值
ifTradeRtn.erase(iTradeRtn);
ifOrderRtn.erase(iOrderRtn);
::LeaveCriticalSection(&ifDealRtn);
return 0;
}
::LeaveCriticalSection(&avgPriceOfIf);
}
iTradeRtn->second.clear();//将成交数组清空
}
}
::LeaveCriticalSection(&ifDealRtn);
if(volumeTraded == endVolumeThisTrade && endVolumeThisTrade < data->numif){//本次成交结束,但是还没有全部成交,需要重新下单
TRACE("%s\r\n","重新下单");
::EnterCriticalSection(&g_IfPrice);
if(req.Direction == THOST_FTDC_D_Buy){//BUY
req.LimitPrice = ifBid1;
#ifdef _debug
req.LimitPrice = ifBid1;
#endif
}
else{//SELL
req.LimitPrice = ifAsk1;
#ifdef _debug
req.LimitPrice = ifAsk1;
#endif
}
::LeaveCriticalSection(&g_IfPrice);
req.VolumeTotalOriginal = data->numif - endVolumeThisTrade;
endVolumeThisTrade = data->numif;//重新设置
::EnterCriticalSection(&ODREF);
iNextOrderRef++;
TThostFtdcOrderRefType orderRefNew;
sprintf(orderRefNew,"%d", iNextOrderRef);
::LeaveCriticalSection(&ODREF);
strcpy(req.OrderRef,orderRefNew);
thisRef = CString(orderRefNew);
::EnterCriticalSection(&REQUEST_ID_IF);
int iResult = pUserApi->ReqOrderInsert(&req, ++iRequestID);
::LeaveCriticalSection(&REQUEST_ID_IF);
}
//如果价格发生不利变化,取消订单
UpdateTrade.Lock(INFINITE);//等待同步事件击发
::EnterCriticalSection(&g_IfPrice);
if((req.Direction == THOST_FTDC_D_Buy && req.LimitPrice < ifBid1) ||//买
(req.Direction == THOST_FTDC_D_Sell && req.LimitPrice > ifAsk1)){//卖
if (IsTradingOrder(&orderOld)){
TRACE("%s\r\n","改单动作,删除");
ReqOrderAction(&orderOld,reqNew);
}
}
::LeaveCriticalSection(&g_IfPrice);
}
delete (IfInData*)pParam;
return iResult;
}
示例3: flatOrOpen
int flatOrOpen(int num,bool isbuy,bool isflat){
if(num <= 0){
return -1;
}
::EnterCriticalSection(&avgPriceOfIf);
avgPriceIf.clear();//清空统计平均价格的数组
::LeaveCriticalSection(&avgPriceOfIf);
int numAvail = 0;//容许开仓数量
if(!isflat){//表示开仓
/*
ReqAccount.ResetEvent();//事件同步,设置为未发信状态
ReqQryIFTradingAccount();//查询if帐户可用资金
ReqAccount.Lock(INFINITE);//等待
if(rtnAvailIfID == rqIfID){
//留有10和100人民币的余地
marginIf = ifAsk1 * 300.0 * 0.12;//12%的保证金率
if(multiply != 0){
numAvail = min((int)((availA50 - 10.0) / (marginA50 * multiply)),(int)((availIf - 100.0) / marginIf));
}
else{
numAvail = num;
}
}
if(numAvail <= 0){
return -1;
}
num = min(num,numAvail);
*/
}
if(isflat){
if(isbuy){
TRACE("买平%d手\r\n",num);
}
else{
TRACE("卖平%d手\r\n",num);
}
}
else{
if(isbuy){
TRACE("买开%d手\r\n",num);
}
else{
TRACE("卖开%d手\r\n",num);
}
}
int numofA50 = num * multiply;
int numofIf = num;
std::vector<HANDLE> handleThread;//存放线程句柄的数组
IfInData *data;
if(isbuy && isflat){
data = new IfInData(1,false,true,0);
}
else if(isbuy && !isflat)
{
data = new IfInData(1,false,false,0);
}
else if(!isbuy && isflat){
data = new IfInData(1,true,true,0);
}
else{
data = new IfInData(1,true,false,0);
}
if(numofA50 != 0){
#define PUT(prop,value) orderA50.get()->##prop## = (##value##);
#define GET(prop) orderA50.get()->##prop
std::auto_ptr<Order> orderA50(new Order());
double valueTradeA50 = 0;
::EnterCriticalSection(&g_A50Price);
if(isbuy){
PUT(action,"BUY");
PUT(totalQuantity,numofA50);
#ifdef _case1
PUT(lmtPrice,a50Ask1 + 100.0);
#else
PUT(lmtPrice,a50Bid1);
#endif
PUT(orderType,"LMT");
}
else{
PUT(action,"SELL");
PUT(totalQuantity,numofA50);
#ifdef _case1
PUT(lmtPrice,a50Bid1 - 100.0);
#else
PUT(lmtPrice,a50Ask1);
#endif
PUT(orderType,"LMT");
}
::LeaveCriticalSection(&g_A50Price);
bool isA50Validate = false;
int iftraded = 0;//已经发出的if指令,A50每次交易满一手对冲,瞬间发出if指令
int filledLast = 0;//最近一次的成交数量
long idThisTrade;//交易id
std::vector<rtn> rtnres;//交易结果返回
int lastpos = -1;//上次检查返回新的vector的数据位置,从-1开始,考虑到0位置前用-1表示
::EnterCriticalSection(&tdi_a50);
idThisTrade = clientDlg->PlaceOrder_hedge(false,orderA50);
clientDlg->m_idrtn.insert(std::pair<long,std::vector<rtn>>(idThisTrade,rtnres));
::LeaveCriticalSection(&tdi_a50);
while(true){
//.........这里部分代码省略.........
示例4: TradeEntry_01
UINT TradeEntry_01(LPVOID pParam)//交易线程1改版
{
#define NUMLADDER 11
double ladder_01[NUMLADDER] = {-100,-80,-60,-40,-20,0,20,40,60,80,100};//暂时设11档,一定要正负对称且呈阶梯状,否则逻辑混乱
int needAmount_01[NUMLADDER] = {5,4,3,2,1,0,-1,-2,-3,-4,-5};//每档对应的持仓数量
int holdA50_01 = 0;//A50持有数量
int holdIf_01 = 0;//IF持有数量
int needHoldA50_01 = 0;//A50应该持有数量
int needHoldIf_01 = 0;//IF应该持有数量
int nowLadder_01 = 0;//当前梯级
bool isFirst = true;//第一次操作
bool isFilledSectionLeft = false;//本区间左侧目标位的买卖操作是否完成
bool isFilledSectionRight = false;//本区间右侧目标位的买卖操作是否完成
int nowSection = 4444;//当前所在的区间,由左端点决定,取4444的初值表示还未找到区间
if(clientDlg == NULL){
return -1;
}
if(pUserApi == NULL){
return -1;
}
//从对话框初始化
datumDiff = clientDlg->m_DeltaDatumDiff + clientDlg->m_datumDiff;
#ifdef _debug
holdA50_01 = 50;
#endif
while(true){
UpdateTrade.Lock(INFINITE);//事件触发
//获取系统时间
SYSTEMTIME sys;
GetLocalTime(&sys);
CString PREMIUM;
calDeviation();
deviationHigh_save = deviationHigh;
deviationLow_save = deviationLow;
PREMIUM.Format(_T("%.4f"),premiumLow);
clientDlg->SetDlgItemTextA(IDC_EDIT18,PREMIUM);
PREMIUM.Format(_T("%.4f"),premiumHigh);
clientDlg->SetDlgItemTextA(IDC_EDIT16,PREMIUM);
//非交易日返回
if(!isTradeDay(sys.wYear,sys.wMonth,sys.wDay))
{
continue;
}
//非常规交易时间
if((sys.wHour == 9 && sys.wMinute < 10) ||
(sys.wHour == 15 && sys.wMinute > 15) ||
(sys.wHour == 11 && sys.wMinute > 30) ||
(sys.wHour == 12)||
(sys.wHour < 9) || (sys.wHour > 15)){
continue;
}
if(clientDlg->tradeEnd){//终止
//做清空处理,重新启动时会初始化
return -1;
}
if(clientDlg->stop){//暂停
continue;
}
if(_isnan(datumDiff) != 0 || _isnan(premium)!=0 ||_isnan(deviation)!=0){
continue;//判断非零值错误
}
if(deviationHigh >= 100 || deviationLow <= -100){
continue;//超过范围,返回
}
for(int i = 0;i <= NUMLADDER - 1;i++){//计算当前的区间位置
if(deviationLow >= ladder_01[i] && deviationHigh <= ladder_01[i + 1]){
if(isFirst){
nowSection = i;
isFirst = false;
break;
}
else{
if(nowSection != i){
nowSection = i;
break;
}
}
}
}
if(nowSection == 4444){
continue;//还未找到区间,返回重新寻找
}
bool isFilledL = false,isFilledR = false;
int needA50L = 0,needA50R = 0;
int needIfL = 0,needIfR = 0;
needIfL = -needAmount_01[nowSection];
needIfR = -needAmount_01[nowSection + 1];
needA50L = needAmount_01[nowSection] * multiply;
needA50R = needAmount_01[nowSection + 1] * multiply;
//强平
if(holdA50_01 > needA50L){
//FTA50(holdA50_01 - needA50L,false);
holdA50_01 = needA50L;
}
if(holdIf_01 < needIfL){
//FTIF(needIfL - holdIf_01,true);
holdIf_01 = needIfL;
}
if(holdA50_01 < needA50R){
//FTA50(needA50R - holdA50_01,true);
//.........这里部分代码省略.........
示例5: TradeEntry_00
//只能开启一个交易线程,否则同步可能出现问题
UINT TradeEntry_00(LPVOID pParam)//启动入口,作为一个独立的线程
{
CThostFtdcQryInstrumentField req;
memset(&req, 0, sizeof(req));
strcpy(req.InstrumentID, INSTRUMENT_ID);
::EnterCriticalSection(&REQUEST_ID_IF);
int iResult = pUserApi->ReqQryInstrument(&req, ++iRequestID);
::LeaveCriticalSection(&REQUEST_ID_IF);
CThostFtdcQryInvestorPositionField req00;
memset(&req00, 0, sizeof(req00));
strcpy(req00.BrokerID, BROKER_ID);
strcpy(req00.InvestorID, INVESTOR_ID);
strcpy(req00.InstrumentID, INSTRUMENT_ID);
::EnterCriticalSection(&REQUEST_ID_IF);
iResult = pUserApi->ReqQryInvestorPosition(&req00, ++iRequestID);
::LeaveCriticalSection(&REQUEST_ID_IF);
#ifdef _debug
iNextOrderRef++;//测试
ifAsk1 = 2180;//
IfInData *data;//测试
data = new IfInData(1,false,true,iNextOrderRef); //测试
AfxBeginThread(IfEntry,data,THREAD_PRIORITY_NORMAL,0,0,NULL);//测试
return 0;//测试
#endif
if(clientDlg == NULL){
return -1;
}
if(pUserApi == NULL){
return -1;
}
//从对话框初始化
step = clientDlg->m_step;
multiply = clientDlg->m_multiply;
aimOfLadder = clientDlg->m_aimOfLadder;
datumDiff = clientDlg->m_DeltaDatumDiff + clientDlg->m_datumDiff;
HoldAndDirec tempIni;
tempIni.price = clientDlg->m_costINI - datumDiff;//持仓相对价格
tempIni.numDirec = clientDlg->m_numINI;//带有方向的持仓
holdHedge.push_back(tempIni);
netHold = tempIni.numDirec;
//溢价和基差计算
while(true){
UpdateTrade.Lock(INFINITE);//事件触发
//获取系统时间
//SYSTEMTIME sys;
//GetLocalTime(&sys);
CString PREMIUM;
calDeviation();
deviationHigh_save = deviationHigh;
deviationLow_save = deviationLow;
PREMIUM.Format(_T("%.4f"),premiumLow);
clientDlg->SetDlgItemTextA(IDC_EDIT18,PREMIUM);
PREMIUM.Format(_T("%.4f"),premiumHigh);
clientDlg->SetDlgItemTextA(IDC_EDIT16,PREMIUM);
/*
//非交易日返回
if(!isTradeDay(sys.wYear,sys.wMonth,sys.wDay))
{
continue;
}
//非常规交易时间
if((sys.wHour == 9 && sys.wMinute < 10) ||
(sys.wHour == 15 && sys.wMinute > 15) ||
(sys.wHour == 11 && sys.wMinute > 30) ||
(sys.wHour == 12)||
(sys.wHour < 9) || (sys.wHour > 15)){
continue;
}
*/
if(clientDlg->tradeEnd){//终止
//做清空处理,重新启动时会初始化
holdHedge.clear();
netHold = 0;
return -1;
}
if(clientDlg->stop){//暂停
continue;
}
if(_isnan(datumDiff) != 0 || _isnan(premium)!=0 ||_isnan(deviation)!=0){
continue;//判断非零值错误
}
::EnterCriticalSection(&g_A50Price);
::EnterCriticalSection(&g_IfPrice);
::EnterCriticalSection(&g_index);
if(a50Bid1 < 1 || a50Ask1 < 1 || ifAsk1 < 1 || ifBid1 < 1 || A50Index < 1 || HS300Index < 1){
::LeaveCriticalSection(&g_IfPrice);
::LeaveCriticalSection(&g_A50Price);
::LeaveCriticalSection(&g_index);;
continue;
}
else{
::LeaveCriticalSection(&g_IfPrice);
::LeaveCriticalSection(&g_A50Price);
::LeaveCriticalSection(&g_index);
}
if(fabs(premium) > 300 || fabs(premium) < 0.01){
continue;//排除开盘时有可能报价不全导致的错误溢价计算
//.........这里部分代码省略.........