3
3
#include <linux/sched.h>
4
4
#include <asm/host_ops.h>
5
5
6
- static int threads_counter ;
7
- static void * threads_counter_lock ;
8
-
9
- static inline void threads_counter_inc (void )
10
- {
11
- lkl_ops -> sem_down (threads_counter_lock );
12
- threads_counter ++ ;
13
- lkl_ops -> sem_up (threads_counter_lock );
14
- }
15
-
16
- static inline void threads_counter_dec (void )
17
- {
18
- lkl_ops -> sem_down (threads_counter_lock );
19
- threads_counter -- ;
20
- lkl_ops -> sem_up (threads_counter_lock );
21
- }
22
-
23
- static inline int threads_counter_get (void )
24
- {
25
- int counter ;
26
-
27
- lkl_ops -> sem_down (threads_counter_lock );
28
- counter = threads_counter ;
29
- lkl_ops -> sem_up (threads_counter_lock );
30
-
31
- return counter ;
32
- }
6
+ static volatile int threads_counter ;
33
7
34
8
struct thread_info * alloc_thread_info_node (struct task_struct * task , int node )
35
9
{
@@ -123,7 +97,7 @@ struct task_struct *__switch_to(struct task_struct *prev,
123
97
124
98
if (ei .dead ) {
125
99
lkl_ops -> sem_free (ei .sched_sem );
126
- threads_counter_dec ( );
100
+ __sync_fetch_and_sub ( & threads_counter , 1 );
127
101
lkl_ops -> thread_exit ();
128
102
}
129
103
@@ -175,7 +149,7 @@ int copy_thread(unsigned long clone_flags, unsigned long esp,
175
149
return - ENOMEM ;
176
150
}
177
151
178
- threads_counter_inc ( );
152
+ __sync_fetch_and_add ( & threads_counter , 1 );
179
153
180
154
return 0 ;
181
155
}
@@ -209,13 +183,6 @@ int threads_init(void)
209
183
goto out ;
210
184
}
211
185
212
- threads_counter_lock = lkl_ops -> sem_alloc (1 );
213
- if (!threads_counter_lock ) {
214
- pr_early ("lkl: failed to alllocate threads counter lock\n" );
215
- ret = - ENOMEM ;
216
- goto out_free_init_sched_sem ;
217
- }
218
-
219
186
return 0 ;
220
187
221
188
out_free_init_sched_sem :
@@ -241,9 +208,8 @@ void threads_cleanup(void)
241
208
kill_thread (ti -> exit_info );
242
209
}
243
210
244
- while (threads_counter_get () )
211
+ while (threads_counter )
245
212
;
246
213
247
214
lkl_ops -> sem_free (init_thread_union .thread_info .sched_sem );
248
- lkl_ops -> sem_free (threads_counter_lock );
249
215
}
0 commit comments