示例#1
0
bool Database_SQLite3::saveBlock(const v3s16 &pos, const std::string &data)
{
	verifyDatabase();

#ifdef __ANDROID__
	/**
	 * Note: For some unknown reason SQLite3 fails to REPLACE blocks on Android,
	 * deleting them and then inserting works.
	 */
	bindPos(m_stmt_read, pos);

	if (sqlite3_step(m_stmt_read) == SQLITE_ROW) {
		deleteBlock(pos);
	}
	sqlite3_reset(m_stmt_read);
#endif

	bindPos(m_stmt_write, pos);
	SQLOK(sqlite3_bind_blob(m_stmt_write, 2, data.data(), data.size(), NULL),
		"Internal error: failed to bind query at " __FILE__ ":" TOSTRING(__LINE__));

	SQLRES(sqlite3_step(m_stmt_write), SQLITE_DONE, "Failed to save block")
	sqlite3_reset(m_stmt_write);

	return true;
}
bool Database_SQLite3::saveBlock(const v3s16 &pos, const std::string &data)
{
	std::lock_guard<std::mutex> lock(mutex);

	verifyDatabase();

#ifdef __ANDROID__
	/**
	 * Note: For some unknown reason SQLite3 fails to REPLACE blocks on Android,
	 * deleting them and then inserting works.
	 */
	bindPos(m_stmt_read, pos);

	if (sqlite3_step(m_stmt_read) == SQLITE_ROW) {
		deleteBlock(pos);
	}
	sqlite3_reset(m_stmt_read);
#endif

	bindPos(m_stmt_write, pos);
	SQLOK(sqlite3_bind_blob(m_stmt_write, 2, data.data(), data.size(), NULL));

	SQLRES(sqlite3_step(m_stmt_write), SQLITE_DONE)
	sqlite3_reset(m_stmt_write);

	return true;
}
示例#3
0
void World::menuChoice(int n) {
    BuildingBlock *bb = getSelectedBuildingBlock();

	switch (n) {
	case 1 : {
		OUTPUT << "ADD block link to : " << bb->blockId << "     num Face : " << numSelectedFace << endl;
		vector<Cell3DPosition> nCells = lattice->getRelativeConnectivity(bb->position);
		Cell3DPosition nPos = bb->position + nCells[numSelectedFace];

		addBlock(0, bb->buildNewBlockCode, nPos, bb->color);
		linkBlock(nPos);
		linkNeighbors(nPos);
	} break;
	case 2 : {
		OUTPUT << "DEL num block : " << tabGlBlocks[numSelectedGlBlock]->blockId << endl;
		deleteBlock(bb);
	} break;
	case 3 : {
		tapBlock(getScheduler()->now(), bb->blockId, numSelectedFace);
	} break;
	case 4:                 // Save current configuration
		exportConfiguration();
		break;
	}
}
void FifoFreeStoreWithoutTLS::deallocate (void* p)
{
    Block* const b = (reinterpret_cast <Header*> (p) - 1)->block;

    if (b->release ())
        deleteBlock (b);
}
示例#5
0
void
CacheFile::deleteFile(int nr) {
	do {
		Block *block = lockBlock(nr);

		if (block == NULL)
			break;

		int next = block->next;

		unlockBlock(nr);

		deleteBlock(nr);

		nr = next;
	} while (nr != 0);
}
示例#6
0
 void handleEvent(SDL_Event evt) {
     /* Left Ctrl+s -> Save level
      * Delete -> delete current block
      * Space -> Make current block draggable
      * Arrow keys -> Set direction of current block
      * Any valid letter -> create block of that type
      */
     
     if(evt.type != SDL_KEYDOWN) return;
     
     if(evt.key.keysym.mod & KMOD_LCTRL && evt.key.keysym.sym == SDLK_s) {
         saveLevel();
     }
     
     else if(evt.key.keysym.sym == SDLK_DELETE) {
         deleteBlock();
     }
     
     else {
         switch(evt.key.keysym.sym) {
             case SDLK_UP:
                 setBlockDirection(rtBlock::UP);
                 break;
             case SDLK_DOWN:
                 setBlockDirection(rtBlock::DOWN);
                 break;
             case SDLK_RIGHT:
                 setBlockDirection(rtBlock::RIGHT);
                 break;
             case SDLK_LEFT:
                 setBlockDirection(rtBlock::LEFT);
                 break;
                 
             case SDLK_SPACE:
                 setDraggable();
                 break;
                 
             default:setBlock(evt.key.keysym.sym);
         }
     }
 }
示例#7
0
/**
 * Sort the m_blocks vector in reverse post order.  This enforces that
 * m_blocks will be a topological order in case the region is acyclic.
 * All region arcs are taken into account, including retranslation arcs.
 */
void RegionDesc::sortBlocks() {
  RegionDesc::BlockIdSet visited;
  RegionDesc::BlockIdVec reverse;

  postOrderSort(entry()->id(), visited, reverse);
  assertx(m_blocks.size() >= reverse.size());

  // Remove unreachable blocks from `m_data'.
  for (auto it = m_blocks.begin(); it != m_blocks.end();) {
    auto bid = (*it)->id();
    if (visited.count(bid) == 0) {
      it = deleteBlock(it);
    } else {
      it++;
    }
  }

  // Update `m_blocks' vector.
  m_blocks.clear();
  auto size = reverse.size();
  for (size_t i = 0; i < size; i++) {
    m_blocks.push_back(block(reverse[size - i - 1]));
  }
}
示例#8
0
void RegionDesc::deleteBlock(BlockId bid) {
  auto it = std::find_if(m_blocks.begin(), m_blocks.end(),
                         [&](const BlockPtr b) { return b->id() == bid; });
  if (it != m_blocks.end()) deleteBlock(it);
}
示例#9
0
void remove_from_cache(struct cache_header *cache, size_t size){
    int bytesNeeded = size - (MAX_CACHE_SIZE - cache->total_size);
    while (bytesNeeded > 0 && !cache_empty(cache)){
        bytesNeeded -= deleteBlock(cache);
    }
}
示例#10
0
void console_start() {
	char **parameters;
	char command[512];
	int exit = 0;

	strcpy(currentDirPrompt, "/");
	strcpy(currentDirId, ROOT_DIR_ID);

	do {
		printf("%s > ", currentDirPrompt);
		readCommand(command);
		// El trim de las commons tira error a veces.. string_trim(&command);

		// Ignore empty enter
		if (command[0] != '\0') {
			parameters = string_split(command, " ");

			if (string_equals_ignore_case(parameters[0], "format")) {
				format();
			} else if (string_equals_ignore_case(parameters[0], "df")) {
				diskFree();
			} else if (string_equals_ignore_case(parameters[0], "rm")) {
				deleteResource(parameters);
			} else if (string_equals_ignore_case(parameters[0], "mv")) {
				moveResource(parameters[1], parameters[2]);
			} else if (string_equals_ignore_case(parameters[0], "rename")) {
				renameResource(parameters[1], parameters[2]);
			} else if (string_equals_ignore_case(parameters[0], "mkdir")) {
				makeDir(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "cd")) {
				changeDir(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "ll")) {
				listResources();
			} else if (string_equals_ignore_case(parameters[0], "md5sum")) {
				md5sum(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "cp")) {
				copyFile(parameters);
			} else if (string_equals_ignore_case(parameters[0], "blocks")) {
				printFileBlocks(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "catb")) {
				saveBlockContents(parameters);
			} else if (string_equals_ignore_case(parameters[0], "cpb")) {
				copyBlock(parameters);
			} else if (string_equals_ignore_case(parameters[0], "rmb")) {
				deleteBlock(parameters);
			} else if (string_equals_ignore_case(parameters[0], "nodestat")) {
				printNodeStatus(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "enablen")) {
				enableNode(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "disablen")) {
				disableNode(parameters[1]);
			} else if (string_equals_ignore_case(parameters[0], "help")) {
				help();
			} else if (string_equals_ignore_case(parameters[0], "exit")) {
				exit = 1;
			} else if (string_equals_ignore_case(parameters[0], "\n")) {
				// ignore enter
			} else {
				printf("Invalid command \n");
			}
			freeSplits(parameters);
		}
	} while (!exit);

	printf("bye\n");
}
void* FifoFreeStoreWithoutTLS::allocate (const size_t bytes)
{
    const size_t actual = sizeof (Header) + bytes;

    if (actual > m_pages->getPageBytes ())
        Throw (Error ().fail (__FILE__, __LINE__, TRANS ("the memory request was too large")));

    Header* h;

    for (;;)
    {
        // Get an active block.
        Block* b = m_active;

        while (!b)
        {
            Thread::yield ();
            b = m_active;
        }

        // (*) It is possible for the block to get a final release here
        //     In this case it will have been put in the garbage, and
        //     m_active will not match.

        // Acquire a reference.
        b->addref ();

        // Is it still active?
        if (m_active == b)
        {
            // Yes so try to allocate from it.
            const Block::Result result = b->allocate (actual, &h);

            if (result == Block::success)
            {
                // Keep the reference and return the allocation.
                h->block = b;
                break;
            }
            else if (result == Block::consumed)
            {
                // Remove block from active.
                m_active = 0;

                // Take away the reference we added
                b->release ();

                // Take away the original active reference.
                if (b->release ())
                    deleteBlock (b);

                // Install a fresh empty active block.
                m_active = newBlock ();
            }
            else
            {
                if (b->release ())
                    deleteBlock (b);
            }

            // Try again.
        }
        else
        {
            // Block became inactive, so release our reference.
            b->release ();

            // (*) It is possible for this to be a duplicate final release.
        }
    }

    return h + 1;
}
FifoFreeStoreWithoutTLS::~FifoFreeStoreWithoutTLS ()
{
    deleteBlock (m_active);
}