int main(void) { double * data; double start, finish; data = createDataArray(); #ifndef PREF // The branch with no prefetch poisonCache(); printf("Simple start\n"); start = getTimeInSeconds(); simpleSumm(data); finish = getTimeInSeconds(); printf("Simple seconds: %f\n", finish - start); #else // The branch with regular prefetch poisonCache(); printf("Prefetch start\n"); start = getTimeInSeconds(); prefetchSumm(data); finish = getTimeInSeconds(); printf("Prefetch seconds: %f\n", finish - start); #endif // PREF deleteDataArray(data); }
bool PorscheSteeringWheel::homeWheel() { bool run; bool success = true; unsigned char pdodata[8]; //std::cerr << "Starting node... "; if (!startNode()) success = false; //std::cerr << "Enabling operation... "; if (!enableOp()) success = false; //std::cerr << "Setting operation mode... "; if (!setOpMode(6)) success = false; //std::cerr << "Setting up homing mode... "; if (!setupHoming(0, 33, 100000, 10)) success = false; ; //std::cerr << "Starting homing... "; if (!enableHoming()) success = false; //std::cerr << "Waiting till homing is finished... "; run = true; unsigned long starttime = getTimeInSeconds(); while (run) { bus->recvPDO(1, 1, pdodata); if ((pdodata[1] & 0x14) == 0x14) run = false; if ((getTimeInSeconds() - starttime) > 10) { run = false; success = false; } std::cerr << "Elapsed time: " << (getTimeInSeconds() - starttime) << std::endl; } //std::cerr << "homing finished!" << std::endl; //std::cerr << "Shutting down... "; if (!shutdown()) success = false; //std::cerr << "Stopping node... "; if (!stopNode()) success = false; return success; }
bool AvalancheEngine::saveGame(const int16 slot, const Common::String &desc) { Common::String fileName = getSaveFileName(slot); Common::OutSaveFile *f = g_system->getSavefileManager()->openForSaving(fileName); if (!f) { warning("Can't create file '%s', game not saved.", fileName.c_str()); return false; } f->writeUint32LE(MKTAG('A', 'V', 'A', 'L')); // Write version. We can't restore from obsolete versions. f->writeByte(kSavegameVersion); f->writeUint32LE(desc.size()); f->write(desc.c_str(), desc.size()); Graphics::saveThumbnail(*f); TimeDate t; _system->getTimeAndDate(t); f->writeSint16LE(t.tm_mday); f->writeSint16LE(t.tm_mon); f->writeSint16LE(t.tm_year); _totalTime += getTimeInSeconds() - _startTime; Common::Serializer sz(NULL, f); synchronize(sz); f->finalize(); delete f; return true; }
void getAudioDevices(AudioDevicePath* adPath, int* count) { int maxCount = *count; char* audiodev; char devsound[15]; int i; long timeInSeconds = getTimeInSeconds(); if (globalADCount < 0 || (getTimeInSeconds() - globalADCacheTime) > AD_CACHE_TIME || (adPath != globalADPaths)) { *count = 0; // first device, if set, is AUDIODEV variable audiodev = getenv("AUDIODEV"); if (audiodev != NULL && audiodev[0] != 0) { addAudioDevice(audiodev, adPath, count); } // then try /dev/audio addAudioDevice("/dev/audio", adPath, count); // then go through all of the /dev/sound/? devices for (i = 0; i < 100; i++) { sprintf(devsound, "/dev/sound/%d", i); if (!addAudioDevice(devsound, adPath, count)) { break; } } if (adPath == globalADPaths) { /* commit cache */ globalADCount = *count; /* set cache time */ globalADCacheTime = timeInSeconds; } } else { /* return cache */ *count = globalADCount; } // that's it }
int main(char **argv, char argc) { int *allocationArray, *workArray, *maxArray, *requestedResources, *needArray, *waitingQueue, *maxAvailableResources, *releaseResources; int numProc; int numRes; int onProc; int i; int startTime; int simTime; int totalBytesToAllocate; int numSecs; char resourceTypes[256]; char numInstances[256]; char numProcesses[256]; char detailsOfPx[256]; /* Set up the signal handler to handle CTRL C requests */ (void) signal(SIGINT, signalHandler); /* Clear out the arrays before using them */ memset((char*)&resourceTypes, 0, sizeof(resourceTypes)); memset((char*)&numInstances, 0, sizeof(numInstances)); memset((char*)&numProcesses, 0, sizeof(numProcesses)); memset((char*)&detailsOfPx, 0, sizeof(detailsOfPx)); /* Gather input from user -- assuming correct input only */ printf("Number of different resource types: "); scanf(" %[^\n]", resourceTypes); numRes = atoi(resourceTypes); numProc = atoi(resourceTypes); printf("Number of instances of each resource type :"); scanf(" %[^\n]", numInstances); printf("Number of processes: "); scanf(" %[^\n]", numProcesses); numProc = atoi(numProcesses); totalBytesToAllocate = numProc*numRes*sizeof(int); /* Allocate memory for a number of different arrays that are used in this program */ allocationArray = malloc(totalBytesToAllocate); workArray = malloc(numRes * sizeof(int)); maxArray = malloc(totalBytesToAllocate); needArray = malloc(totalBytesToAllocate); waitingQueue = malloc(numProc * sizeof(int)); requestedResources = malloc(totalBytesToAllocate); maxAvailableResources = malloc(numRes * sizeof(int)); releaseResources = malloc(numRes * sizeof(int)); /* Clear out all of the useful arrays before using them */ memset((int*)allocationArray, 0,totalBytesToAllocate); memset((int*)workArray, 0, numRes * sizeof(int)); memset((int*)releaseResources, 0, numRes * sizeof(int)); memset((int*)maxAvailableResources, 0, numRes * sizeof(int)); memset((int*)maxArray, 0, totalBytesToAllocate); memset((int*)waitingQueue, 0, numProc * sizeof(int)); memset((int*)requestedResources, 0, totalBytesToAllocate); /* Store the data from the max array */ storeTheData(numInstances, workArray, 0); for (i = 0; i < numProc; i++) { onProc = i * numRes; printf("Details of P%d: ",i+1); scanf(" %[^\n]", detailsOfPx); storeTheData(detailsOfPx, maxArray, onProc); } computeMaxAvailableResources(maxAvailableResources, allocationArray, workArray, numProc, numRes); /* The need array is simply a copy of the max array in the beginning since we started with zero resources allocated */ memcpy(needArray,maxArray, numProc*numRes * sizeof(int) ); startTime = getTimeInSeconds(); simTime = startTime; numSecs = 4; printf("Hello. Please read the README if you can. Thank you. :) \n"); while (1) { /* Every five seconds, we make an action for each process -- but it is 4 the first time */ if (getTimeInSeconds() - simTime >= numSecs) { simTime = getTimeInSeconds(); /* Run all of the processes in a loop whereby each chooses one possible action */ runProcesses(allocationArray, workArray, maxArray,\ requestedResources, needArray, waitingQueue, maxAvailableResources, releaseResources, numProc, numRes); } numSecs = 5; } return 0; }
/* get current time seconds function */ long rfc::Time::getSeconds() const { return getTimeInSeconds() % 60; } /* end of 'rfc::Time::getSeconds' function */
/* get current time IN minutes function. * This function returns all time only in seconds. * For example - 2 hours returns 120 minutes. */ long rfc::Time::getTimeInMinutes() const { return getTimeInSeconds() / 60; } /* end of 'rfc::Time::getMinutes' function */