예제 #1
0
I8254* i8254Create(UInt32 frequency, I8254Out out1, I8254Out out2, I8254Out out3, void* ref)
{
    I8254* i8254 = calloc(1, sizeof(I8254));
    
    i8254->counter1 = counterCreate(out1 ? out1 : outDummy, ref, frequency);
    i8254->counter2 = counterCreate(out2 ? out2 : outDummy, ref, frequency);
    i8254->counter3 = counterCreate(out3 ? out3 : outDummy, ref, frequency);

    return i8254;
}
예제 #2
0
void precisionCommand(client *c) {
    counter *cntr;
    double precision;

    cntr = counterLookup(c->argv[1]->ptr);
    if (cntr == NULL && c->argc == 2) {
        /* Counter doesn't exist, return the default precision. */
        addReplyDouble(c, server.default_precision);
        return;
    }

    if (c->argc == 2) {
        addReplyDouble(c, cntr->precision);
        return;
    }

    if (getDoubleFromObjectOrReply(c, c->argv[2], &precision, NULL) != C_OK)
        return;

    if (cntr == NULL) {
        cntr = counterCreate(c->argv[1]->ptr);
    }

    cntr->precision = precision;
    server.dirty++;
    addReplyDouble(c, cntr->precision);
}
예제 #3
0
void genericIncrCommand(client *c, long double increment) {
    counter *cntr;

    cntr = counterLookup(c->argv[1]->ptr);
    if (cntr == NULL) {
        cntr = counterCreate(c->argv[1]->ptr);
    }

    if (cntr->myshard == NULL) {
        counterAddShard(cntr, myself, myself->name);
    }

    cntr->myshard->value += increment;
    cntr->value += increment;
    server.dirty++;
    counterCacheResponse(cntr);
    addReplyString(c,cntr->rbuf,cntr->rlen);
}
예제 #4
0
void setCommand(client *c) {
    counter *cntr;
    long double value;
    unsigned int i;

    if (getLongDoubleFromObjectOrReply(c,c->argv[2],&value,NULL) != C_OK)
        return;

    cntr = counterLookup(c->argv[1]->ptr);
    if (cntr == NULL) {
        cntr = counterCreate(c->argv[1]->ptr);
    }

    if (cntr->myshard == NULL) {
        counterAddShard(cntr,myself,myself->name);
    }

    /* myshard->value        = 4
     * cntr->value           = 10
     * value                 = 2
     * value in other shards = 6
     * new myshard->value    = 2 - (10 - 4) = -4
     */
    cntr->myshard->value = value - (cntr->value - cntr->myshard->value);

    /* Force a new prediction to be send. */
    cntr->myshard->predict_time = 0;

    /* Make sure the prediction is 0 so it doesn't change every second. */
    for (i = 0; i < server.history_size; i++) {
        cntr->history[i] = cntr->myshard->value;
    }

    cntr->value = value;
    server.dirty++;
    counterCacheResponse(cntr);
    addReplyString(c,cntr->rbuf,cntr->rlen);
}