source: trunk/Softwares/Basic_test.or32/src/c/func_test_lock.c @ 2

Last change on this file since 2 was 2, checked in by kane, 17 years ago

Import Morpheo

File size: 1.8 KB
Line 
1#include "func_test_lock.h"
2#include <sys/lock.h>
3__LOCK_INIT(static,lock1);
4static int val1 = 0;
5void 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);
22static int val2 = 0;
23void 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);
41static int val_recursive1 = 0;
42void 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);
63static int val_recursive2 = 0;
64void 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}
Note: See TracBrowser for help on using the repository browser.