Пример #1
0
/* 
 * Enter and Leave Critical Section 
 */
DWORD
PALAPI 
enterandleavecs( LPVOID lpParam )
{
       
	struct statistics stats;
	int loopcount = REPEAT_COUNT;
	int i;
	DWORD dwStart =0;

	int Id=(int)lpParam;

	//initialize strucutre to hold thread level statistics
	stats.relationId = RELATION_ID;
	stats.processId = USE_PROCESS_COUNT;
	stats.operationsFailed = 0;
	stats.operationsPassed = 0;
	stats.operationsTotal  = 0;
	stats.operationTime    = 0;

	//Wait for main thread to signal event
	if (WAIT_OBJECT_0 != WaitForSingleObject(g_hEvent,INFINITE))
		{
		Fail ("readfile: Wait for Single Object (g_hEvent) failed.  Failing test.\n"
	       "GetLastError returned %d\n", GetLastError()); 
		}
	
	//Collect operation start time
	dwStart = GetTickCount();
	
	//Operation starts loopcount times
	for(i = 0; i < loopcount; i++)
	{

		EnterCriticalSection(&CriticalSectionM);
		/*
		*Do Some Thing once you enter critical section 
		*/		
		incrementCounter();
		LeaveCriticalSection(&CriticalSectionM);

		stats.operationsPassed++;
		stats.operationsTotal++;
	}
	//collect operation end time
	stats.operationTime = GetTickCount() - dwStart;

	/*Trace("\n\n\n\nOperation Time %d\n", stats.operationTime);
	Trace("Operation Passed %d\n", stats.operationsPassed);
	Trace("Operation Total %d\n", stats.operationsTotal);
	Trace("Operation Failed %d\n", stats.operationsFailed); */

	if(resultBuffer->LogResult(Id, (char *)&stats))
	{
		Fail("Error while writing to shared memory, Thread Id is[%d] and Process id is [%d]\n", Id, USE_PROCESS_COUNT);
	}
	
	
    return 0;
}
Пример #2
0
/* This function is executed by the first task.
 */
void task1(void *arg)
{
	VAR_t f;
	
	/* avoid compiler warning */
	(void) arg;

	for(;;) {
	
		f = posFlagGet(flagset, POSFLAG_MODE_GETSINGLE);
		
		nosPrintf("\nfirsttask: going to signal flag %i\n", f);
		
		if(f==1){
			incrementCounter(1);
			posFlagSet(flagset, 2);
			nosPrintf("flag value = %i\n",f);
			task2(arg);
		} 
		
		
		/* do something here and waste some time */
		posTaskSleep(MS(500));
	}
	
	posSemaSignal(semaphore);
	
}
Пример #3
0
void task2(void *arg)
{
	VAR_t f; // flag definition variable
	
	(void) arg;

	for(;;) {
	
		// get the flag status
		f = posFlagGet(flagset, POSFLAG_MODE_GETSINGLE);
		
		if(f==2){
			incrementCounter(2);
		}
		
		/* flag status update */
		posFlagSet(flagset, 3);
		nosPrintf("flag value = %i\n",f);
		
		/* do something here and waste some time */
		posTaskSleep(MS(500));
	}
	
	// next the task
	posSemaSignal(semaphore);
}
Пример #4
0
char *
expandTheorem(int i, char *option)
/**************************************************************************
     purpose: retrieves and expands a \newtheorem into a string
**************************************************************************/
{	
	char s[128], *num;
	int ithm;
	
	if (i<0 || i>=iNewTheoremCount)
		return strdup("");
	
	incrementCounter(NewTheorems[i].numbered_like);
	ithm = getCounter(NewTheorems[i].numbered_like);
	
	if (NewTheorems[i].within) {
		num = FormatUnitNumber(NewTheorems[i].within);
		if (option)
			snprintf(s,128,"%s %s.%d (%s)", NewTheorems[i].caption, num, ithm, option);
		else
			snprintf(s,128,"%s %s.%d", NewTheorems[i].caption, num, ithm);
		free(num);
	} else {
		if (option)
			snprintf(s,128,"%s %d (%s)", NewTheorems[i].caption, ithm, option);
		else
			snprintf(s,128,"%s %d", NewTheorems[i].caption, ithm);
	}
			
	return strdup(s);
}
Пример #5
0
/*************************************************************
************** LFU Page Replacement Algorithm ****************
*************************************************************/
void LFUPageReplacement(){
	int numberOfPageFaults = 0;
	frame = malloc(sizeof(struct frames));
	head = malloc(sizeof(struct frames));
	tail = malloc(sizeof(struct frames));
	head = frame;
	tail = frame;
	frame->next = NULL;
	frame->prev = head;
	frame->pageNum = inputSeq[0];
	frame->counter = 1;
	numberOfPageFaults += 1;
	int i, isPageAlreadyExists = 0;
	for (i=1; i<strlen(inputSeq); i++){
		if (isspace(inputSeq[i]) == 0){
			isPageAlreadyExists = findPage(inputSeq[i]);
			if (isPageAlreadyExists == 1){
				incrementCounter(inputSeq[i]);
			}else if (isPageAlreadyExists == 0 && isFrameAvailable() == 1){
				numberOfPageFaults += 1;
				framesLeft -= 1;
				addPageToTailOfFrame(inputSeq[i]);
			}else if (isPageAlreadyExists == 0 && isFrameAvailable() == 0){
				numberOfPageFaults += 1;
				char victim = findPageWithMinFreq();
				removeNodeFromFrame(victim);
				addPageToTailOfFrame(inputSeq[i]);
			}
		}
	}
	printf("\n# of page replacements with LFU = %d\n",numberOfPageFaults-availableFrames);
	nbOfPageReplacementByAlgo = numberOfPageFaults-availableFrames;
}
Пример #6
0
AbstractCounter::AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent)
    : QGraphicsItem(parent), player(_player), id(_id), name(_name), value(_value), hovered(false), aDec(0), aInc(0), dialogSemaphore(false), deleteAfterDialog(false), shownInCounterArea(_shownInCounterArea)
{
#if QT_VERSION < 0x050000
    setAcceptsHoverEvents(true);
#else
    setAcceptHoverEvents(true);
#endif

    if (player->getLocal()) {
        menu = new QMenu(name);
        aSet = new QAction(this);
        connect(aSet, SIGNAL(triggered()), this, SLOT(setCounter()));
        menu->addAction(aSet);
        menu->addSeparator();
        for (int i = -10; i <= 10; ++i)
            if (i == 0)
                menu->addSeparator();
            else {
                QAction *aIncrement = new QAction(QString(i < 0 ? "%1" : "+%1").arg(i), this);
                if (i == -1)
                    aDec = aIncrement;
                else if (i == 1)
                    aInc = aIncrement;
                aIncrement->setData(i);
                connect(aIncrement, SIGNAL(triggered()), this, SLOT(incrementCounter()));
                menu->addAction(aIncrement);
            }
    } else
        menu = 0;
    
    retranslateUi();
}
Пример #7
0
mapbox::util::variant<Database, Exception> Database::tryOpen(const std::string &filename, int flags) {
    if (!QSqlDatabase::drivers().contains("QSQLITE")) {
        return Exception { ResultCode::CantOpen, "SQLite driver not found." };
    }

    QString connectionName = QString::number(uint64_t(QThread::currentThread())) + incrementCounter();

    assert(!QSqlDatabase::contains(connectionName));
    auto db = QSqlDatabase::addDatabase("QSQLITE", connectionName);

    QString connectOptions = db.connectOptions();
    if (flags & OpenFlag::ReadOnly) {
        if (!connectOptions.isEmpty()) connectOptions.append(';');
        connectOptions.append("QSQLITE_OPEN_READONLY");
    }
    if (flags & OpenFlag::SharedCache) {
        if (!connectOptions.isEmpty()) connectOptions.append(';');
        connectOptions.append("QSQLITE_ENABLE_SHARED_CACHE");
    }

    db.setConnectOptions(connectOptions);
    db.setDatabaseName(QString(filename.c_str()));

    if (!db.open()) {
        // Assume every error when opening the data as CANTOPEN. Qt
        // always returns -1 for `nativeErrorCode()` on database errors.
        return Exception { ResultCode::CantOpen, "Error opening the database." };
    }

    return Database(std::make_unique<DatabaseImpl>(connectionName));
}
Ogre::SceneNode* ParticleFactory::CreateParticleEntity(Ogre::String object_name, Ogre::String material_name,Ogre::SceneNode* parent, Ogre::Vector3 size){

		/* Create one instance of the torus (one entity) */
		/* The same object can have multiple instances or entities */

		/* Create entity */
		Ogre::String name = parent->getName() + object_name;
        //Ogre::Entity* entity = scene_manager->createEntity(object_name);
		Ogre::Entity* entity = scene_manager->createEntity(object_name);

		Ogre::MaterialPtr mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(material_name));
		//mat = mat->clone(object_name.append("_" +material_name.append("_" + Ogre::StringConverter::toString(materialCounter))));
		mat = mat->clone(name.append("_" +material_name.append("_" + Ogre::StringConverter::toString(materialCounter))));

		//std::cout << "NAME: " << name << std::endl;
		//mat = mat->clone(object_name.append(material_name));
		/* Apply a material to the entity */
		entity->setMaterialName(mat->getName());
		//materialArray[numMaterials] = mat->getName();
		materialArray.push_back(mat->getName());
		

		/* Create a scene node for the entity */
		/* The scene node keeps track of the entity's position */
        Ogre::SceneNode* scene_node = parent->createChildSceneNode(mat->getName());
        scene_node->attachObject(entity);
		//scene_node->translate(0.5,0.5,-1);
		incrementCounter();
		/* Scale the entity */
		scene_node->scale(size);
		return scene_node;
}
Пример #9
0
void starttests(int threadID)
{
	/*All threads beign executing tests cases*/	
	int i = 0;
	int Id = threadID;
	struct statistics stats;
	ULONGLONG startTime = 0;
	ULONGLONG endTime = 0;


	stats.relationId = RELATION_ID;
	stats.processId = USE_PROCESS_COUNT;
	stats.operationsFailed = 0;
	stats.operationsPassed = 0;
	stats.operationsTotal  = 0;
	stats.operationTime    = 0;
		
	//Enter and Leave Critical Section in a loop REPEAT_COUNT Times
	
	startTime = GetTicks();

	for (i=0;i<REPEAT_COUNT;i++)
		{
			if (0!=MTXEnterCriticalSection(&g_cs))
				{
					stats.operationsFailed++;
					stats.operationsTotal++;
					continue;
				}
			
			incrementCounter();
				
			if (0!=MTXLeaveCriticalSection(&g_cs))
				{
					stats.operationsFailed++;
					stats.operationsTotal++;
					continue;
				}
			stats.operationsPassed++;
			stats.operationsTotal++;

		}

	stats.operationTime = (DWORD)(GetTicks() - startTime)/callibrationValue;

//	printf("Operation Time %d \n", stats.operationTime);
	
	if(resultBuffer->LogResult(Id, (char *)&stats))
	{
		printf("Error while writing to shared memory, Thread Id is[??] and Process id is [%d]\n", USE_PROCESS_COUNT);
	}
	
}
Пример #10
0
    double SearchStructure::findNearestIntersection(
            const Raycast& raycast,
            RayHitReport& reportMin,
            RayHitList& rayHitList) const
    {
        Raycast ray(raycast);

        size_t minId = -1;

        size_t zId = 0;
        size_t zoneCount = _searchZones.size();
        while(zId < zoneCount)
        {
            const SearchZone& zone = _searchZones[zId];

            if(zone.bounds == StageZone::UNBOUNDED.get() ||
               zone.bounds->intersects(ray, rayHitList))
            {
                for(size_t s = zone.begSurf; s < zone.endSurf; ++s)
                {
                    rayHitList.clear();

                    _searchSurfaces[s]->raycast(ray, rayHitList);

                    RayHitReport* node = rayHitList.head;
                    while(node != nullptr)
                    {
                        if(0.0 < node->length && node->length < ray.limit)
                        {
                            ray.limit = node->length;
                            reportMin = *node;
                            minId = s;
                        }

                        node = node->_next;
                    }
                }

                ++zId;
            }
            else
            {
                zId = zone.endZone;
            }
        }

        if(!_isOptimized && reportMin.length != raycast.limit)
        {
            incrementCounter(_searchSurfaces[minId], ray.entropy);
        }

        return reportMin.length;
    }
Пример #11
0
/* This function is executed by the second task that is set up
 * in the function firsttask() by a call to nosTaskCreate()
 */
void task2(void *arg)
{
  /* avoid compiler warning */
  (void) arg;

  for(;;)
  {
    /* call function */
    incrementCounter(2);

    /* do something here and waste some time */
    posTaskSleep(MS(300));
  }
}
Пример #12
0
/* Worker Thread
 * Enter and Leave Nested Critical Sections
 */
DWORD
PALAPI 
enterandleave_cs( LPVOID lpParam )
{
       
	//Declare Local Variables
	
	CRITICAL_SECTION lcs;
	CRITICAL_SECTION lcsNested;

	 DWORD dwWaitResult;

	//Intialize Critical Section Structures
	InitializeCriticalSection ( &lcs);
	InitializeCriticalSection ( &lcsNested);

	
	//Wait for event to signal to start test	
	dwWaitResult  = WaitForSingleObject(g_hEvent,INFINITE);
	if (WAIT_OBJECT_0 != dwWaitResult)
		{
		Fail ("enterandleave_cs: Wait for Single Object (g_hEvent) failed.  Failing test.\n"
	       "GetLastError returned %d\n", GetLastError()); 
		}
		 
	//Trace("Critical Section Started\n");
	
	while(TRUE)
		{
	EnterCriticalSection(&lcs);

		EnterCriticalSection(&lcsNested);
		
			incrementCounter();

		LeaveCriticalSection(&lcsNested);
		
	LeaveCriticalSection(&lcs);
	//g_enterleavecsoperation++;
		}

	//Delete Critical Section Structures

	DeleteCriticalSection(&lcs);
	DeleteCriticalSection(&lcsNested);
	
	 
    return 0;
}
Пример #13
0
void task3(void *arg)
{
	VAR_t f;
	
	(void) arg;
		
	for(;;) {
	
		f = posFlagGet(flagset, POSFLAG_MODE_GETSINGLE);
		
		if(f==3){
			incrementCounter(3);
		}
			
		posFlagSet(flagset, 1);
		nosPrintf("flag value = %i\n",f);
		
		posTaskSleep(MS(500));
	}
	
	posSemaSignal(semaphore);
}
Пример #14
0
    bool SearchStructure::intersectsScene(
            const Raycast& raycast,
            RayHitList& rayHitList,
            double incomingEntropy) const
    {
        rayHitList.clear();

        size_t zId = 0;
        size_t zoneCount = _searchZones.size();
        while(zId < zoneCount)
        {
            const SearchZone& zone = _searchZones[zId];

            if(zone.bounds == StageZone::UNBOUNDED.get() ||
               zone.bounds->intersects(raycast, rayHitList))
            {
                for(size_t s = zone.begSurf; s < zone.endSurf; ++s)
                {
                    if(_searchSurfaces[s]->intersects(raycast, rayHitList))
                    {
                        if(!_isOptimized)
                            incrementCounter(_searchSurfaces[s],
                                             incomingEntropy);

                        return true;
                    }
                }

                ++zId;
            }
            else
            {
                zId = zone.endZone;
            }
        }

        return false;
    }
Пример #15
0
void _int_(8) isr_t2(void){
	incrementCounter();
	ledsCounter();
	IFS0bits.T2IF = 0;
}
Пример #16
0
static void 
FinishRtfEquation(int code, int EQ_Needed)
{	
	if (EQ_Needed && g_processing_fields==1) {
		fprintRTF("}}{\\fldrslt }}");
		g_processing_fields--;	
	}
	
	switch (code) {
	
		case EQN_MATH:
			diagnostics(4,"FinishRtfEquation -- \\end{math}");
			CmdIndent(INDENT_INHIBIT);
			SetTexMode(MODE_HORIZONTAL);
			break;
	
		case EQN_DOLLAR:
			diagnostics(4,"FinishRtfEquation -- $");
			fprintRTF("}");
			SetTexMode(MODE_HORIZONTAL);
			break;
	
		case EQN_RND_OPEN:	
			diagnostics(4,"FinishRtfEquation -- \\)");
			fprintRTF("}");
			SetTexMode(MODE_HORIZONTAL);
			break;
	
		case EQN_DOLLAR_DOLLAR:
			diagnostics(4,"FinishRtfEquation -- $$");
			CmdEndParagraph(0);
			CmdIndent(INDENT_INHIBIT);
			fprintRTF("}");
			break;
	
		case EQN_BRACKET_OPEN:
			diagnostics(4,"FinishRtfEquation -- \\[");
			SetTexMode(MODE_VERTICAL);
			fprintRTF("\\par\\par\n}");
			break;

		case EQN_DISPLAYMATH:
			diagnostics(4,"FinishRtfEquation -- displaymath");
			CmdEndParagraph(0);
			CmdIndent(INDENT_INHIBIT);
			break;

		case EQN_EQUATION_STAR:
			diagnostics(4,"FinishRtfEquation -- equation*");
			CmdEndParagraph(0);
			CmdIndent(INDENT_INHIBIT);
			break;

		case EQN_ARRAY_STAR:
			diagnostics(4,"FinishRtfEquation -- eqnarray* ");
			CmdEndParagraph(0);
			CmdIndent(INDENT_INHIBIT);
			g_processing_eqnarray = FALSE;
			g_processing_tabular = FALSE;
			break;

		case EQN_EQUATION:
		case EQN_ARRAY:
		    diagnostics(4,"FinishRtfEquation --- equation or eqnarray");
			if (g_show_equation_number && !g_suppress_equation_number) {
				char number[20];
				incrementCounter("equation");
				for (; g_equation_column < 3; g_equation_column++)
						fprintRTF("\\tab ");
				fprintRTF("\\tab{\\b0 (");
				sprintf(number,"%d",getCounter("equation"));
				InsertBookmark(g_equation_label,number);
				if (g_equation_label) {
					free(g_equation_label);
					g_equation_label = NULL;
				}
				fprintRTF(")}");
			}
			g_processing_eqnarray = FALSE;
			g_processing_tabular = FALSE;
			CmdEndParagraph(0);
			CmdIndent(INDENT_INHIBIT);
			break;
			
		default:
			diagnostics(ERROR, "calling FinishRtfEquation with OFF code");
			break;
		}
}
Пример #17
0
void _int_(4) isr_t1(void){
	incrementCounter();
	ledsCounter();
	IFS0bits.T1IF = 0;
}