Пример #1
0
struct buf *
blk_get(blk_nr_t blk_nr)
{
	struct buf *bufp;
repeat:
	if ((bufp = btable_get(blk_nr))) { // requested block in the table
		if (bufp->locked) {
			;// Wait until it become unlocked
			goto repeat;
		}
		bufp->locked = 1;
		bfree_rm(bufp);		// it has to be in the bfree
		return bufp;
	}
	if (!(bufp = bfree_any_take())) { /*
		A buffer is never locked across syscalls, thefore the kernel
		can guarantee that a buffer will eventually become available */
		;// Wait until a free buffer is available
		goto repeat;
	}
	// the taken buffer is not now in the free buffer pool
	bufp->locked = 1;
	btable_rm(bufp);	// it could be in the btable
	bufp->blk_nr = blk_nr;
	bufp->valid = 0;
	btable_ins(bufp);
	return bufp;	
}
Пример #2
0
Файл: main.c Проект: ykst/euler
static inline bool check(uint32_t *ptable, uint32_t x, uint64_t *p_k)
{
    int k;
    int n = 0;
    bool ok = false;

    *p_k = 0;

    for(k = 1; ; k++) {
        n = 2 * k * k;
        if(n > x) break;
        if(btable_get(ptable, x - n)) {
            ok = true;
            *p_k = k;
            break;
        }
    }

    return ok;
}
Пример #3
0
Файл: main.c Проект: ykst/euler
int main(int argc, char **argv)
{
    int n_in = 0;
    int x_in = 0;

    for (int c; (c = getopt(argc, argv, "n:x:")) != -1;) {
        switch(c) {
            case 'n':
                n_in = atoi(optarg);
                break;
            case 'x':
                x_in = atoi(optarg);
                break;
        }
    }

    uint64_t result = 0;
    uint32_t pents[1000000] = {};
    vector(int) *vpents = vector_new(int, 100);

    int i, j, n = 0, m = 0;
    for(i = 1; ; i++) {
        n = pentagonal(i);
        if(n > 32000000) break;
        btable_set(pents, n);
        vector_pushback(vpents, n);
        m = n;
    }

    int cur, tgt, sum, diff;
    uint32_t d = 0xFFFFFFFF;
    for(i = 1; i < vpents->idx - 1; i++) {
        cur = vpents->buf[i];

        if(cur - vpents->buf[i - 1] > d) {
            ICHECK;
            break;
        }

        for(j = 0 ;j < i; j++) {

            tgt = vpents->buf[j];
            sum = cur + tgt;
            diff = cur - tgt;

            //printf("%d %d %d %d\n", tgt, cur, sum, diff);
            if(sum <= n && 
               btable_get(pents, sum) && 
               btable_get(pents, diff)) {

                printf("%d %d %d %d\n", tgt, cur, sum, diff);

                d = min(d, diff);
            }
        }
    }

    vector_delete(vpents);

    DUMPL(result = d); 

    return 0;
}