Beispiel #1
0
static void *
thread(void *null)
{
	struct block *context = null;
	int i = ITERATE;
	unsigned int l;

        if (aff_iterate(&a)) {
                perror("ERROR: Could not affine thread");
                exit(EXIT_FAILURE);
        }

	if (context->tid == (unsigned int)nthr - 1)
		context->tid = sizeof(lock.readers) + 1;

	while (i--) {
		ck_bytelock_write_lock(&lock, context->tid);
		{
			l = ck_pr_load_uint(&locked);
			if (l != 0) {
				ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l);
			}

			ck_pr_inc_uint(&locked);
			ck_pr_inc_uint(&locked);
			ck_pr_inc_uint(&locked);
			ck_pr_inc_uint(&locked);
			ck_pr_inc_uint(&locked);
			ck_pr_inc_uint(&locked);
			ck_pr_inc_uint(&locked);
			ck_pr_inc_uint(&locked);

			l = ck_pr_load_uint(&locked);
			if (l != 8) {
				ck_error("ERROR [WR:%d]: %u != 2\n", __LINE__, l);
			}

			ck_pr_dec_uint(&locked);
			ck_pr_dec_uint(&locked);
			ck_pr_dec_uint(&locked);
			ck_pr_dec_uint(&locked);
			ck_pr_dec_uint(&locked);
			ck_pr_dec_uint(&locked);
			ck_pr_dec_uint(&locked);
			ck_pr_dec_uint(&locked);

			l = ck_pr_load_uint(&locked);
			if (l != 0) {
				ck_error("ERROR [WR:%d]: %u != 0\n", __LINE__, l);
			}
		}
		ck_bytelock_write_unlock(&lock);

		ck_bytelock_read_lock(&lock, context->tid);
		{
			l = ck_pr_load_uint(&locked);
			if (l != 0) {
				ck_error("ERROR [RD:%d]: %u != 0\n", __LINE__, l);
			}
		}
		ck_bytelock_read_unlock(&lock, context->tid);
	}

	return (NULL);
}
Beispiel #2
0
int
main(void)
{
        uint64_t s_b, e_b, i;
        ck_bytelock_t bytelock = CK_BYTELOCK_INITIALIZER;
        rwlock_t naive;

        for (i = 0; i < STEPS; i++) {
                ck_bytelock_write_lock(&bytelock, 1);
                ck_bytelock_write_unlock(&bytelock);
        }

        s_b = rdtsc();
        for (i = 0; i < STEPS; i++) {
                ck_bytelock_write_lock(&bytelock, 1);
                ck_bytelock_write_unlock(&bytelock);
        }
        e_b = rdtsc();
        printf("WRITE: bytelock %15" PRIu64 "\n", (e_b - s_b) / STEPS);

        rwlock_init(&naive);
        for (i = 0; i < STEPS; i++) {
                rwlock_write_lock(&naive);
                rwlock_write_unlock(&naive);
        }

        s_b = rdtsc();
        for (i = 0; i < STEPS; i++) {
                rwlock_write_lock(&naive);
                rwlock_write_unlock(&naive);
        }
        e_b = rdtsc();
        printf("WRITE: naive    %15" PRIu64 "\n", (e_b - s_b) / STEPS);

        for (i = 0; i < STEPS; i++) {
                ck_bytelock_read_lock(&bytelock, 1);
                ck_bytelock_read_unlock(&bytelock, 1);
        }
        s_b = rdtsc();
        for (i = 0; i < STEPS; i++) {
                ck_bytelock_read_lock(&bytelock, 1);
                ck_bytelock_read_unlock(&bytelock, 1);
        }
        e_b = rdtsc();
        printf("READ:  bytelock %15" PRIu64 "\n", (e_b - s_b) / STEPS);

        for (i = 0; i < STEPS; i++) {
                rwlock_read_lock(&naive);
                rwlock_read_unlock(&naive);
        }

        s_b = rdtsc();
        for (i = 0; i < STEPS; i++) {
                rwlock_read_lock(&naive);
                rwlock_read_unlock(&naive);
        }
        e_b = rdtsc();
        printf("READ:  naive    %15" PRIu64 "\n", (e_b - s_b) / STEPS);

        return (0);
}