2 * Copyright (C) 2011-2012 ARM Limited. All rights reserved.
4 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5 * 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 * A copy of the licence is included with the program, and can also be obtained from Free Software
8 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 * @file mali_osk_wait_queue.c
13 * Implemenation of the OS abstraction layer for the kernel device driver
16 #include <linux/wait.h>
17 #include <linux/slab.h>
18 #include <linux/sched.h>
21 #include "mali_kernel_common.h"
23 struct _mali_osk_wait_queue_t_struct
25 wait_queue_head_t wait_queue;
28 _mali_osk_wait_queue_t* _mali_osk_wait_queue_init( void )
30 _mali_osk_wait_queue_t* ret = NULL;
32 ret = kmalloc(sizeof(_mali_osk_wait_queue_t), GFP_KERNEL);
39 init_waitqueue_head(&ret->wait_queue);
40 MALI_DEBUG_ASSERT(!waitqueue_active(&ret->wait_queue));
45 void _mali_osk_wait_queue_wait_event( _mali_osk_wait_queue_t *queue, mali_bool (*condition)(void) )
47 MALI_DEBUG_ASSERT_POINTER( queue );
48 MALI_DEBUG_PRINT(6, ("Adding to wait queue %p\n", queue));
49 wait_event(queue->wait_queue, condition());
52 void _mali_osk_wait_queue_wake_up( _mali_osk_wait_queue_t *queue )
54 MALI_DEBUG_ASSERT_POINTER( queue );
56 /* if queue is empty, don't attempt to wake up its elements */
57 if (!waitqueue_active(&queue->wait_queue)) return;
59 MALI_DEBUG_PRINT(6, ("Waking up elements in wait queue %p ....\n", queue));
61 wake_up_all(&queue->wait_queue);
63 MALI_DEBUG_PRINT(6, ("... elements in wait queue %p woken up\n", queue));
66 void _mali_osk_wait_queue_term( _mali_osk_wait_queue_t *queue )
68 /* Parameter validation */
69 MALI_DEBUG_ASSERT_POINTER( queue );
71 /* Linux requires no explicit termination of wait queues */