Example #1
0
/*
 * Create and initialize a new Thread structure attached to a given proc.
 */
static int
newthread(Proc *p, void (*f)(void *arg), void *arg, uint stacksize,
	  char *name, int grp)
{
	int id;
	Thread *t;

	if(stacksize < 32)
		sysfatal("bad stacksize %d", stacksize);
	t = _threadmalloc(sizeof(Thread), 1);
	t->stksize = stacksize;
	t->stk = _threadmalloc(stacksize, 0);
	memset(t->stk, 0xFE, stacksize);
	_threadinitstack(t, f, arg);
	t->grp = grp;
	if(name)
		t->cmdname = strdup(name);
	t->id = nextID();
	id = t->id;
	t->next = (Thread*)~0;
	t->proc = p;
	_threaddebug(DBGSCHED, "create thread %d.%d name %s", p->pid, t->id, name);
	lock(&p->lock);
	p->nthreads++;
	if(p->threads.head == nil)
		p->threads.head = t;
	else
		*p->threads.tail = t;
	p->threads.tail = &t->nextt;
	t->nextt = nil;
	t->state = Ready;
	_threadready(t);
	unlock(&p->lock);
	return id;
}
Example #2
0
void CValuables::thingUpdated(const hacc::TDBID & thingID)
{
    QSqlQuery q = HACC_DB->query("select "
                                 "transactions_things.id "
                                 "from transactions_things "
                                 "where transactions_things.thing_id=?",
                                 QVariantList() << thingID);
    while(q.next())
    {
        hacc::TDBID transactionID = HACC_DB_2_DBID(q, 0);
        QSqlQuery inq = HACC_DB->query("select id from valuables where transaction_id=?",
                                       QVariantList() << transactionID);
        hacc::TDBID valID = HACC_QUERY_DATA_AVIALABLE(inq) ? HACC_DB_2_DBID(inq, 0) : 0;
        if(HACC_THINGS->tagAttached(HACC_TAG_ID_OBJECT, thingID))
        {
            if(!valID)
            {
                hacc::TDBID newID = nextID();
                HACC_DB->exec("insert into valuables (id,transaction_id,serial_number) values (?,?,?)",
                              QVariantList() << newID << transactionID << idToSerial(newID));
                emit created(newID);
            }
        }
        else
        {
            if(valID)
            {
                execRemove("transaction_id=?", QVariantList() << transactionID);
            }
        }
    }
}
Example #3
0
Ledger
LedgerOracle::accept(
    Ledger const& parent,
    TxSetType const& txs,
    NetClock::duration closeTimeResolution,
    NetClock::time_point const& consensusCloseTime)
{
    Ledger::Instance next(*parent.instance_);
    next.txs.insert(txs.begin(), txs.end());
    next.seq = parent.seq() + Ledger::Seq{1};
    next.closeTimeResolution = closeTimeResolution;
    next.closeTimeAgree = consensusCloseTime != NetClock::time_point{};
    if(next.closeTimeAgree)
        next.closeTime = effCloseTime(
            consensusCloseTime, closeTimeResolution, parent.closeTime());
    else
        next.closeTime = parent.closeTime() + 1s;

    next.parentCloseTime = parent.closeTime();
    next.parentID = parent.id();
    next.ancestors.push_back(parent.id());

    auto it = instances_.left.find(next);
    if (it == instances_.left.end())
    {
        using Entry = InstanceMap::left_value_type;
        it = instances_.left.insert(Entry{next, nextID()}).first;
    }
    return Ledger(it->second, &(it->first));
}
Example #4
0
Variable VariablePool::getFreshVariable(VariableType type) noexcept {
	std::size_t tmp = 0;
	{
		FRESHVAR_LOCK_GUARD
		tmp = nextID(type)++;
	}
	CARL_LOG_DEBUG("carl.varpool", "New variable of type " << type << " with id " << tmp);
	return Variable(tmp, type);
}
int DOMTimerCoordinator::installNewTimeout(ExecutionContext* context, ScheduledAction* action, int timeout, bool singleShot)
{
    // FIXME: DOMTimers depends heavily on ExecutionContext. Decouple them.
    ASSERT(context->timers() == this);
    int timeoutID = nextID();
    TimeoutMap::AddResult result = m_timers.add(timeoutID, DOMTimer::create(context, action, timeout, singleShot, timeoutID));
    ASSERT(result.isNewEntry);
    DOMTimer* timer = result.storedValue->value.get();

    timer->suspendIfNeeded();

    return timeoutID;
}
Example #6
0
xmlItem XMLProc::insert(xmlItem context, const QString &otype, const QString &name, long id)
{
    xmlItem i;

    if ( id==0 ) id = nextID();
    i = xml.createElement( otype );
    if ( id >= 100 ) setAttr(i, mda_id, id );
    if ( !name.isNull()) setAttr(i, mda_name, name );
    context.appendChild(i);
    if ( id > 0 ) idcache.insert(id, new ItemContaner(id,i) );
    SetModify(true);
    return i;
}
Example #7
0
int ModelManager::add(std::string name)
{
	int id;
	if (names.find(name) != names.end()) {
		id = names[name];
		items[id]->addref();
		return id;
	}
	// load new
	Model *model = new Model(name);
	id = nextID();
    do_add(name, id, model);
    return id;
}
Example #8
0
std::pair<std::vector<TileID>, AnnotationIDs>
AnnotationManager::addPointAnnotations(const std::vector<LatLng>& points,
                                       const std::vector<std::string>& symbols,
                                       const MapData& data) {
    std::lock_guard<std::mutex> lock(mtx);

    // We pre-generate tiles to contain each annotation up to the map's max zoom.
    // We do this for fast rendering without projection conversions on the fly, as well as
    // to simplify bounding box queries of annotations later. Tiles get invalidated when
    // annotations are added or removed in order to refresh the map render without
    // touching the base map underneath.

    const uint16_t extent = 4096;

    std::vector<uint32_t> annotationIDs;
    annotationIDs.reserve(points.size());

    std::vector<TileID> affectedTiles;

    for (size_t i = 0; i < points.size(); ++i) {
        const uint32_t annotationID = nextID();

        // track the annotation global ID and its geometry
        auto anno_it = annotations.emplace(
            annotationID,
            std::make_unique<Annotation>(AnnotationType::Point,
                                          AnnotationSegments({ { points[i] } })));

        const uint8_t maxZoom = data.transform.getMaxZoom();

        // side length of map at this zoom
        uint32_t z2 = 1 << maxZoom;

        // projection conversion into unit space
        const vec2<double> p = projectPoint(points[i]);

        uint32_t x = p.x * z2;
        uint32_t y = p.y * z2;

        for (int8_t z = maxZoom; z >= 0; z--) {
            affectedTiles.emplace_back(z, x, y, z);
            TileID tileID = affectedTiles.back();

            // calculate tile coordinate
            const Coordinate coordinate(extent * (p.x * z2 - x), extent * (p.y * z2 - y));

            const GeometryCollection geometries({ { { { coordinate } } } });

            // at render time we style the annotation according to its {sprite} field
            const std::map<std::string, std::string> properties = {
                { "sprite", (symbols[i].length() ? symbols[i] : defaultPointAnnotationSymbol) }
            };

            auto feature =
                std::make_shared<const LiveTileFeature>(FeatureType::Point, geometries, properties);

            auto tile_it = tiles.find(tileID);
            if (tile_it != tiles.end()) {
                //
                // We have this tile created already. Add this feature to it.
                //
                // get point layer & add feature
                auto layer =
                    tile_it->second.second->getMutableLayer(layerID);
                layer->addFeature(feature);
                // record annotation association with tile
                tile_it->second.first.insert(annotationID);
            } else {
                //
                // We need to create a new tile for this feature.
                //
                // create point layer & add feature
                util::ptr<LiveTileLayer> layer = std::make_shared<LiveTileLayer>();
                layer->addFeature(feature);
                // create tile & record annotation association
                auto tile_pos = tiles.emplace(
                    tileID, std::make_pair(std::unordered_set<uint32_t>({ annotationID }),
                                           std::make_unique<LiveTile>()));
                // add point layer to tile
                tile_pos.first->second.second->addLayer(layerID, layer);
            }

            // Record annotation association with tile and tile feature. This is used to determine stale tiles,
            // as well as to remove the feature from the tile upon annotation deletion.
            anno_it.first->second->tileFeatures.emplace(
                tileID, std::weak_ptr<const LiveTileFeature>(feature));

            // get ready for the next-lower zoom number
            z2 /= 2;
            x /= 2;
            y /= 2;
        }

        annotationIDs.push_back(annotationID);
    }

    // Tile:IDs that need refreshed and the annotation identifiers held onto by the client.
    return std::make_pair(affectedTiles, annotationIDs);
}
void VkeCubeTexture::List::addTexture(VkeCubeTexture * const inMaterial){
	VkeCubeTexture::ID id = nextID();
	m_data[id] = inMaterial;
}
VkeCubeTexture *VkeCubeTexture::List::newTexture(){
	VkeCubeTexture::ID id = nextID();
	return newTexture(id);
}
Example #11
0
 static std::string nextID(const std::string &prefix) {
   return prefix + Ogre::StringConverter::toString(nextID());
 }
Example #12
0
LedgerOracle::LedgerOracle()
{
    instances_.insert(InstanceEntry{Ledger::genesis, nextID()});
}