Blame src/functional/tls_local_exec.c

Szabolcs Nagy 4f5020
#include <stdint.h>
Szabolcs Nagy 4f5020
#include <pthread.h>
Szabolcs Nagy 4f5020
#include "test.h"
Szabolcs Nagy 4f5020
Szabolcs Nagy 4f5020
static __thread char d1 = 11;
Szabolcs Nagy 4f5020
static __thread char d64 __attribute__ ((aligned(64))) = 22;
Szabolcs Nagy 4f5020
static __thread char d4096 __attribute__ ((aligned(4096))) = 33;
Szabolcs Nagy 4f5020
static __thread char z1 = 0;
Szabolcs Nagy 4f5020
static __thread char z64 __attribute__ ((aligned(64))) = 0;
Szabolcs Nagy 4f5020
static __thread char z4096 __attribute__ ((aligned(4096))) = 0;
Szabolcs Nagy 4f5020
Szabolcs Nagy 4f5020
static int tnum;
Szabolcs Nagy 4f5020
Szabolcs Nagy 4f5020
#define CHECK(c, fmt, ...) do{ \
Szabolcs Nagy 4f5020
	if (!(c)) \
Szabolcs Nagy 4f5020
		t_error("[thread %d]: "#c" failed"fmt".\n", tnum, __VA_ARGS__); \
Szabolcs Nagy 4f5020
}while(0)
Szabolcs Nagy 4f5020
Szabolcs Nagy 4f5020
static unsigned ptrmod(void *p, unsigned m)
Szabolcs Nagy 4f5020
{
Szabolcs Nagy 4f5020
	volatile unsigned n = (uintptr_t)p;
Szabolcs Nagy 4f5020
	return n % m;
Szabolcs Nagy 4f5020
}
Szabolcs Nagy 4f5020
Szabolcs Nagy 4f5020
static void *check(void *arg)
Szabolcs Nagy 4f5020
{
Szabolcs Nagy 4f5020
	tnum++;
Szabolcs Nagy 4f5020
Szabolcs Nagy 4f5020
	CHECK(d1 == 11, " want 11 got %d", d1);
Szabolcs Nagy 4f5020
	CHECK(d64 == 22, " want 22 got %d", d64);
Szabolcs Nagy 4f5020
	CHECK(d4096 == 33, " want 33 got %d", d4096);
Szabolcs Nagy 4f5020
Szabolcs Nagy 4f5020
	CHECK(ptrmod(&d64, 64) == 0, " address is %p, want 64 byte alignment", &d64);
Szabolcs Nagy 4f5020
	CHECK(ptrmod(&d4096, 4096) == 0, " address is %p, want 4096 byte alignment", &d4096);
Szabolcs Nagy 4f5020
Szabolcs Nagy 4f5020
	CHECK(z1 == 0, " want 0 got %d", z1);
Szabolcs Nagy 4f5020
	CHECK(z64 == 0, " want 0 got %d", z64);
Szabolcs Nagy 4f5020
	CHECK(z4096 == 0, " want 0 got %d", z4096);
Szabolcs Nagy 4f5020
Szabolcs Nagy 4f5020
	CHECK(ptrmod(&z64, 64) == 0, " address is %p, want 64 byte alignment", &z64);
Szabolcs Nagy 4f5020
	CHECK(ptrmod(&z4096, 4096) == 0, " address is %p, want 4096 byte alignment", &z4096);
Szabolcs Nagy 4f5020
	return 0;
Szabolcs Nagy 4f5020
}
Szabolcs Nagy 4f5020
Szabolcs Nagy 4f5020
int main()
Szabolcs Nagy 4f5020
{
Szabolcs Nagy 4f5020
	pthread_t td;
Szabolcs Nagy 4f5020
Szabolcs Nagy 4f5020
	check(0);
Szabolcs Nagy 4f5020
	CHECK(pthread_create(&td, 0, check, 0) == 0, "", "");
Szabolcs Nagy 4f5020
	CHECK(pthread_join(td, 0) == 0, "", "");
Szabolcs Nagy 4f5020
Szabolcs Nagy 4f5020
	return t_status;
Szabolcs Nagy 4f5020
}