git » libfilo » master » tree

[master] / tests / test4.c

#include <stdio.h>
#include <unistd.h>

#include "libfilo.h"

#define LOCK(start, len, mode)	 			\
	do {						\
		printf("%lu: about to lock\n", pthread_self()); \
		if (!filo_lock(&l, start, len, mode)) printf("F\n"); \
		printf("%lu: lock\t %d %d %d\n", pthread_self(), start, len, mode); \
	} while(0);

#define UNLOCK(start, len)	 			\
	do {						\
		printf("%lu: about to unlock\n", pthread_self()); \
		if (!filo_unlock(&l, start, len)) printf("F\n"); \
		printf("%lu: unlock\t %d %d\n", pthread_self(), start, len); \
	} while(0);

#define LU_S(start, len, mode, sl)			\
	do {						\
		LOCK(start, len, mode);			\
		sleep(sl);				\
		UNLOCK(start, len);			\
	} while(0);

filock_t l;

int main(void) {

	filo_init(&l);

	LOCK(10, 1, FL_WR_MODE);
	UNLOCK(10, 1);

	LOCK(0, 1, FL_RD_MODE);
	LOCK(0, 1, FL_WR_MODE);
	UNLOCK(0, 1);

	LOCK(0, 2, FL_RD_MODE);
	UNLOCK(0, 1);
	UNLOCK(1, 1);

	filo_free(&l);

	printf("done static\n\n");
	return 0;

}