lock.c 916 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include "iotrack.h"
  12. #include "dat.h"
  13. #include "fns.h"
  14. void
  15. mlock(MLock *l)
  16. {
  17. if(l->key != 0 && l->key != 1)
  18. panic("uninitialized lock");
  19. if (l->key)
  20. panic("lock");
  21. l->key = 1;
  22. }
  23. void
  24. unmlock(MLock *l)
  25. {
  26. if(l->key != 0 && l->key != 1)
  27. panic("uninitialized unlock");
  28. if (!l->key)
  29. panic("unlock");
  30. l->key = 0;
  31. }
  32. int
  33. canmlock(MLock *l)
  34. {
  35. if(l->key != 0 && l->key != 1)
  36. panic("uninitialized canlock");
  37. if (l->key)
  38. return 0;
  39. l->key = 1;
  40. return 1;
  41. }