9os

Experimental kernel using plan9 ideas for embedded device
git clone git://git.simple-cc.org/9os
Log | Files | Refs | README | LICENSE

lock.c (474B)


      1 #include <os9/os9.h>
      2 
      3 void
      4 unlockspin(spinlock_t *s)
      5 {
      6 	unlock(s);
      7 }
      8 
      9 void
     10 lockspin(spinlock_t *s)
     11 {
     12 	lock(s);
     13 }
     14 
     15 void
     16 lock(mutex_t *mutex)
     17 {
     18 	if (!mutex)
     19 		panic("lock segfault");
     20 	if (*mutex)
     21 		panic("deadlock");
     22 	*mutex = 1;
     23 }
     24 
     25 void
     26 unlock(mutex_t *mutex)
     27 {
     28 	if (!mutex)
     29 		panic("unlock segfault");
     30 	if (!*mutex)
     31 		panic("unlock");
     32 	*mutex = 0;
     33 }
     34 
     35 int
     36 trylock(mutex_t *mutex)
     37 {
     38 	if (!mutex)
     39 		panic("trylock segfault");
     40 	if (*mutex)
     41 		return 0;
     42 	*mutex = 1;
     43 	return 1;
     44 }