void generateRun(int thread, int startMode, bool doUpgrades, bool doNonBlock) { if (thread == nProcs) { doRun(); return; } testPerProc_t *pls = PERPROC(&procs[thread]); for (int mode1 = startMode; mode1 < NUM_MODES; ++mode1) { pls->testMode1 = mode1; pls->testMode1DontWait = false; pls->testMode2 = -1; pls->testMode2DontWait = false; generateRun(thread + 1, mode1, doUpgrades, doNonBlock); if (doNonBlock) { pls->testMode1DontWait = true; generateRun(thread + 1, mode1, doUpgrades, doNonBlock); pls->testMode1DontWait = false; } if (doUpgrades) { for (int mode2 = 0; mode2 < NUM_MODES; ++mode2) { if (mode1 == mode2) continue; pls->testMode2 = mode2; generateRun(thread + 1, mode1, doUpgrades, doNonBlock); if (doNonBlock) { pls->testMode2DontWait = true; generateRun(thread + 1, mode1, doUpgrades, doNonBlock); pls->testMode2DontWait = false; } } } } }
int main(int argc, char **argv) { int threads = 2, switches = 7, doUpgrades = 0, doNonBlock = 0; //int threads = 2, switches = 7, doUpgrades = 0, doNonBlock = 1; //int threads = 3, switches = 5, doUpgrades = 0, doNonBlock = 1; //int threads = 4, switches = 3, doUpgrades = 0, doNonBlock = 0; procInit(resetLock, switches); assert(NUM_MODES <= LC_MAX_MODES); lcInitConflictTable(&conflictTable, conflicts, NUM_MODES); gslLockInit(&theLock, NULL); for (int i = 0; i < threads; ++i) { char name[2] = {i + 'A', 0}; proc_t *proc = procAdd(name, testLock); testPerProc_t *perProc = calloc(1, sizeof *perProc); proc->user = perProc; } generateRun(0, 0, doUpgrades, doNonBlock); return 0; }
Status SortedFile::sortFile() { Status status; Record rec; // Open source file. // Start an unfiltered sequential scan. if (!(file = new HeapFileScan(fileName, 0, 0, STRING, NULL, EQ, status))) return INSUFMEM; if (status != OK) return status; // As long as the source file has more records, collect up to // maxItems records into buffer and then dump records into // temporary file. do { for(numItems = 0; numItems < maxItems; numItems++) { // Fetch next record from source file, check if end of file. if ((status = file->scanNext(buffer[numItems].rid)) == FILEEOF) break; else if (status != OK) return status; if ((status = file->getRecord(buffer[numItems].rid, rec)) != OK) return status; // Create space for holding a copy of the sorting attribute // only (rest of record is read when temporary file is // written). Copy sorting attribute from source record and // store the length of the attribute (reccmp is general- // purpose and can be shared by multiple instances of // SortedFile!). if (!(buffer[numItems].field = new char [length])) return INSUFMEM; memcpy(buffer[numItems].field, (char *)rec.data + offset, length); buffer[numItems].length = length; } // If at least 1 record in sub-run, sort records and write out // to temporary file. if (numItems > 0) { if ((status = generateRun(numItems)) != OK) return status; for(int i = 0; i < numItems; i++) delete [] buffer[i].field; } } while (numItems > 0); // Terminate sequential scan on source file and close file. delete file; // Prepare a sequential scan on each sub-run so that next() // can fetch next record from each run. if ((status = startScans()) != OK) return status; return OK; }