示例#1
0
lazy_string::char_reference &lazy_string::char_reference::operator=(char value) {
    ReadWriteLock &current = (*this->ls->lock);
    current.writeLock();
    bool updating = false;
    if(this->ls->present.use_count() > 1) {
        this->ls->present = make_shared<std::string>(this->ls->present->substr(this->ls->start, this->ls->sizevar));
        this->ls->start = 0;
        ReadWriteLock newLock;
        newLock.writeLock();
        this->ls->lock = make_shared<ReadWriteLock>(newLock);
        updating = true;
    }
    const string svalue(1, value);
    (*this->ls->present).replace(this->ls->start + this->index, 1, svalue);
    current.writeUnlock();
    if(updating)
        this->ls->lock->writeUnlock();
    return *this;
}
示例#2
0
WriteLocker::WriteLocker(ReadWriteLock& rwLock)
: _rwLock(rwLock)
{
    rwLock.writeLock();
}