lock_test.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. *
  3. * simple locking test program
  4. * (no paralles stuff)
  5. *
  6. * Compile with: gcc -D__CPU_i386 -O3 on x86 machines and
  7. * gcc -mips2 -O2 -D__CPU_mips2 on mips machines.
  8. * -- andrei
  9. *
  10. *
  11. */
  12. #include <stdio.h>
  13. #include "../fastlock.h"
  14. int main(int argc, char** argv)
  15. {
  16. fl_lock_t lock;
  17. int r;
  18. lock=0;
  19. printf("starting locking basic tests...\n");
  20. r=try_lock(&lock);
  21. printf(" try_lock should return 0 ... %d\n", r);
  22. printf(" lock should be 1 now ... %d\n", lock);
  23. r=try_lock(&lock);
  24. printf(" tsl should return -1 ... %d\n", r);
  25. printf(" lock should still be 1 now ... %d\n", lock);
  26. release_lock(&lock);
  27. printf(" release_lock: lock should be 0 now ... %d\n", lock);
  28. printf("try_lock once more...\n");
  29. r=try_lock(&lock);
  30. printf(" try_lock should return 0 ... %d\n", r);
  31. printf(" lock should be 1 now ... %d\n", lock);
  32. release_lock(&lock);
  33. get_lock(&lock);
  34. printf(" get_lock, lock should be 1 now ... %d\n", lock);
  35. printf("\ndone.\n");
  36. return 0;
  37. }