ia64/xen-unstable

view extras/mini-os/lock.c @ 18811:390ef36eb596

Remove Xen-private definitions from kexec public header.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Nov 19 13:13:39 2008 +0000 (2008-11-19)
parents 433d1b26fd51
children
line source
1 /*
2 * locks for newlib
3 *
4 * Samuel Thibault <Samuel.Thibault@eu.citrix.net>, July 20008
5 */
7 #ifdef HAVE_LIBC
9 #include <sys/lock.h>
10 #include <sched.h>
11 #include <wait.h>
13 int ___lock_init(_LOCK_T *lock)
14 {
15 lock->busy = 0;
16 init_waitqueue_head(&lock->wait);
17 return 0;
18 }
20 int ___lock_acquire(_LOCK_T *lock)
21 {
22 unsigned long flags;
23 while(1) {
24 wait_event(lock->wait, !lock->busy);
25 local_irq_save(flags);
26 if (!lock->busy)
27 break;
28 local_irq_restore(flags);
29 }
30 lock->busy = 1;
31 local_irq_restore(flags);
32 return 0;
33 }
35 int ___lock_try_acquire(_LOCK_T *lock)
36 {
37 unsigned long flags;
38 int ret = -1;
39 local_irq_save(flags);
40 if (!lock->busy) {
41 lock->busy = 1;
42 ret = 0;
43 }
44 local_irq_restore(flags);
45 return ret;
46 }
48 int ___lock_release(_LOCK_T *lock)
49 {
50 unsigned long flags;
51 local_irq_save(flags);
52 lock->busy = 0;
53 wake_up(&lock->wait);
54 local_irq_restore(flags);
55 return 0;
56 }
59 int ___lock_init_recursive(_LOCK_RECURSIVE_T *lock)
60 {
61 lock->owner = NULL;
62 init_waitqueue_head(&lock->wait);
63 return 0;
64 }
66 int ___lock_acquire_recursive(_LOCK_RECURSIVE_T *lock)
67 {
68 unsigned long flags;
69 if (lock->owner != get_current()) {
70 while (1) {
71 wait_event(lock->wait, lock->owner == NULL);
72 local_irq_save(flags);
73 if (lock->owner == NULL)
74 break;
75 local_irq_restore(flags);
76 }
77 lock->owner = get_current();
78 local_irq_restore(flags);
79 }
80 lock->count++;
81 return 0;
82 }
84 int ___lock_try_acquire_recursive(_LOCK_RECURSIVE_T *lock)
85 {
86 unsigned long flags;
87 int ret = -1;
88 local_irq_save(flags);
89 if (!lock->owner) {
90 ret = 0;
91 lock->owner = get_current();
92 lock->count++;
93 }
94 local_irq_restore(flags);
95 return ret;
96 }
98 int ___lock_release_recursive(_LOCK_RECURSIVE_T *lock)
99 {
100 unsigned long flags;
101 BUG_ON(lock->owner != get_current());
102 if (--lock->count)
103 return 0;
104 local_irq_save(flags);
105 lock->owner = NULL;
106 wake_up(&lock->wait);
107 local_irq_restore(flags);
108 return 0;
109 }
111 #endif