Exemplo n.º 1
0
void testcreate()
{
    uint64_t cguid = 1;
    SDF_container_type_t ctype = SDF_BLOCK_CONTAINER;
    SDF_boolean_t bEntryCreated;

    for (int blockNum = 0; blockNum < numBlocks; blockNum++) {
        local_key_t *lkey = get_local_block_key(blockNum);
        DirEntry *entry = HomeDir_get_create(homedir, cguid, ctype, lkey, &bEntryCreated);
        plat_assert_always(SDF_TRUE == bEntryCreated && NULL != entry);
        // {{
        fthWaitEl_t *wait = reqq_lock(entry->q); // LOCK REQQ
        fthThread_t *top = reqq_peek(entry->q);
        plat_assert_always(top == fthSelf());
        fthThread_t *self = reqq_dequeue(entry->q);
        plat_assert_always(self == fthSelf());
        reqq_unlock(entry->q, wait); // UNLOCK REQQ
        // }}
        if (bEntryCreated) {
            free_local_key(lkey); // HomeDir_get_create makes a copy if created via LinkedDirList_put
        }
    }

    printf("Thread 1: Created %d blocks in the directory\n", numBlocks);
}
Exemplo n.º 2
0
void
testRoutine2(uint64_t arg)
{
    uint64_t cguid = 1;
    SDF_container_type_t ctype = SDF_BLOCK_CONTAINER;
    int blockNum;
    SDF_boolean_t bEntryCreated;

    for (blockNum = 0; blockNum < numBlocks; blockNum++) {
        local_key_t *lkey = get_local_block_key(blockNum);
        DirEntry *entry = HomeDir_get_create(homedir, cguid, ctype, lkey, &bEntryCreated);
        // {{
        fthThread_t *top = reqq_peek(entry->q);
        if (top != fthSelf()) {

            fthWaitEl_t *wait = reqq_lock(entry->q);
            uint16_t sz = reqq_enqueue(entry->q, fthSelf());
            reqq_unlock(entry->q, wait);

            printf("Thread 2: Size of request queue when second thread added itself = %u.\n", sz);

            if (sz > 1) {
                printf("Thread 2: going to wait\n");
                fthWait();
                printf("Thread 2: resumed after wait\n");
                fthWaitEl_t *wait = reqq_lock(entry->q);
                fthThread_t *top = reqq_peek(entry->q);
                if (top == fthSelf()) {
                    fthThread_t *self = reqq_dequeue(entry->q);
                    plat_assert_always(self == top);
                }
                reqq_unlock(entry->q, wait);
            }
        }
        // }}
    }
}
void testcreate(uint64_t seq) {
	uint64_t cguid = 1;
	SDF_container_type_t ctype = SDF_BLOCK_CONTAINER;
	SDF_boolean_t bEntryCreated;

	for (int i = 0; i < niterator; i++) {
		local_key_t *lkey = get_local_block_key(0);
		DirEntry *entry = HomeDir_get_create(homedir, cguid, ctype, lkey,
				&bEntryCreated);
		if (SDF_TRUE == bEntryCreated) {
			printf("fth %d create block\n", seq);
			fflush(stdout);
			//record actions
			(void) __sync_fetch_and_add(&nputs, 1);
		}
		else
		{
			(void) __sync_fetch_and_add(&ngets, 1);
			(void) __sync_fetch_and_add(&nhits, 1);
		}
		plat_assert_always(entry != NULL);
		// {{
		fthWaitEl_t *wait = reqq_lock(entry->q); // LOCK REQQ
		fthThread_t *top = reqq_peek(entry->q);
		plat_assert_always(top != 0);
//		plat_assert_always(top == fthSelf());
		fthThread_t *self = reqq_dequeue(entry->q);
		plat_assert_always(self != 0);
//		plat_assert_always(self == fthSelf());
		reqq_unlock(entry->q, wait); // UNLOCK REQQ
		// }}
		if (bEntryCreated) {
			free_local_key(lkey); // HomeDir_get_create makes a copy if created via LinkedDirList_put
		}
	}
}