int write (const char* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
    {
        int bytesWritten = -1;
        const uint32 timeoutEnd = getTimeoutEnd (timeOutMilliseconds);

        if (pipeOut == -1)
        {
            pipeOut = openPipe (createdPipe ? pipeOutName : pipeInName, O_WRONLY, timeoutEnd);

            if (pipeOut == -1)
                return -1;
        }

        bytesWritten = 0;

        while (bytesWritten < numBytesToWrite && ! hasExpired (timeoutEnd))
        {
            const int bytesThisTime = numBytesToWrite - bytesWritten;
            const int numWritten = (int) ::write (pipeOut, sourceBuffer, bytesThisTime);

            if (numWritten <= 0)
            {
                bytesWritten = -1;
                break;
            }

            bytesWritten += numWritten;
            sourceBuffer += numWritten;
        }

        return bytesWritten;
    }
    int write (const char* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
    {
        const uint32 timeoutEnd = getTimeoutEnd (timeOutMilliseconds);

        if (pipeOut == -1)
        {
            //bob: added O_NONBLOCK to prevent deadlocks when no client is connected for reading before we kill the PIPE
            pipeOut = openPipe (createdPipe ? pipeOutName : pipeInName, O_WRONLY|O_NONBLOCK, timeoutEnd);

            if (pipeOut == -1)
                return -1;
        }

        int bytesWritten = 0;

        while (bytesWritten < numBytesToWrite && ! hasExpired (timeoutEnd))
        {
            const int bytesThisTime = numBytesToWrite - bytesWritten;
            const int numWritten = (int) ::write (pipeOut, sourceBuffer, (size_t) bytesThisTime);

            if (numWritten <= 0)
                return -1;

            bytesWritten += numWritten;
            sourceBuffer += numWritten;
        }

        return bytesWritten;
    }
// MANIPULATORS
bsl::shared_ptr<const Calendar>
CalendarCache::getCalendar(const char *calendarName)
{
    BSLS_ASSERT(calendarName);

    {
        bsls::BslLockGuard lockGuard(&d_lock);

        CacheIterator iter = d_cache.find(calendarName);

        if (iter != d_cache.end()) {

            if (!d_hasTimeOutFlag
             || !hasExpired(d_timeOut, iter->second.loadTime())) {
                return iter->second.get();                            // RETURN
            }
            else {
                d_cache.erase(iter);
            }
        }
    }

    // Load calendar identified by 'calendarName'.

    PackedCalendar packedCalendar;  // temporary, so use default allocator

    if (d_loader_p->load(&packedCalendar, calendarName)) {
        return bsl::shared_ptr<const Calendar>();                     // RETURN
    }

    // Create out-of-place calendar that will be managed by 'bsl::shared_ptr'.

    Calendar *calendarPtr = new (*d_allocator_p) Calendar(packedCalendar,
                                                          d_allocator_p);

    CalendarCache_Entry entry(calendarPtr, bsl::time(0), d_allocator_p);

    BSLS_ASSERT(static_cast<bsl::time_t>(-1) != entry.loadTime());

    // Insert newly-loaded calendar into cache if another thread hasn't done so
    // already.

    bsls::BslLockGuard lockGuard(&d_lock);

    ConstCacheIterator iter = d_cache.find(calendarName);

    // Here, we assume that the time elapsed between the last check and the
    // loading of the calendar is insignificant compared to the timeout, so we
    // will simply return the entry in the cache if it has been inserted by
    // another thread.

    if (iter != d_cache.end()) {
        return iter->second.get();                                    // RETURN
    }

    d_cache[calendarName] = entry;

    return entry.get();
}
bool LLFrameTimer::checkExpirationAndReset(F32 expiration)
{
	if (hasExpired())
	{
		reset(expiration);
		return true;
	}
	return false;
}
Exemple #5
0
void Cooldown::wrap()
{
	if (hasExpired()) {
		passed -= duration;
	}
	else {
		Log::err("Cooldown", "wrapping when not expired");
	}
}
    static int openPipe (const String& name, int flags, const uint32 timeoutEnd)
    {
        for (;;)
        {
            const int p = ::open (name.toUTF8(), flags);

            if (p != -1 || hasExpired (timeoutEnd))
                return p;

            Thread::sleep (2);
        }
    }
BOOL LLFrameTimer::checkExpirationAndReset(F32 expiration)
{
	//llinfos << "LLFrameTimer::checkExpirationAndReset()" << llendl;
	//llinfos << "  mStartTime:" << mStartTime << llendl;
	//llinfos << "  sFrameTime:" << sFrameTime << llendl;
	//llinfos << "  mExpiry:   " <<  mExpiry << llendl;

	if(hasExpired())
	{
		reset();
		setTimerExpirySec(expiration);
		return TRUE;
	}
	return FALSE;
}
        void RenderObjectManager::renderObjectExpired( const Core::Index& idx )
        {
            std::lock_guard<std::mutex> lock( m_doubleBufferMutex );

            auto ro = m_renderObjects.at( idx );
            m_renderObjects.remove( idx );

            auto type = ro->getType();

            m_renderObjectByType[(int)type].erase( idx );

            ro->hasExpired();

            ro.reset();
        }
    int read (char* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
    {
        int bytesRead = -1;
        blocked = true;
        const uint32 timeoutEnd = getTimeoutEnd (timeOutMilliseconds);

        if (pipeIn == -1)
        {
            pipeIn = openPipe (createdPipe ? pipeInName : pipeOutName, O_RDWR | O_NONBLOCK, timeoutEnd);

            if (pipeIn == -1)
            {
                blocked = false;
                return -1;
            }
        }

        bytesRead = 0;

        while (bytesRead < maxBytesToRead)
        {
            const int bytesThisTime = maxBytesToRead - bytesRead;
            const int numRead = (int) ::read (pipeIn, destBuffer, bytesThisTime);

            if (numRead <= 0)
            {
                if (errno != EWOULDBLOCK || stopReadOperation || hasExpired (timeoutEnd))
                {
                    bytesRead = -1;
                    break;
                }

                const int maxWaitingTime = 30;
                waitForInput (pipeIn, timeoutEnd == 0 ? maxWaitingTime
                                                      : jmin (maxWaitingTime,
                                                              (int) (timeoutEnd - Time::getMillisecondCounter())));
                continue;
            }

            bytesRead += numRead;
            destBuffer += numRead;
        }

        blocked = false;
        return bytesRead;
    }
Exemple #10
0
// ACCESSORS
bsl::shared_ptr<const Calendar>
CalendarCache::lookupCalendar(const char *calendarName) const
{
    BSLS_ASSERT(calendarName);

    bsls::BslLockGuard lockGuard(&d_lock);

    CacheIterator iter = d_cache.find(calendarName);

    if (iter != d_cache.end()) {

        if (!d_hasTimeOutFlag
         || !hasExpired(d_timeOut, iter->second.loadTime())) {
            return iter->second.get();                                // RETURN
        }
        else {
            d_cache.erase(iter);
        }
    }

    return bsl::shared_ptr<const Calendar>();
}
Exemple #11
0
int BookInfo::update(const BookInfo *other) {
    qDebug() << Q_FUNC_INFO << "isbn"  << other->isbn;

    int updateType = UPDATE_NONE;

    if(this == other) return updateType;

    dirty = true;

    if (title != other->title) {
        title = other->title;
        updateType |= UPDATE_METADATA;
    }

    if (isbn != other->isbn) {
        isbn = other->isbn;
        updateType |= UPDATE_METADATA;
    }

    qDebug() << Q_FUNC_INFO << "lastTimeRead1" << lastTimeRead;
    qDebug() << Q_FUNC_INFO << "other->lastTimeRead" << other->lastTimeRead;
    if (lastTimeRead != other->lastTimeRead)
    {
        lastTimeRead = other->lastTimeRead;
        updateType |= UPDATE_METADATA;
    }

    qDebug() << Q_FUNC_INFO << "readingStatus" << readingStatus;
    qDebug() << Q_FUNC_INFO << "other->readingStatus: " << other->readingStatus;
    if(readingStatus != other->readingStatus)
    {
        readingStatus = other->readingStatus;
        if(other->readingStatus == BookInfo::READ_BOOK || other->readingStatus == BookInfo::NO_READ_BOOK)
            updateType |= UPDATE_CLOSED;
    }

    if (path != other->path) {
        path = other->path;
        updateType |= UPDATE_METADATA;
    }
    if (author != other->author) {
        author = other->author;
        updateType |= UPDATE_METADATA;
    }

    if (thumbnail != other->thumbnail) {
        thumbnail = other->thumbnail;
        updateType |= UPDATE_METADATA;
    }

    if (coverUrl != other->coverUrl) {
        coverUrl = other->coverUrl;
        updateType |= UPDATE_METADATA;
    }

    if (publishTime != other->publishTime) {
        publishTime = other->publishTime;
        updateType |= UPDATE_METADATA;
    }

    if (size != other->size) {
        size = other->size;
        updateType |= UPDATE_METADATA;
    }

    downloadTime = other->downloadTime;

    if (markCount != other->markCount) {
        markCount = other->markCount;
        updateType |= UPDATE_READING_METADATA;
    }

    if (noteCount != other->noteCount) {
        noteCount = other->noteCount;
        updateType |= UPDATE_READING_METADATA;
    }

    if (hiliCount != other->hiliCount) {
        hiliCount = other->hiliCount;
        updateType |= UPDATE_READING_METADATA;
    }

    if (pageCount != other->pageCount) {
        pageCount = other->pageCount;
        updateType |= UPDATE_READING_METADATA;
    }

    if (lastReadLink != other->lastReadLink) {
        lastReadLink = other->lastReadLink;
        updateType |= UPDATE_READING_POSITION;
        }

    if (lastReadPage != other->lastReadPage) {
        lastReadPage = other->lastReadPage;
        updateType |= UPDATE_READING_POSITION;
        }

    if (fabs(readingProgress - other->readingProgress) > EPS) {
        readingProgress = other->readingProgress;
        updateType |= UPDATE_READING_POSITION;
        }

    if (fabs(readingPercentage != other->readingPercentage) > EPS) {
        readingPercentage = other->readingPercentage;
        updateType |= UPDATE_READING_POSITION;
    }

    if (readingPeriod != other->readingPeriod)
        readingPeriod = other->readingPeriod;

    if (percentageList != other->percentageList)
        percentageList = other->percentageList;

    if (fontSize != other->fontSize) {
        fontSize = other->fontSize;
        updateType |= UPDATE_READING_METADATA;
    }

    if (pageMode != other->pageMode) {
        pageMode = other->pageMode;
        updateType |= UPDATE_READING_METADATA;
    }

    if (orientation != other->orientation) {
        orientation = other->orientation;
        updateType |= UPDATE_READING_METADATA;
    }

    if (timestamp != other->timestamp) {
        timestamp = other->timestamp;
        updateType |= UPDATE_METADATA;
    }

    publisher = other->publisher;
    synopsis = other->synopsis;
    fileSize = other->fileSize;
    syncDate = other->syncDate;
    storePrice = other->storePrice;
    format = other->format;
    language = other->language;

    if (m_type != other->m_type) {
        m_type = other->m_type;
        updateType |= UPDATE_TYPE;
    }

    if (m_expirationDate != other->m_expirationDate)
        m_expirationDate = other->m_expirationDate;

    if(hasExpired())
        updateType |= UPDATE_EXPIRATION;

    if(m_type == BOOKINFO_TYPE_SUBSCRIPTION)
        corrupted = true;
    else
        corrupted = other->corrupted;

    if (m_archived != other->m_archived) {
        m_archived = other->m_archived;
        updateType |= UPDATE_ARCHIVED;
    }

    if(isDRMFile != other->isDRMFile)
        isDRMFile = other->isDRMFile;

    m_collections = other->m_collections;
    m_cssFileList = other->m_cssFileList;
    totalReadingTime = other->totalReadingTime;

    if(locationsHasChanged(other->m_locations))
    {
        qDebug() << Q_FUNC_INFO << "locations has changed";
        updateType |= UPDATE_READING_METADATA;
        setLocations(other->m_locations);
    }

    return updateType;
}
Exemple #12
0
Datum Timer::getValue() {
	return Datum(hasExpired());
}