Initial commit
[kernel/linux-3.0.git] / drivers / gpu / vithar_rev0 / osk / src / linux / mali_osk_workq.c
1 /*
2  *
3  * (C) COPYRIGHT 2011 ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
6  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
7  * 
8  * A copy of the licence is included with the program, and can also be obtained from Free Software
9  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
10  * 
11  */
12
13
14
15 #include <osk/mali_osk.h>
16
17 #if MALI_LICENSE_IS_GPL == 0
18 /* Wrapper function to allow flushing in Non-GPL driver */
19 void oskp_work_func_wrapper( struct work_struct *work )
20 {
21         osk_workq_work *osk_work = CONTAINER_OF( work, osk_workq_work, os_work );
22         osk_workq *parent_wq;
23         u32 val;
24         unsigned long flags;
25
26         parent_wq = osk_work->parent_wq;
27         osk_work->actual_fn( osk_work );
28         /* work and osk_work could disappear from this point on */
29
30         /* parent_wq of course shouldn't disappear *yet*, because it must itself flush this function before term */
31
32         spin_lock_irqsave( &parent_wq->active_items_lock, flags );
33         val = --(parent_wq->nr_active_items);
34         /* The operations above and below must form an atomic operation themselves,
35          * hence the lock. See osk_workq_flush() for why */
36         if ( val == 0 )
37         {
38                 wake_up( &parent_wq->waitq_zero_active_items );
39         }
40         spin_unlock_irqrestore( &parent_wq->active_items_lock, flags );
41
42         /* parent_wq may've now disappeared */
43 }
44
45 #endif /* MALI_LICENSE_IS_GPL == 0 */