sIntBasePtr ShGcInt::bitwiseOr(sIntBasePtr& a, sIntBasePtr & b) { if (a->bitCount() != b->bitCount()) throw RTE_LOC; auto aa = getMemory(a); auto bb = getMemory(b); auto ret(new ShGcInt(mRt, a->bitCount())); ShGc::CircuitItem workItem; workItem.mInputBundleCount = 2; workItem.mLabels.resize(3); workItem.mLabels[0] = aa; workItem.mLabels[1] = bb; workItem.mLabels[2] = ret->mLabels; workItem.mCircuit = mRt.mLibrary.int_int_bitwiseOr( workItem.mLabels[0]->size(), workItem.mLabels[1]->size(), workItem.mLabels[2]->size()); mRt.enqueue(std::move(workItem)); return sIntBasePtr(ret); }
ResultCode ObjectMemoryDeferFree::run() throw() { const double minDuration = 0.000001; const double maxDuration = 0.1; double duration = minDuration; while (! getShouldExit()) { plonk_assert (getMemory().getUserData() == this); Element d = queue->pop(); if (d.ptr != 0) { duration = minDuration; // reset back to high speed staticDoFree (this, d.ptr); } else { // gradually increase the amount of sleep if the queue is empty duration = plonk::min (duration * 2.0, maxDuration); } Threading::sleep (duration); } getMemory().resetFunctions(); queue->clearAll(); return 0; }
TEST_F(ListTest, CanRemoveItemFromMiddleOfList) { auto list = new Utils::List<FooMock>(getMemory(), listCapacity); list->emplace(); list->emplace(); FooMock& deletedItem = list->emplace(); list->emplace(); list->emplace(); EXPECT_EQ(5, list->size()); list->eraseAt(2); for(auto i = 0; i < list->size(); i++) { uint32_t number = (*list)[i].Quack(); EXPECT_EQ(FooMock::fooConst, number); } EXPECT_EQ(4, list->size()); EXPECT_EQ(sizeof(FooMock) * list->capacity(), getMemory().getAllocationSize(list->begin())); ::testing::Mock::VerifyAndClearExpectations(&deletedItem); delete list; }
sIntBasePtr ShGcInt::ifelse(sIntBasePtr& a, sIntBasePtr & ifTrue, sIntBasePtr & ifFalse) { auto aa = getMemory(a); auto tt = getMemory(ifTrue); auto ff = getMemory(ifFalse); auto ret(new ShGcInt(mRt, tt->size())); sIntBasePtr rret(ret); ShGc::CircuitItem workItem; workItem.mInputBundleCount = 3; workItem.mLabels.resize(4); workItem.mLabels[0] = tt; workItem.mLabels[1] = ff; workItem.mLabels[2] = aa; workItem.mLabels[3] = ret->mLabels; if (workItem.mLabels[0]->size() != workItem.mLabels[1]->size() || workItem.mLabels[0]->size() != workItem.mLabels[3]->size()) throw std::runtime_error("IfElse must be performed with variables of the same bit length. " LOCATION); if (workItem.mLabels[2]->size()!= 1) throw std::runtime_error(LOCATION); workItem.mCircuit = mRt.mLibrary.int_int_multiplex(workItem.mLabels[0]->size()); mRt.enqueue(std::move(workItem)); return rret; }
ObjectMemoryDeferFree::~ObjectMemoryDeferFree() { setShouldExitAndWait(); // the thread clears the queues //<-- something could happen here on another thread but we should be shut down by now..? getMemory().resetUserData(); getMemory().resetFunctions(); delete queue; }
void Assoc::setPointer(const char *id, void *data) { unsigned idx = getIndex(id); entry *e = (entry *)getMemory(sizeof(entry)); e->id = (const char *)getMemory(strlen(id) + 1); strcpy((char *)e->id, id); e->data = data; e->next = entries[idx]; entries[idx] = e; }
TEST_F(ListTest, CanCreateListWithCapacity) { auto list = new Utils::List<FooMock>(getMemory(), listCapacity); EXPECT_NE(nullptr, list); EXPECT_EQ(list->capacity(), listCapacity); EXPECT_EQ(sizeof(FooMock) * listCapacity, getMemory().getAllocationSize(list->begin())); delete list; }
TEST_F(ListTest, CanAddItemToList) { auto list = new Utils::List<FooMock>(getMemory(), listCapacity); list->emplace(); EXPECT_EQ(1, list->size()); EXPECT_EQ(sizeof(FooMock) * list->capacity(), getMemory().getAllocationSize(list->begin())); delete list; }
ObjectMemoryDeferFree::ObjectMemoryDeferFree (Memory& m) throw() : ObjectMemoryBase (m), Threading::Thread ("Memory Deferred Free Thread") { setPriority (0); getMemory().resetUserData(); getMemory().resetFunctions(); AtomicOps::memoryBarrier(); queue = new LockFreeQueue<Element>; AtomicOps::memoryBarrier(); getMemory().setUserData (this); getMemory().setFunctions (staticAlloc, staticFree); }
int main(int argc, char *argv[]) { int *memAddr; int semID; if(argc != 3) { printf("You have to pass pathname and ID!\n"); exit(EXIT_FAILURE); } key_t key = ftok(argv[1], atoi(argv[2])); if(key < 0) { printf("Error while creating a key!\n"); exit(EXIT_FAILURE); } memAddr = getMemory(key, 0); if((semID = semget(key, SEMVALUE, 0)) == -1) { printf("Error while getting semID!\n"); exit(EXIT_FAILURE); } consume(memAddr, semID); return EXIT_SUCCESS; }
bool JdbcUtil::removeMemory(void) { setError(NULL); if (!getMemory(false)) { // If not found, it does not exist if (errorCode == ENOENT) return true; return false; } // deactivate the old memory in case some still has it attached if (attachMemory()) { sharedMemory->active = false; detachMemory(); } // Remove the memory if (shmctl(sharedMemoryId,IPC_RMID,NULL)==-1) { setPerror("Cannot remove shared memory"); return false; } sharedMemoryId = -1; return true; }
bool JdbcUtil::attachMemory(void) { setError(NULL); // If we have not accessed the memory, get it // only if it has already been created. if ((sharedMemoryId==-1) && !getMemory(false)) return false; if (sharedMemory && !sharedMemory->active) { // We are attached to an old memory segment. // Detach it so we can attach the new one. if (!detachMemory()) return false; } if (sharedMemory==NULL) { // At this point we have an id to the memory, now we // can attach it. void *shm; if ((shm = shmat(sharedMemoryId, NULL, 0)) == (void *) -1) { setPerror("Cannot attach shared memory"); return false; } sharedMemory = (struct JdbcUtilMemoryStruct *) shm; } return true; }
void channelDisplay::drawArray() { ofPushMatrix(); ofTranslate(ax,ay,0); float mx = (float) aw / (float) (len-1); float my = (float) ah / 1.0f; ofFill(); ofSetColor(255,0,0); ofBeginShape(); ofVertex(0,ah); for(int i=0; i<len; i++) { ofVertex(i*mx, ah-getMemory(i)*my); } ofVertex((len-1)*mx,ah); ofEndShape(); // draw outline ofSetColor(0,0,0); ofNoFill(); ofRect(0,0,aw,ah); ofPopMatrix(); }
TEST_F(ListTest, CanRemoveItemFromList) { auto list = new Utils::List<FooMock>(getMemory(), listCapacity); list->emplace(); EXPECT_EQ(1, list->size()); EXPECT_CALL((*list)[0], Die()); list->eraseAt(0); EXPECT_EQ(0, list->size()); EXPECT_EQ(sizeof(FooMock) * list->capacity(), getMemory().getAllocationSize(list->begin())); delete list; }
void* UI_Memtools::getClearedMemory( unsigned long size ) { void *ptr; ptr = getMemory(size); memset(ptr, 0, size); return ptr; }
void* IMemory::pointer() const { ssize_t offset; sp<IMemoryHeap> heap = getMemory(&offset); void* const base = heap!=0 ? heap->base() : MAP_FAILED; if (base == MAP_FAILED) return 0; return static_cast<char*>(base) + offset; }
TEST_F(ListTest, CanCreateList) { auto list = new Utils::List<FooMock>(getMemory()); EXPECT_NE(nullptr, list); delete list; }
void main() { // inintilizillig the matrics int i,j,k,tid; double sum = 0; GetArray(); inputMatrix_T = getMemory(ArraySize); outputMatrix = getMemory(ArraySize); /* Loop for the generate transpose of matrix */ #pragma omp parallel for num_threads(NUM_THREADS) shared(inputMatrix,inputMatrix_T) private(i,j) for(i=0;i<ArraySize;i++) { for(j=0;j<ArraySize;j++){ inputMatrix_T[i][j] = inputMatrix[j][i]; } } /* Timer Start */ start(); /* Matrix Multipication loop */ #pragma omp parallel for num_threads(NUM_THREADS) \ shared(inputMatrix,inputMatrix_T,outputMatrix,ArraySize) \ private(i,j,k) reduction(+:sum) for (i=0;i<ArraySize;i++) { for (j=0;j<ArraySize;j++) { //#pragma omp parallel private(i) num_threads(4) sum = 0; // outputMatrix[i][j]=0; for (k=0;k<ArraySize;k++) { sum += inputMatrix[i][k]*inputMatrix_T[j][k]; } outputMatrix[i][j] = sum; //printf("outputMatrix[%d][%d] %d \n",i,j,outputMatrix[i][j]); } } /* Timer Stop */ stop(); write_output("parallel_output.csv"); free(outputMatrix); free(inputMatrix); free(inputMatrix_T); }
TEST_F(MemoryParserTestFixture, testFillMemoryStruct){ auto memoryParser = std::make_unique<MemoryParser>(console); Memory * memory = memoryParser->getMemory(); //grep MemTotal /proc/meminfo | awk '{print $2}' EXPECT_LT(memory->total, 8090000); // >= EXPECT_GE(memory->total, 8000000); // <=? EXPECT_GE(memory->total, memory->used); // >= EXPECT_GT(memory->total, memory->free); // > }
void Kernel::loadBootProcess(BootImage *image, Address imagePAddr, Size index) { Address imageVAddr = (Address) image, args, vaddr; Size args_size = ARGV_SIZE; BootSymbol *program; BootSegment *segment; Process *proc; Arch::Memory local(0, Kernel::instance->getMemory()); // Point to the program and segments table program = &((BootSymbol *) (imageVAddr + image->symbolTableOffset))[index]; segment = &((BootSegment *) (imageVAddr + image->segmentsTableOffset))[program->segmentsOffset]; // Ignore non-BootProgram entries if (program->type != BootProgram) return; // Create process proc = m_procs->create(program->entry); proc->setState(Process::Ready); if (!proc->getPageDirectory()) return; // Obtain process memory Arch::Memory mem(proc->getPageDirectory(), getMemory()); // Map program segment into it's virtual memory for (Size i = 0; i < program->segmentsCount; i++) { for (Size j = 0; j < segment[i].size; j += PAGESIZE) { mem.map(imagePAddr + segment[i].offset + j, segment[i].virtualAddress + j, Arch::Memory::Present | Arch::Memory::User | Arch::Memory::Readable | Arch::Memory::Writable | Arch::Memory::Executable); } } // Map program arguments into the process m_memory->allocate(&args_size, &args); mem.map(args, ARGV_ADDR, Arch::Memory::Present | Arch::Memory::User | Arch::Memory::Readable | Arch::Memory::Writable); // Copy program arguments vaddr = local.findFree(ARGV_SIZE, Memory::KernelPrivate); local.map(args, vaddr, Memory::Present|Memory::Readable|Memory::Writable); MemoryBlock::copy((char *)vaddr, program->name, ARGV_SIZE); // Done NOTICE("loaded: " << program->name); }
TEST_F(ListTest, CanAddManyItemsToList) { auto list = new Utils::List<int>(getMemory()); for(int i = 0; i < listCapacity; i++) list->add(i); EXPECT_EQ(list->size(), listCapacity); EXPECT_LE(list->size(), list->capacity()); delete list; }
void test_c64_vice_get_memory(void**) { const uint8_t read_memory[] = { 0xa9, 0x22, 0xa2, 0x32, 0xc8, 0xee, 0x20, 0xd0, 0xee, 0x21, 0xd0, 0x4c, 0x0e, 0x08 }; uint8_t dest[sizeof(read_memory) + 1]; int dataSize = 0; assert_true(getMemory(dest, &dataSize, 0x080e, 14)); assert_true(dataSize >= 14); assert_memory_equal(dest, read_memory, sizeof_array(read_memory)); }
sIntBasePtr ShGcInt::gt(sIntBasePtr& a, sIntBasePtr & b) { auto aa = getMemory(a); auto bb = getMemory(b); auto ret(new ShGcInt(mRt, 1)); ShGc::CircuitItem workItem; workItem.mInputBundleCount = 2; workItem.mLabels.resize(3); workItem.mLabels[0] = bb; workItem.mLabels[1] = aa; workItem.mLabels[2] = ret->mLabels; workItem.mCircuit = mRt.mLibrary.int_int_lt( workItem.mLabels[0]->size(), workItem.mLabels[1]->size()); mRt.enqueue(std::move(workItem)); return sIntBasePtr(ret); }
void printMemory(struct Processor *proc, char **tokens) { int start = 0; int end = MEMORY_SIZE; if (checkIfAllMemoryLocationsAreValid(tokens+1)) { printInvalidCommandMessage(); return; } if (strcmp(tokens[0],"-r")) { start = atoi(tokens[1]); end = atoi(tokens[2]); if (start>end) { printInvalidCommandMessage(); return; } if (tokens[4]!=NULL) { printInvalidCommandMessage(); return; } } else if (strcmp(tokens[0],"-m")) { int j=0; while (*tokens) { printf("M%i=%i ",atoi(*tokens),getMemory(proc,atoi(*tokens))); tokens++; j++; if (j%8==0) printf("\n"); } } else if (strcmp(tokens[0],"-a")!=0) { printInvalidCommandMessage(); return; } for (int c=start; c<start/8 ; c++) { for (int d=0;d<8 ;d++) { printf("M%i=%i ",(c*d) +d,getMemory(proc,atoi(*tokens))); } printf("\n"); } }
sIntBasePtr ShGcInt::neq(sIntBasePtr& a, sIntBasePtr & b) { if (a->bitCount() != b->bitCount()) throw std::runtime_error("mixed bit count eq not impl. " LOCATION); auto aa = getMemory(a); auto bb = getMemory(b); auto ret(new ShGcInt(mRt, 1)); ShGc::CircuitItem workItem; workItem.mInputBundleCount = 2; workItem.mLabels.resize(3); workItem.mLabels[0] = aa; workItem.mLabels[1] = bb; workItem.mLabels[2] = ret->mLabels; workItem.mCircuit = mRt.mLibrary.int_neq( workItem.mLabels[0]->size()); mRt.enqueue(std::move(workItem)); return sIntBasePtr(ret); }
virtual void newChild(const std::shared_ptr<Poco::Net::WebSocket> &socket) override { _childSockets.push_back(socket); if (_childSockets.size() > NumToPrefork) { Poco::Timestamp::TimeDiff elapsed = _startTime.elapsed(); auto totalTime = (1000. * elapsed)/Poco::Timestamp::resolution(); Log::info() << "Launched " << _childSockets.size() << " in " << totalTime << Log::end; size_t totalPSSKb = 0; size_t totalDirtyKb = 0; // Skip the last one as it's not completely initialized yet. for (size_t i = 0; i < _childSockets.size() - 1; ++i) { Log::info() << "Getting memory of child #" << i + 1 << " of " << _childSockets.size() << Log::end; if (!getMemory(_childSockets[i], totalPSSKb, totalDirtyKb)) { exitTest(TestResult::TEST_FAILED); return; } } Log::info() << "Memory use total " << totalPSSKb << "k shared " << totalDirtyKb << "k dirty" << Log::end; totalPSSKb /= _childSockets.size(); totalDirtyKb /= _childSockets.size(); Log::info() << "Memory use average " << totalPSSKb << "k shared " << totalDirtyKb << "k dirty" << Log::end; Log::info() << "Launch time total " << totalTime << " ms" << Log::end; totalTime /= _childSockets.size(); Log::info() << "Launch time average " << totalTime << " ms" << Log::end; if (!_failure.empty()) { Log::error("UnitPrefork failed due to: " + _failure); exitTest(TestResult::TEST_FAILED); } else { Log::error("UnitPrefork success."); exitTest(TestResult::TEST_OK); } } }
status_t BnMemory::onTransact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { switch(code) { case GET_MEMORY: { CHECK_INTERFACE(IMemory, data, reply); ssize_t offset; size_t size; reply->writeStrongBinder( getMemory(&offset, &size)->asBinder() ); reply->writeInt32(offset); reply->writeInt32(size); return NO_ERROR; } break; default: return BBinder::onTransact(code, data, reply, flags); } }
Position PathMemory::moveOnPath(Position current, Position next, Position end) { if (!currentPath) { if (existsPath(current, end)) { currentPath = getMemory(current, end); } else { startPath(current, end); } } else { if (current == end) { currentPath->path.push_back(current); currentPath->pathComplete = true; currentPath = NULL; return current; } if (currentPath->pathComplete) { return getPrevPosition(); } else if (pathMap[next] == VISITED) { pathMap[current] = VISITED; if (currentPath->path.size() >= 2) { Position pos = *(currentPath->path.end() - 1); currentPath->path.erase(currentPath->path.end() - 1); return pos; } return currentPath->start; } else { currentPath->path.push_back(current); pathMap[current] = VISITED; return next; } } return next; }
int main(int argc, char **argv) { int rv = getMemory(); if(rv == OSMP_ERROR) { printf("Fehler beim Laden des Shared Memorys! Grund: %s", strerror(errno)); return OSMP_ERROR; } int value = 10; while(value == 10) { printMemory(); value = getchar(); fflush(stdin); } return 1; }
void Timer::step (std::string text) { stopTime(); stopMemory(); clock_t clickNb = eTime - iTime; time = ((float)clickNb)/CLOCKS_PER_SEC; memory = eMemory - iMemory; if (text != "") { std::cout << text << ": "; } std::cout << "STEP TIMER " << id << " (" << time << " sec, " << memory << " bytes)" << std::endl; iTime = clock(); iMemory = getMemory(); }