Changeset 11 for trunk/kernel/libk/remote_spinlock.c
- Timestamp:
- Apr 26, 2017, 2:29:23 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/remote_spinlock.c
r1 r11 31 31 #include <remote_spinlock.h> 32 32 33 //////////////////////////////////////// 34 void remote_spinlock_init( xptr_t lock )33 /////////////////////////////////////////// 34 void remote_spinlock_init( xptr_t lock_xp ) 35 35 { 36 remote_spinlock_t * ptr = (remote_spinlock_t *)GET_PTR( lock );37 cxy_t cxy = GET_CXY( lock );36 remote_spinlock_t * ptr = (remote_spinlock_t *)GET_PTR( lock_xp ); 37 cxy_t cxy = GET_CXY( lock_xp ); 38 38 39 39 hal_remote_sw ( XPTR( cxy , &ptr->taken ) , 0 ); … … 42 42 } 43 43 44 /////////////////////////////////////////////// 45 uint32_t remote_spinlock_trylock( xptr_t lock)44 ///////////////////////////////////////////////// 45 error_t remote_spinlock_trylock( xptr_t lock_xp ) 46 46 { 47 47 uint32_t mode; … … 49 49 50 50 // get cluster and local pointer on remote_spinlock 51 remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock );52 cxy_t lock_cxy = GET_CXY( lock );51 remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock_xp ); 52 cxy_t lock_cxy = GET_CXY( lock_xp ); 53 53 54 54 // get cluster and local pointer on local thread … … 84 84 } 85 85 86 //////////////////////////////////////// 87 void remote_spinlock_lock( xptr_t lock ) 86 /////////////////////////////////////////////////// 87 void remote_spinlock_lock_busy( xptr_t lock_xp, 88 uint32_t * irq_state ) 88 89 { 89 90 bool_t isAtomic = false; … … 92 93 93 94 // get cluster and local pointer on remote_spinlock 94 remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock ); 95 cxy_t lock_cxy = GET_CXY( lock ); 95 remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock_xp ); 96 cxy_t lock_cxy = GET_CXY( lock_xp ); 97 98 // get cluster and local pointer on local thread 99 cxy_t thread_cxy = local_cxy; 100 thread_t * thread_ptr = CURRENT_THREAD; 101 102 // disable interrupts 103 hal_disable_irq( &mode ); 104 105 // loop until success 106 while( isAtomic == false ) 107 { 108 taken = hal_remote_lw( XPTR( lock_cxy , &lock_ptr->taken ) ); 109 110 // try to take the lock if not already taken 111 if( taken == 0 ) 112 { 113 isAtomic = hal_remote_atomic_cas( XPTR( lock_cxy , &lock_ptr->taken ) , 0 , 1 ); 114 } 115 } 116 117 // register lock in thread 118 thread_ptr->remote_locks++; 119 120 hal_remote_swd( XPTR( lock_cxy , &lock_ptr->owner ) , 121 (uint64_t)XPTR( thread_cxy , thread_ptr) ); 122 123 xlist_add_first( XPTR( thread_cxy , &thread_ptr->xlocks_root ) , 124 XPTR( lock_cxy , &lock_ptr->list ) ); 125 126 // irq_state must be restored when lock is released 127 *irq_state = mode; 128 129 } // end remote_spinlock_lock_busy() 130 131 //////////////////////////////////////////////////// 132 void remote_spinlock_unlock_busy( xptr_t lock_xp, 133 uint32_t irq_state ) 134 { 135 // get cluster and local pointer on remote_spinlock 136 remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock_xp ); 137 cxy_t lock_cxy = GET_CXY( lock_xp ); 138 139 // get pointer on local thread 140 thread_t * thread_ptr = CURRENT_THREAD; 141 142 hal_remote_swd( XPTR( lock_cxy , &lock_ptr->owner ) , XPTR_NULL ); 143 144 hal_remote_sw ( XPTR( lock_cxy , &lock_ptr->taken ) , 0 ); 145 146 thread_ptr->remote_locks--; 147 148 xlist_unlink( XPTR( lock_cxy , &lock_ptr->list ) ); 149 150 hal_restore_irq( irq_state ); 151 } 152 153 /////////////////////////////////////////// 154 void remote_spinlock_lock( xptr_t lock_xp ) 155 { 156 bool_t isAtomic = false; 157 uint32_t mode; 158 volatile uint32_t taken; 159 160 // get cluster and local pointer on remote_spinlock 161 remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock_xp ); 162 cxy_t lock_cxy = GET_CXY( lock_xp ); 96 163 97 164 // get cluster and local pointer on local thread … … 133 200 } 134 201 135 ////////////////////////////////////////// 136 void remote_spinlock_unlock( xptr_t lock )137 { 138 // get cluster and local pointer on remote_spinlock 139 remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock );140 cxy_t lock_cxy = GET_CXY( lock );202 ///////////////////////////////////////////// 203 void remote_spinlock_unlock( xptr_t lock_xp ) 204 { 205 // get cluster and local pointer on remote_spinlock 206 remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock_xp ); 207 cxy_t lock_cxy = GET_CXY( lock_xp ); 141 208 142 209 // get pointer on local thread
Note: See TracChangeset
for help on using the changeset viewer.