2 * Copyright (C) 2010-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.
11 #include "mali_spinlock_reentrant.h"
14 #include "mali_kernel_common.h"
16 struct mali_spinlock_reentrant *mali_spinlock_reentrant_init(_mali_osk_lock_order_t lock_order)
18 struct mali_spinlock_reentrant *spinlock;
20 spinlock = _mali_osk_calloc(1, sizeof(struct mali_spinlock_reentrant));
21 if (NULL == spinlock) {
25 spinlock->lock = _mali_osk_spinlock_irq_init(_MALI_OSK_LOCKFLAG_ORDERED, lock_order);
26 if (NULL == spinlock->lock) {
27 mali_spinlock_reentrant_term(spinlock);
34 void mali_spinlock_reentrant_term(struct mali_spinlock_reentrant *spinlock)
36 MALI_DEBUG_ASSERT_POINTER(spinlock);
37 MALI_DEBUG_ASSERT(0 == spinlock->counter && 0 == spinlock->owner);
39 if (NULL != spinlock->lock) {
40 _mali_osk_spinlock_irq_term(spinlock->lock);
43 _mali_osk_free(spinlock);
46 void mali_spinlock_reentrant_wait(struct mali_spinlock_reentrant *spinlock, u32 tid)
48 MALI_DEBUG_ASSERT_POINTER(spinlock);
49 MALI_DEBUG_ASSERT_POINTER(spinlock->lock);
50 MALI_DEBUG_ASSERT(0 != tid);
52 MALI_DEBUG_PRINT(5, ("%s ^\n", __FUNCTION__));
54 if (tid != spinlock->owner) {
55 _mali_osk_spinlock_irq_lock(spinlock->lock);
56 MALI_DEBUG_ASSERT(0 == spinlock->owner && 0 == spinlock->counter);
57 spinlock->owner = tid;
60 MALI_DEBUG_PRINT(5, ("%s v\n", __FUNCTION__));
65 void mali_spinlock_reentrant_signal(struct mali_spinlock_reentrant *spinlock, u32 tid)
67 MALI_DEBUG_ASSERT_POINTER(spinlock);
68 MALI_DEBUG_ASSERT_POINTER(spinlock->lock);
69 MALI_DEBUG_ASSERT(0 != tid && tid == spinlock->owner);
72 if (0 == spinlock->counter) {
74 MALI_DEBUG_PRINT(5, ("%s release last\n", __FUNCTION__));
75 _mali_osk_spinlock_irq_unlock(spinlock->lock);