本文整理汇总了C++中ReleaseMutex函数的典型用法代码示例。如果您正苦于以下问题:C++ ReleaseMutex函数的具体用法?C++ ReleaseMutex怎么用?C++ ReleaseMutex使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReleaseMutex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NetlibUPnPCleanup
void NetlibUPnPCleanup(void*)
{
if (db_get_b(NULL, "Netlib", "NLEnableUPnP", 1) == 0)
// upnp is disabled globally, no need for a cleanup
return;
{
int incoming = 0;
mir_cslock lck(csNetlibUser);
for (int i=0; i < netlibUser.getCount(); i++)
if (netlibUser[i]->user.flags & NUF_INCOMING) {
incoming = 1;
break;
}
if (!incoming)
return;
}
if (findUPnPGateway())
{
char* szData = (char*)alloca(4096);
char buf[50], lip[50];
unsigned i, j = 0, k, num = 100;
WORD ports[30];
strcpy(lip, inet_ntoa(locIP.sin_addr));
WaitForSingleObject(portListMutex, INFINITE);
if (httpTransact(szCtlUrl, szData, 4096, "PortMappingNumberOfEntries", ControlQuery) == 200 &&
txtParseParam(szData, "QueryStateVariableResponse", "<return>", "<", buf, sizeof(buf)))
num = atol(buf);
for (i=0; i<num && !Miranda_Terminated(); i++)
{
mir_snprintf(szData, 4096, get_port_mapping, i);
ReleaseMutex(portListMutex);
WaitForSingleObject(portListMutex, INFINITE);
if (httpTransact(szCtlUrl, szData, 4096, "GetGenericPortMappingEntry", ControlAction) != 200)
break;
if (!txtParseParam(szData, "<NewPortMappingDescription", ">", "<", buf, sizeof(buf)) || strcmp(buf, "Miranda") != 0)
continue;
if (!txtParseParam(szData, "<NewInternalClient", ">", "<", buf, sizeof(buf)) || strcmp(buf, lip) != 0)
continue;
if (txtParseParam(szData, "<NewExternalPort", ">", "<", buf, sizeof(buf)))
{
WORD mport = (WORD)atol(buf);
if (j >= SIZEOF(ports))
break;
for (k = 0; k<numports; ++k)
if (portList[k] == mport)
break;
if (k >= numports)
ports[j++] = mport;
}
}
ReleaseMutex(portListMutex);
for (i=0; i<j && !Miranda_Terminated(); i++)
NetlibUPnPDeletePortMapping(ports[i], "TCP");
}
}
示例2: pthread_mutex_unlock
static int pthread_mutex_unlock(pthread_mutex_t *mutex) {
return ReleaseMutex(*mutex) == 0 ? -1 : 0;
}
示例3: lock_release
/*
* Release a lock previously held.
*/
VOID lock_release( LOCK * lock )
{
if( lock != NULL ) {
ReleaseMutex( lock->handle );
}
}
示例4: Z_Free
//.........这里部分代码省略.........
memtag_t tag = Z_GetTag(header);
if (tag != TAG_STATIC)
{
#ifndef _GAMECUBE
WaitForSingleObject(s_Mutex, INFINITE);
#endif
// Determine size of header and footer
int header_size = sizeof(ZoneHeader);
int align_size = Z_GetAlign(header);
int footer_size = 0;
int data_size = Z_GetSize(header);
if (Z_IsTagLinked(tag))
{
header_size += sizeof(ZoneLinkHeader);
}
if (Z_IsTagTemp(tag))
{
footer_size += align_size;
}
else
{
header_size += align_size;
}
#ifdef _DEBUG
header_size += sizeof(ZoneDebugHeader);
footer_size += sizeof(ZoneDebugFooter);
#endif
int real_size = data_size + header_size + footer_size;
// Update the stats
s_Stats.m_SizeAlloc -= data_size;
s_Stats.m_OverheadAlloc -= header_size + footer_size;
s_Stats.m_SizesPerTag[tag] -= data_size;
s_Stats.m_CountAlloc--;
s_Stats.m_CountsPerTag[tag]--;
// Delink block
if (Z_IsTagLinked(tag))
{
ZoneLinkHeader* linked = (ZoneLinkHeader*)header - 1;
if (linked == s_LinkBase)
{
s_LinkBase = linked->m_Next;
if (s_LinkBase)
{
s_LinkBase->m_Prev = NULL;
}
}
else
{
if (linked->m_Next)
{
linked->m_Next->m_Prev = linked->m_Prev;
}
linked->m_Prev->m_Next = linked->m_Next;
}
assert(Z_ValidateLinks());
}
// Clear the block header for safety
*header = 0;
// Add block to free list
ZoneFreeBlock* nblock = NULL;
if (real_size < sizeof(ZoneFreeBlock))
{
// Not enough space in block to put free information --
// use overflow buffer.
nblock = Z_GetOverflowBlock();
if (nblock == NULL)
{
Z_Details_f();
Com_Error(ERR_FATAL, "Zone free overflow buffer overflowed!");
}
}
else
{
// Place free information in block
nblock = (ZoneFreeBlock*)((char*)pvAddress - header_size);
}
nblock->m_Address = (unsigned int)pvAddress - header_size;
nblock->m_Size = real_size;
Z_LinkFreeBlock(nblock);
// Coalesce any adjacent free blocks
Z_Coalasce(nblock);
#ifndef _GAMECUBE
ReleaseMutex(s_Mutex);
#endif
}
Z_FREE_RETURN( 0 );
}
示例5: time
int
LocalWin32Socket::Read( void* buf, size_t minSize, size_t maxSize,
time_t timeout )
{
time_t start = 0;
char* dst = (char*) buf;
size_t size = 0;
lastError = EC_OK;
if ( timeout != WAIT_FOREVER )
{
start = time( NULL );
timeout *= 1000; // convert seconds to miliseconds
}
while ( size < minSize && state == SS_OPEN )
{
recvBuffer->recvWaitFlag = true;
size_t begin = recvBuffer->dataBeg;
size_t end = recvBuffer->dataEnd;
size_t recvSize =
(begin <= end) ? end - begin : sizeof(recvBuffer->dataBuf) - begin;
if (recvSize > 0)
{
recvBuffer->recvWaitFlag = false;
if ( recvSize >= maxSize )
{
memcpy( dst, &recvBuffer->dataBuf[begin], maxSize );
begin += maxSize;
size += maxSize;
}
else
{
memcpy( dst, &recvBuffer->dataBuf[begin], recvSize );
begin += recvSize;
dst += recvSize;
size += recvSize;
maxSize -= recvSize;
}
recvBuffer->dataBeg = (begin == sizeof(recvBuffer->dataBuf)) ? 0 : begin;
if (recvBuffer->sendWaitFlag)
{
SetEvent(signalHandle[RTR]);
}
}
else
{
HANDLE h[2];
h[0] = signalHandle[RD];
h[1] = mutexHandle;
int rc = WaitForMultipleObjects( 2, h, false, timeout );
recvBuffer->recvWaitFlag = false;
if ( rc != WAIT_OBJECT_0 )
{
if ( rc == WAIT_OBJECT_0+1 || rc == WAIT_ABANDONED+1)
{
SetStreamState( ios::failbit | ios::eofbit );
lastError = EC_BROKEN_PIPE;
ReleaseMutex(mutexHandle);
}
else if ( rc == WAIT_TIMEOUT )
{
return (size);
}
else
{
SetStreamState( ios::failbit );
lastError = GetLastError();
}
return (-1);
}
if ( timeout != WAIT_FOREVER )
{
time_t now = time( NULL );
timeout = timeout >=
(now - start)*1000 ? timeout - (now - start)*1000 : 0;
}
}
}
return (size < minSize ? -1 : (int) size);
}
示例6: WaitForSingleObject
/***************************************************************
【函数功能】: 发送Get报文
【输 入】: addr:模块地址;cmd:get命令;
【输 出】: 执行结果:0正确;-1错误;-2发送失败;
【说 明】: 在timer中被调用。直接通过串口发送。
***************************************************************/
int CSensor::SendGetFrame(char addr, char cmd)
{
UINT sum = 0;
int i;
if(!m_bPortOpened)
return -1;
/**********************************************/
WaitForSingleObject(m_hMutex,1000);
// 占用串口发送资源
m_sCmd.send = (BYTE)cmd;
m_sCmd.stat = STAT_SENSOR_T2T;
m_sCmd.addr = (BYTE)addr;
switch ((BYTE)cmd)
{
case CMD_GET_TDM_INFO:
m_sCmd.ack = CMD_RET_TDM_INFO; // 正常应该回复此命令
break;
case CMD_GET_TDM_DATA:
m_sCmd.ack = CMD_RET_TDM_DATA; // 正常应该回复此命令
break;
case CMD_GET_US_DATA:
m_sCmd.ack = CMD_RET_US_DATA; // 正常应该回复此命令
break;
case CMD_GET_US_ERRCODE:
m_sCmd.ack = CMD_RET_US_ERRCODE;// 正常应该回复此命令
break;
case CMD_GET_IO_BOMA:
m_sCmd.ack = CMD_RET_IO_BOMA; // 正常应该回复此命令
break;
case CMD_GET_IO_MODE:
m_sCmd.ack = CMD_RET_IO_MODE; // 正常应该回复此命令
break;
default:
break;
}
// 准备发送CMD_GET_US_DATA读取超声波测距值
char buf[8] = {0};
buf[0] = 0xAA;
buf[1] = 0x55;
buf[2] = 4;
buf[3] = cmd;
buf[4] = addr;
buf[5] = ADDR_MASTER_DEFAULT;
for(i=0; i<4; i++)
{
sum += (BYTE)buf[i+2];
}
buf[6] = (BYTE)(sum >> 8);
buf[7] = (BYTE)sum;
// 直接通过串口发送,保证时间精度
i = sio_write(m_iPort, buf, 8); // 持续时间大约10us
m_sCmd.stat = STAT_SENSOR_T2R;
ReleaseMutex(m_hMutex);
/**********************************************/
if(i != 8)
return -2;
return 0;
}
示例7: SelectHostIPsByHostName
int SelectHostIPsByHostName(char * hostName, list<string> * v){
char query[300];
char * fixedInsertStr;
unsigned int len;
int holder;
MYSQL_RES * results;
MYSQL_ROW row;
unsigned int numRows = 0, numFields = 0;
MYSQL * conn;
if(hostName == NULL || strlen(hostName) == 0){
printf("SelectHostIPsByHostName(): hostName passed was null\n");
return GENERIC_ERROR;
}
fixedInsertStr = "SELECT ip_str FROM Hosts WHERE hostName like '%s'";
len = sprintf_s(query, 300, fixedInsertStr, hostName);
if(WaitForSingleObject(mysqlMutex, INFINITE) != WAIT_OBJECT_0){
printf("SelectHostIPsByHostName: Couldn't acquire mutex. Returning\n");
return GENERIC_ERROR;
}
conn = OpenDatabaseConnection(gffServerDBName);
if(conn == NULL){
printf("SelectHostIPsByHostName(): OpenDatabaseConnection(gffServerDBName) failed\n");
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
//////////////////////////////////
if(0 != mysql_real_query(conn, query, len)){
holder = CheckError(conn,mysql_errno(conn));
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, holder);
}
results = mysql_store_result(conn);
if(results == NULL){
printf("SelectHostIPsByHostName(): mysql_use_result failed\n");
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
numRows = (unsigned int)mysql_num_rows(results);
if(numRows == 0){
mysql_free_result(results);
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, NO_RESULTS_FOUND);
}
//This function expects that the results will be a single column of strings
for(unsigned int i = 0; i < numRows; i++){
row = mysql_fetch_row(results);
if(row == NULL){
printf("SelectHostIPsByHostName(): mysql_fetch_row failed\n");
mysql_free_result(results);
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
string temp = (string)row[0];
v->push_back(temp);
}
mysql_free_result(results);
//////////////////////////////////
CloseDatabaseConnection(conn);
if(!ReleaseMutex(mysqlMutex)){
printf("SelectHostIPsByHostName(): Couldn't release mutex. Exiting thread\n");
return GENERIC_ERROR;
}
return GENERIC_SUCCESS;
}
示例8: SelectAllHostsToMeasureForPolling
//TODO: Document me
int SelectAllHostsToMeasureForPolling(int tolerance, queue<int> * q){
int hostID;
MYSQL_RES * results;
MYSQL_ROW row;
unsigned int len;
int holder;
unsigned int numRows = 0, numFields = 0;
char query[200];
MYSQL * conn;
time_t rawtime;
time (&rawtime);
unsigned int tempTimeStamp = (unsigned int)rawtime;
tempTimeStamp = tempTimeStamp - (unsigned int)tolerance;
if(WaitForSingleObject(mysqlMutex, INFINITE) != WAIT_OBJECT_0){
printf("SelectAllHostsToMeasureForPolling: Couldn't acquire mutex. Returning\n");
return GENERIC_ERROR;
}
conn = OpenDatabaseConnection(gffServerDBName);
if(conn == NULL){
printf("SelectAllHostsToMeasureForPolling: OpenDatabaseConnection(gffServerDBName) failed\n");
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
len = sprintf_s(query, 200, "SELECT hostID FROM HostsToMeasure WHERE readiness = %u and lastTimeMeasurementRequested < %u",READY, tempTimeStamp);
//////////////////////////////////
if(0 != mysql_real_query(conn, query, len)){
holder = CheckError(conn,mysql_errno(conn));
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, holder);
}
results = mysql_store_result(conn);
if(results == NULL){
printf("SelectAllHostsToMeasureForPolling: mysql_use_result failed\n");
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
numRows = (unsigned int)mysql_num_rows(results);
if(numRows == 0){//Will fail here if an empty set is returned
mysql_free_result(results);
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, NO_RESULTS_FOUND);
}
//This function expects that the results will be a single column of integers (IDs)
for(unsigned int i = 0; i < numRows; i++){
row = mysql_fetch_row(results);
if(row == NULL){
printf("SelectAllHostsToMeasureForPolling: mysql_fetch_row failed\n");
mysql_free_result(results);
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
hostID = strtoul(row[0], NULL, 10);
q->push(hostID);
}
mysql_free_result(results);
//////////////////////////////////
CloseDatabaseConnection(conn);
if(!ReleaseMutex(mysqlMutex)){
printf("SelectAllHostsToMeasureForPolling: Couldn't release mutex. Exiting thread\n");
return GENERIC_ERROR;
}
return GENERIC_SUCCESS;
}
示例9: SelectAllHostsToMeasure
int SelectAllHostsToMeasure(queue<string> * q, queue<int> * r){
MYSQL_RES * results;
MYSQL_ROW row; //really a char **
string hostIP;
int hostID;
char * endptr = "";
char * fixedInsertStr;
unsigned int len;
int holder;
unsigned int numRows = 0, numFields = 0;
MYSQL * conn;
fixedInsertStr = "SELECT Hosts.id, Hosts.ip_str FROM Hosts INNER JOIN HostsToMeasure WHERE Hosts.id = HostsToMeasure.hostID";
len = strlen(fixedInsertStr);
if(WaitForSingleObject(mysqlMutex, INFINITE) != WAIT_OBJECT_0){
printf("SelectAllHostsToMeasure: Couldn't acquire mutex. Returning\n");
return GENERIC_ERROR;
}
conn = OpenDatabaseConnection(gffServerDBName);
if(conn == NULL){
printf("SelectAllHostsToMeasure: OpenDatabaseConnection(gffServerDBName) failed\n");
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
//////////////////////////////////
if(0 != mysql_real_query(conn, fixedInsertStr, len)){
holder = CheckError(conn,mysql_errno(conn));
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, holder);
}
results = mysql_store_result(conn);
if(results == NULL){
printf("SelectAllHostsToMeasure: mysql_use_result failed\n");
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
numRows = (unsigned int)mysql_num_rows(results);
if(numRows == 0){//Will fail here if an empty set is returned
mysql_free_result(results);
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, NO_RESULTS_FOUND);
}
//This function expects that the results will be a single column of integers (IDs)
for(unsigned int i = 0; i < numRows; i++){
row = mysql_fetch_row(results);
if(row == NULL){
printf("SelectAllHostsToMeasure: mysql_fetch_row failed\n");
mysql_free_result(results);
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
hostID = strtoul(row[0], &endptr, 10);
r->push(hostID);
q->push(row[1]);
}
holder = GENERIC_SUCCESS;
mysql_free_result(results);
//////////////////////////////////
CloseDatabaseConnection(conn);
if(!ReleaseMutex(mysqlMutex)){
printf("SelectAllHostsToMeasure: Couldn't release mutex. Exiting thread\n");
return GENERIC_ERROR;
}
return holder;
}
示例10: SelectModulesToMeasure
//Document me
int SelectModulesToMeasure(vector<string> * v){
MYSQL_RES * results;
MYSQL_ROW row;
char * fixedInsertStr;
unsigned int len;
int holder;
unsigned int numRows = 0, numFields = 0;
MYSQL * conn;
fixedInsertStr = "SELECT moduleName FROM ModulesToMeasure";
len = strlen(fixedInsertStr);
if(WaitForSingleObject(mysqlMutex, INFINITE) != WAIT_OBJECT_0){
printf("SelectModulesToMeasure: Couldn't acquire mutex. Returning\n");
return GENERIC_ERROR;
}
conn = OpenDatabaseConnection(gffServerDBName);
if(conn == NULL){
printf("SelectModulesToMeasure: OpenDatabaseConnection(gffServerDBName) failed\n");
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
//////////////////////////////////
if(0 != mysql_real_query(conn, fixedInsertStr, len)){
holder = CheckError(conn,mysql_errno(conn));
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, holder);
}
results = mysql_store_result(conn);
if(results == NULL){
printf("SelectModulesToMeasure: mysql_use_result failed\n");
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
numRows = (unsigned int)mysql_num_rows(results);
if(numRows == 0){
mysql_free_result(results);
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, NO_RESULTS_FOUND);
}
//This function expects that the results will be a single column of wstrings
for(unsigned int i = 0; i < numRows; i++){
row = mysql_fetch_row(results);
if(row == NULL){
printf("SelectModulesToMeasure: mysql_fetch_row failed\n");
mysql_free_result(results);
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
string temp = (string)row[0];
v->push_back(temp);
}
mysql_free_result(results);
//////////////////////////////////
CloseDatabaseConnection(conn);
if(!ReleaseMutex(mysqlMutex)){
printf("SelectModulesToMeasure: Couldn't release mutex. Exiting thread\n");
return GENERIC_ERROR;
}
return GENERIC_SUCCESS;
}
示例11: SelectDataSetForLimitCalculations
int SelectDataSetForLimitCalculations(unsigned int countFromTimeInSeconds, unsigned int count, queue<unsigned int> * q){
MYSQL_RES * results;
MYSQL_ROW row;
char query[300];
char * fixedInsertStr;
unsigned int len;
MYSQL * conn;
unsigned int counter = 0;
fixedInsertStr = "SELECT meRTTInMicroseconds FROM MeasurementEvents WHERE type = %d and timeInSeconds > %d";
len = sprintf_s(query, 300, fixedInsertStr, SELF_ATTESTATION, countFromTimeInSeconds);
if(WaitForSingleObject(mysqlMutex, INFINITE) != WAIT_OBJECT_0){
printf("SelectDataSetForLimitCalculations: Couldn't acquire mutex. Returning\n");
return GENERIC_ERROR;
}
conn = OpenDatabaseConnection(gffServerDBName);
if(conn == NULL){
printf("SelectDataSetForLimitCalculations: OpenDatabaseConnection(gffServerDBName) failed\n");
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
//////////////////////////////////
if(0 != mysql_real_query(conn, query, len)){
printf("mysql_real_query() failed in SelectDataSetForLimitCalculations\n");
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
results = mysql_store_result(conn);
if(results == NULL){
printf("SelectDataSetForLimitCalculations: mysql_store_result failed\n");
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
if(mysql_num_rows(results) == 0){
mysql_free_result(results);
printf("SelectDataSetForLimitCalculations: mysql_num_rows returned no results\n");
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, NO_RESULTS_FOUND);
}
while(counter < count){
row = mysql_fetch_row(results);
if(row == NULL){
printf("SelectDataSetForLimitCalculations: mysql_fetch_row failed\n");
mysql_free_result(results);
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
q->push((unsigned int)(atoi(row[0])));
counter++;
}
//////////////////////////////////
CloseDatabaseConnection(conn);
if(!ReleaseMutex(mysqlMutex)){
printf("SelectDataSetForLimitCalculations: Couldn't release mutex.\n");
return GENERIC_ERROR;
}
return GENERIC_SUCCESS;
}
示例12: SelectUnfinishedPendingSelfAttestationMeIds
int SelectUnfinishedPendingSelfAttestationMeIds(unsigned int timeLimit, vector<int> * v){
MYSQL_RES * results;
MYSQL_ROW row;
unsigned int len;
int holder;
unsigned int numRows = 0;
MYSQL * conn;
char query[400];
len = sprintf_s(query, 400, "SELECT id FROM pendingmeasurementevents WHERE timeInSeconds < %u AND type = 0", timeLimit);
if(WaitForSingleObject(mysqlMutex, INFINITE) != WAIT_OBJECT_0){
printf("SelectUnfinishedPendingSelfAttestationMeIds: Couldn't acquire mutex. Returning\n");
return GENERIC_ERROR;
}
conn = OpenDatabaseConnection(gffServerDBName);
if(conn == NULL){
printf("SelectUnfinishedPendingSelfAttestationMeIds: OpenDatabaseConnection(gffServerDBName) failed\n");
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
//////////////////////////////////
if(0 != mysql_real_query(conn, query, len)){
holder = CheckError(conn,mysql_errno(conn));
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, holder);
}
results = mysql_store_result(conn);
if(results == NULL){
printf("SelectUnfinishedPendingSelfAttestationMeIds: mysql_use_result failed\n");
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
numRows = (unsigned int)mysql_num_rows(results);
if(numRows == 0){
mysql_free_result(results);
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, NO_RESULTS_FOUND);
}
for(unsigned int i = 0; i < numRows; i++){
row = mysql_fetch_row(results);
if(row == NULL){
printf("SelectUnfinishedPendingSelfAttestationMeIds: mysql_fetch_row failed\n");
mysql_free_result(results);
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
unsigned int temp = strtoul(row[0], NULL, 10);
v->push_back(temp);
}
mysql_free_result(results);
//////////////////////////////////
CloseDatabaseConnection(conn);
if(!ReleaseMutex(mysqlMutex)){
printf("SelectUnfinishedPendingSelfAttestationMeIds: Couldn't release mutex. Exiting thread\n");
return GENERIC_ERROR;
}
return GENERIC_SUCCESS;
}
示例13: CleanUpStaleMatchingPendingEvents
int CleanUpStaleMatchingPendingEvents(me_t * pendingME){
char query[256];
char * fixedInsertStr;
unsigned int len;
unsigned int numRows;
int holder;
MYSQL * conn;
MYSQL_RES * results;
MYSQL_ROW row;
fixedInsertStr = "SELECT id FROM PendingMeasurementEvents WHERE type = %d AND timeInSeconds = %d AND hostID = %d AND overloadedForeignID = %d AND id <> %d AND timeInSeconds < %d AND nonce = %d";
len = sprintf_s(query, 256, fixedInsertStr, pendingME->type, pendingME->timeInSeconds, pendingME->hostID,pendingME->overloadedForeignID,pendingME->id,pendingME->timeInSeconds,pendingME->nonce);
if(WaitForSingleObject(mysqlMutex, INFINITE) != WAIT_OBJECT_0){
printf("CleanUpStaleMatchingPendingEvents: Couldn't acquire mutex. Returning\n");
return GENERIC_ERROR;
}
conn = OpenDatabaseConnection(gffServerDBName);
if(conn == NULL){
printf("CleanUpStaleMatchingPendingEvents: OpenDatabaseConnection(gffServerDBName) failed\n");
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
//////////////////////////////////
if(0 != mysql_real_query(conn, query, len)){
holder = CheckError(conn,mysql_errno(conn));
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, holder);
}
results = mysql_store_result(conn);
if(results == NULL){
printf("CleanUpStaleMatchingPendingEvents: mysql_use_result failed\n");
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
numRows = (unsigned int)mysql_num_rows(results);
if(numRows == 0){
mysql_free_result(results);
CloseDatabaseConnection(conn);
if(!ReleaseMutex(mysqlMutex)){
printf("CleanUpStaleMatchingPendingEvents: Couldn't release mutex.\n");
return GENERIC_ERROR;
}
return GENERIC_SUCCESS;
}
for(unsigned int i = 0; i < numRows; i++){
row = mysql_fetch_row(results);
if(row == NULL){
printf("CleanUpStaleMatchingPendingEvents: mysql_fetch_row failed\n");
mysql_free_result(results);
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
unsigned int temp = (unsigned int)row[0];
fixedInsertStr = "DELETE FROM PendingMeasurementEvents WHERE id = %d";
len = sprintf_s(query, 100, fixedInsertStr, temp);
//if(0 != mysql_real_query(conn, query, len)){
// holder = CheckError(conn,mysql_errno(conn));
// CloseDatabaseConnection(conn);
// return ReleaseMutexAndReturnError(mysqlMutex, holder);
//}
printf("CleanUpStaleMatchingPendingEvents: delete sql = %s\n",query);
}
mysql_free_result(results);
//////////////////////////////////
CloseDatabaseConnection(conn);
if(!ReleaseMutex(mysqlMutex)){
printf("CleanUpStaleMatchingPendingEvents: Couldn't release mutex.\n");
return GENERIC_ERROR;
}
return GENERIC_SUCCESS;
}
示例14: return
Socket*
LocalWin32Socket::Accept()
{
HANDLE h[2];
if ( state != SS_OPEN )
{
return (NULL);
}
ConnectData* cdp = (ConnectData*) sendBuffer->dataBuf;
cdp->processId = GetCurrentProcessId();
cdp->mutexHandle = watchDogMutex;
while (true)
{
SetEvent( signalHandle[RTR] );
int rc = WaitForSingleObject( signalHandle[RD], ACCEPT_TIMEOUT );
if ( rc == WAIT_OBJECT_0 )
{
if ( state != SS_OPEN )
{
lastError = EC_NOT_OPENED;
return (NULL);
}
lastError = EC_OK;
break;
}
else if ( rc != WAIT_TIMEOUT )
{
lastError = GetLastError();
return (NULL);
}
}
LocalWin32Socket* sock = new LocalWin32Socket();
sock->mutexHandle = ((ConnectData*) recvBuffer->dataBuf)->mutexHandle;
AcceptData* adp = (AcceptData*) sendBuffer->dataBuf;
adp->bufferHandle = sock->bufferHandle;
for ( int i = RD; i <= RTT; i++ )
{
adp->signalHandle[(i + TD - RD) & RTT] = sock->signalHandle[i];
}
SetEvent( signalHandle[TD] );
h[0] = signalHandle[RD];
h[1] = sock->mutexHandle;
int rc = WaitForMultipleObjects( 2, h, FALSE, INFINITE );
if ( rc != WAIT_OBJECT_0 )
{
if ( rc == WAIT_OBJECT_0+1 || rc == WAIT_ABANDONED+1 )
{
lastError = EC_BROKEN_PIPE;
ReleaseMutex( mutexHandle );
}
else
{
lastError = GetLastError();
}
delete sock;
return (NULL);
}
return (sock);
}
示例15: SelectTiresiasChecksumByNonceAndBaseAndTimedatestamp
int SelectTiresiasChecksumByNonceAndBaseAndTimedatestamp(self_check_t * selfCheckInput, self_check_t * selfCheckTiresias){
MYSQL_RES * results;
MYSQL_ROW row; //really a char **
unsigned int numRows = 0, numFields = 0;
char query[200];
unsigned int len;
char * fixedSelectStr;
MYSQL * conn;
fixedSelectStr = "SELECT * FROM Checksums WHERE nonce = %#x AND timeDateStamp = %#x AND baseVA = %#x";
len = sprintf_s(query, 200, fixedSelectStr, selfCheckInput->nonce, selfCheckInput->timeDateStamp, selfCheckInput->baseVA);
if(WaitForSingleObject(mysqlMutex, INFINITE) != WAIT_OBJECT_0){
printf("SelectTiresiasChecksumByNonceAndBaseAndTimedatestamp: Couldn't acquire mutex. Returning\n");
return GENERIC_ERROR;
}
conn = OpenDatabaseConnection(gffTiresiasDBName);
if(conn == NULL){
printf("SelectTiresiasChecksumByNonceAndBaseAndTimedatestamp: OpenDatabaseConnection(gffTiresiasDBName) failed\n");
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
//////////////////////////////////
if(0 != mysql_real_query(conn, query, len)){
printf("SelectTiresiasChecksumByNonceAndBaseAndTimedatestamp: mysql_real_query failed\n");
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
results = mysql_store_result(conn);
if(results == NULL){
printf("SelectTiresiasChecksumByNonceAndBaseAndTimedatestamp: mysql_use_result failed\n");
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
numRows = (unsigned int)mysql_num_rows(results);
if(numRows == 0){//Will fail here if an empty set is returned
mysql_free_result(results);
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, NO_RESULTS_FOUND);
}
//There should only ever be one correct checksum value
//for a given combination of nonce/timeDateStamp/baseVA
if(numRows > 1){
mysql_free_result(results);
printf("SelectTiresiasChecksumByNonceAndBaseAndTimedatestamp: More than one checksum found for the nonce/timeDateStamp/baseVA combination. Check tiresias database\n");
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, TOO_MANY_RESULTS_FOUND);
}
row = mysql_fetch_row(results);
if(row == NULL){
printf("SelectTiresiasChecksumByNonceAndBaseAndTimedatestamp: mysql_fetch_row failed\n");
mysql_free_result(results);
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
numFields = mysql_num_fields(results);
if(numFields != (4 + SELF_CHECKSUM_SIZE)){
printf("SelectTiresiasChecksumByNonceAndBaseAndTimedatestamp: mysql_num_fields says we have the wrong number of fields\n");
mysql_free_result(results);
CloseDatabaseConnection(conn);
return ReleaseMutexAndReturnError(mysqlMutex, GENERIC_ERROR);
}
selfCheckTiresias->nonce = selfCheckInput->nonce;
selfCheckTiresias->timeDateStamp = selfCheckInput->timeDateStamp;
selfCheckTiresias->baseVA = selfCheckInput->baseVA;
for(unsigned int i = 0; i < SELF_CHECKSUM_SIZE; i++){
selfCheckTiresias->checksum[i] = strtoul(row[4+i], NULL, 10);
}
mysql_free_result(results);
//////////////////////////////////
CloseDatabaseConnection(conn);
if(!ReleaseMutex(mysqlMutex)){
printf("SelectTiresiasChecksumByNonceAndBaseAndTimedatestamp: Couldn't release mutex. Exiting thread\n");
return GENERIC_ERROR;
}
return GENERIC_SUCCESS;
}