Esempio n. 1
0
void set_time_t(time_t *sometime, char *buffer) {
  LOCK_CLOCK();
  sometime->hours = char_to_digit(buffer[0]) * 10 + char_to_digit(buffer[1]);
  sometime->deci_seconds = char_to_digit(buffer[2]) * 10 + char_to_digit(buffer[3]);  
  sometime->deci_seconds *= 600;
  UNLOCK_CLOCK();
  state = VIEW_CLOCK;
}
Esempio n. 2
0
void show_stopwatch( char *a, char *b ){
	unsigned ds; 
    strcpy(a, "1:On 2:Off 3:Clr");
	
	LOCK_CLOCK();
	ds = stopwatch.deci_seconds;
	UNLOCK_CLOCK();
	
	write_time(&stopwatch, b);
	b[8] = '.';
	int_to_ascii((ds % 600) % 10, b + 9, ' ', 2);
}
Esempio n. 3
0
void do_item_unlink(item *it, const uint32_t hv) {
    MEMCACHED_ITEM_UNLINK(ITEM_key(it), it->nkey, it->nbytes);
    LOCK_CLOCK();
    if ((it->it_flags & ITEM_LINKED) != 0) {
        it->it_flags &= ~ITEM_LINKED;
        STATS_LOCK();
        stats.curr_bytes -= ITEM_ntotal(it);
        stats.curr_items -= 1;
        STATS_UNLOCK();
        assoc_delete(ITEM_key(it), it->nkey, hv);
        item_unlink_q(it);
        do_item_remove(it);
    }
    UNLOCK_CLOCK();
}
Esempio n. 4
0
void write_time(time_t *sometime, char *line) {
  	unsigned hrs, ds;
	
	LOCK_CLOCK();
	hrs = sometime->hours;
	ds = sometime->deci_seconds;
	UNLOCK_CLOCK();
	
	int_to_ascii(hrs, line, '0', 3);
	line[2] = ':';
	int_to_ascii(ds / 600, line + 3, '0', 3);
	line[5] = ':';
	int_to_ascii( (ds % 600) / 10, line + 6, '0', 3);
	line[8] = ' ';
}
Esempio n. 5
0
void do_item_update(item *it) {
#ifdef CLOCK_REPLACEMENT    
    if (it->recency == 0) it->recency = 1;
#else
    MEMCACHED_ITEM_UPDATE(ITEM_key(it), it->nkey, it->nbytes);
    if (it->time < current_time - ITEM_UPDATE_INTERVAL) {
        assert((it->it_flags & ITEM_SLABBED) == 0);

        LOCK_CLOCK();
        if ((it->it_flags & ITEM_LINKED) != 0) {
            item_unlink_q(it);
            it->time = current_time;
            item_link_q(it);
        }
        UNLOCK_CLOCK();
    }
#endif
}
Esempio n. 6
0
void show_timer( char *a, char *b ){
    if (set_timer_position == 0 && timer.hours != MAX_HOURS) {
	  time_t difference;
	  
	  LOCK_CLOCK();
	  difference.hours = timer.hours - time.hours;
  	  difference.deci_seconds = timer.deci_seconds - time.deci_seconds;
	  UNLOCK_CLOCK();
	  
	  strcpy(a, "Time left:");
	
      write_time(&difference, b);
      b[8] = '.';
      int_to_ascii((difference.deci_seconds % 600) % 10, b + 9, ' ', 2);
	} else {
      show_time_prompt("New Timer MM:SS", a, b, set_timer_buffer);
	}
}
Esempio n. 7
0
void keypress_timer(char key) {
  int minutes, seconds;
  int ds, hrs;
  
  if (enter_time(key, &timer, set_timer_buffer, &set_timer_position, false)) {
	minutes = char_to_digit(set_timer_buffer[0]) * 10 + char_to_digit(set_timer_buffer[1]);
	seconds = char_to_digit(set_timer_buffer[2]) * 10 + char_to_digit(set_timer_buffer[3]);
	
    LOCK_CLOCK();
	ds = time.deci_seconds + minutes * 600 + seconds * 10;
	hrs = time.hours;
	timer.hours = (hrs + ds / MAX_DECISECONDS) % 24;
	timer.deci_seconds = ds % MAX_DECISECONDS;
    UNLOCK_CLOCK();
	
	clear_time_prompt(set_timer_buffer);
  } 
}
Esempio n. 8
0
/*@null@*/
item *do_item_alloc(char *key, const size_t nkey, const int flags,
                    const rel_time_t exptime, const int nbytes,
                    const uint32_t cur_hv) {
    uint8_t nsuffix;
    ck_spinlock_mcs_context_t second_lock;
    item *it = NULL;
    char suffix[40];
    size_t ntotal = item_make_header(nkey + 1, flags, nbytes, suffix, &nsuffix);
    if (settings.use_cas) {
        ntotal += sizeof(uint64_t);
    }

    unsigned int id = slabs_clsid(ntotal);
    if (id == 0)
        return 0;

    LOCK_CLOCK();

    /* Avoid hangs if a slab has nothing but refcounted stuff in it. */
    /* int tries_lrutail_reflocked = 1000; */
    item *search;
    item *next_it;
    void *hold_lock = NULL;

    /* We have no expiration. Try alloc a new one first. */
    if ((it = slabs_alloc(ntotal, id)) == NULL) {
        printf("item slab alloc fails\n");
        assert(0);
        /* doing CLOCK eviction */
        search = hand[id];
        if (!search) {
            /* no mem from alloc or replace */
            UNLOCK_CLOCK();
            return NULL;
        }

        /* scan loop of the clock, which could be potentially
         * unbounded -- we may want an upper limit for it. */
        for (search = hand[id]; search != NULL; search = next_it) {
            assert(search);
            /* we might relink search mid-loop, so search->prev isn't reliable */
            next_it = search->prev;
//            if (*key == 101) printf("aaa %d\n", sizes[id]);
            if (search->nbytes == 0 && search->nkey == 0 && search->it_flags == 1) {
                /* We are a crawler, ignore it. */
                continue;
            }
            uint32_t hv = hash(ITEM_key(search), search->nkey);
            /* Attempt to hash item lock the "search" item. If locked, no
             * other callers can incr the refcount
             */
            /* Don't accidentally grab ourselves, or bail if we can't quicklock */
            if (hv == cur_hv || (hold_lock = item_try_mcslock(hv, &second_lock)) == NULL)
                continue;
            /* Now see if the item is refcount locked */
            if (refcount_incr(&search->refcount) != 2) {
                /* Avoid pathological case with ref'ed items in tail */
                do_item_update_nolock(search);
                /* tries_lrutail_reflocked--; */
                refcount_decr(&search->refcount);
                itemstats[id].lrutail_reflocked++;
                /* Old rare bug could cause a refcount leak. We haven't seen
                 * it in years, but we leave this code in to prevent failures
                 * just in case */
                if (settings.tail_repair_time &&
                    search->time + settings.tail_repair_time < current_time) {
                    itemstats[id].tailrepairs++;
                    search->refcount = 1;
                    do_item_unlink_nolock(search, hv);
                }
                if (hold_lock)
                    item_try_mcsunlock(hold_lock, &second_lock);

                /* if (tries_lrutail_reflocked < 1) */
                /*     break; */

                continue;
            }

            if (search->recency) {
                /* recently accessed. clear bit and continue. */
                search->recency = 0;
                continue;
            }

//            printf("aaa %d, %d\n", sizes[id], *key);

            itemstats[id].evicted++;
            itemstats[id].evicted_time = current_time - search->time;
            if (search->exptime != 0)
                itemstats[id].evicted_nonzero++;
            if ((search->it_flags & ITEM_FETCHED) == 0) {
                itemstats[id].evicted_unfetched++;
            }
            it = search;
            slabs_adjust_mem_requested(it->slabs_clsid, ITEM_ntotal(it), ntotal);
            do_item_unlink_nolock(it, hv);
            /* Initialize the item block: */
            it->slabs_clsid = 0;
            
            refcount_decr(&search->refcount);
            /* If hash values were equal, we don't grab a second lock */
            if (hold_lock)
                item_try_mcsunlock(hold_lock, &second_lock);
            break;
        }
        /* end of loop*/
    }
    /* end of allocation / eviction */

    if (it == NULL) {
        itemstats[id].outofmemory++;
        UNLOCK_CLOCK();
        return NULL;
    }

    assert(it->slabs_clsid == 0);

    /* Item initialization can happen outside of the lock; the item's already
     * been removed from the slab LRU.
     */
    it->refcount = 1;     /* the caller will have a reference */
    UNLOCK_CLOCK();
    it->next = it->prev = it->h_next = 0;
    it->slabs_clsid = id;

    DEBUG_REFCNT(it, '*');
    it->it_flags = settings.use_cas ? ITEM_CAS : 0;
    it->nkey = nkey;
    it->nbytes = nbytes;
    memcpy(ITEM_key(it), key, nkey);
    it->exptime = 0; //exptime; /* disable expiration. */
    memcpy(ITEM_suffix(it), suffix, (size_t)nsuffix);
    it->nsuffix = nsuffix;
    return it;
}