예제 #1
0
/***************************************************************************
 * This inserts the timeout entry into the appropriate place in the
 * timeout ring.
 ***************************************************************************/
void
timeouts_add(struct Timeouts *timeouts, struct TimeoutEntry *entry,
             size_t offset, uint64_t timestamp)
{
    unsigned index;

    /* Unlink from wherever the entry came from */
    timeout_unlink(entry);

    if (entry->prev) {
        LOG(1, "***CHANGE %d-seconds\n", 
                    (int)((timestamp-entry->timestamp)/TICKS_PER_SECOND));
    }

    /* Initialize the new entry */
    entry->timestamp = timestamp;
    entry->offset = (unsigned)offset;

    /* Link it into it's new location */
    index = timestamp & timeouts->mask;
    entry->next = timeouts->slots[index];
    timeouts->slots[index] = entry;
    entry->prev = &timeouts->slots[index];
    if (entry->next)
        entry->next->prev = &entry->next;
}
예제 #2
0
/***************************************************************************
 * Remove the next event that it older than the specified timestamp
 ***************************************************************************/
void *
timeouts_remove(struct Timeouts *timeouts, uint64_t timestamp)
{
    struct TimeoutEntry *entry = NULL;

    /* Search until we find one */
    while (timeouts->current_index <= timestamp) {

        /* Start at the current slot */
        entry = timeouts->slots[timeouts->current_index & timeouts->mask];

        /* enumerate through the linked list until we find a used slot */
        while (entry && entry->timestamp > timestamp)
            entry = entry->next;
        if (entry)
            break;

        /* found nothing at this slot, so move to next slot */
        timeouts->current_index++;
    }

    if (entry == NULL) {
        /* we've caught up to the current time, and there's nothing
         * left to timeout, so return NULL */
        return NULL;
    }

    /* unlink this entry from the timeout system */
    timeout_unlink(entry);

    /* return a pointer to the structure holding this entry */
    return ((char*)entry) - entry->offset;
}
예제 #3
0
void
timeouts_add(struct Timeouts *timeouts, struct TimeoutEntry *entry,
             size_t offset, uint64_t timestamp)
{
    unsigned index;
    //time_t now = time(0);
    //time_t time_future = (unsigned)(timestamp/16384ULL);

    /* Unlink from wherever the entry came from */
    timeout_unlink(entry);

//printf("++ADD %d.%03u\n", time_future-now, (unsigned)(((timestamp%16384ULL)/16384.0)*1000.0));
    /* Initialize the new entry */    
    entry->timestamp = timestamp;
    entry->offset = (unsigned)offset;

    /* Link it into it's new location */
    index = timestamp & timeouts->mask;
    entry->next = timeouts->slots[index];
    timeouts->slots[index] = entry;
    entry->prev = &timeouts->slots[index];
    if (entry->next)
        entry->next->prev = &entry->next;
//printf("++PREV=0x%llx\n", entry->prev);
}