[2] | 1 | #include "func_test_lock.h" |
---|
| 2 | #include <sys/lock.h> |
---|
| 3 | __LOCK_INIT(static,lock1); |
---|
| 4 | static int val1 = 0; |
---|
| 5 | void test_lock1 () |
---|
| 6 | { |
---|
| 7 | __lock_init (lock1); |
---|
| 8 | print((unsigned int)lock1.mutex); |
---|
| 9 | |
---|
| 10 | while (val1 < 100) |
---|
| 11 | { |
---|
| 12 | __lock_acquire (lock1); |
---|
| 13 | print(val1); |
---|
| 14 | val1 ++; |
---|
| 15 | __lock_release (lock1); |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | __lock_close (lock1); |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | __LOCK_INIT(static,lock2); |
---|
| 22 | static int val2 = 0; |
---|
| 23 | void test_lock2 () |
---|
| 24 | { |
---|
| 25 | __lock_init (lock2); |
---|
| 26 | print((unsigned int)lock2.mutex); |
---|
| 27 | while (val2 < 100) |
---|
| 28 | { |
---|
| 29 | if (__lock_try_acquire (lock2) == 1) |
---|
| 30 | { |
---|
| 31 | print(val2); |
---|
| 32 | val2 ++; |
---|
| 33 | __lock_release (lock2); |
---|
| 34 | } |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | __lock_close (lock2); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | __LOCK_INIT_RECURSIVE(static,lock_recursive1); |
---|
| 41 | static int val_recursive1 = 0; |
---|
| 42 | void test_lock_recursive1 () |
---|
| 43 | { |
---|
| 44 | __lock_init_recursive (lock_recursive1); |
---|
| 45 | print((unsigned int)lock_recursive1.mutex); |
---|
| 46 | |
---|
| 47 | while (val_recursive1 < 100) |
---|
| 48 | { |
---|
| 49 | __lock_acquire_recursive (lock_recursive1); |
---|
| 50 | __lock_acquire_recursive (lock_recursive1); |
---|
| 51 | print(val_recursive1); |
---|
| 52 | val_recursive1 ++; |
---|
| 53 | __lock_release_recursive (lock_recursive1); |
---|
| 54 | print(val_recursive1); |
---|
| 55 | val_recursive1 ++; |
---|
| 56 | __lock_release_recursive (lock_recursive1); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | __lock_close_recursive (lock_recursive1); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | __LOCK_INIT_RECURSIVE(static,lock_recursive2); |
---|
| 63 | static int val_recursive2 = 0; |
---|
| 64 | void test_lock_recursive2 () |
---|
| 65 | { |
---|
| 66 | __lock_init_recursive (lock_recursive2); |
---|
| 67 | print((unsigned int)lock_recursive2.mutex); |
---|
| 68 | |
---|
| 69 | while (val_recursive2 < 100) |
---|
| 70 | { |
---|
| 71 | if (__lock_try_acquire_recursive (lock_recursive2) == 1) |
---|
| 72 | { |
---|
| 73 | if (__lock_try_acquire_recursive (lock_recursive2) == 1) |
---|
| 74 | { |
---|
| 75 | print(val_recursive2); |
---|
| 76 | val_recursive2 ++; |
---|
| 77 | __lock_release_recursive (lock_recursive2); |
---|
| 78 | } |
---|
| 79 | print(val_recursive2); |
---|
| 80 | val_recursive2 ++; |
---|
| 81 | __lock_release_recursive (lock_recursive2); |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | __lock_close_recursive (lock_recursive2); |
---|
| 86 | } |
---|