2
3
Calls the simple_lock_try( ) routine to try to assert a lock with read and write access for the resource that is associated with the specified simple lock. The el_start( ) routine calls simple_lock_try( ) rather than simple_lock( ) because simple_lock_try( ) returns immediately if the resource is already locked; simple_lock( ) spins until the lock has been obtained. Make sure that you call simple_lock_try( ) when you need a simple lock but the code cannot spin until the lock is obtained.
In this example, simple_lock_try( ) was used as an optimization. If the simple lock is already held, then another thread is executing somewhere in the driver and is either currently servicing the transmit request queue or will service it soon. Therefore, the transmit request that was put on the send queue prior to calling the start interface will be handled shortly. In this case, the code does not need to wait for the lock (because someone else will do the transmit) and can return to the caller.
The argument to simple_lock_try( ) is a pointer to a simple lock data structure. The if_el device driver declares the simple lock data structure by calling the decl_simple_lock_data( ) routine, and it stores a pointer to this data structure in the el_softc data structure.
If the simple_lock_try( ) routine fails to assert the simple lock, calls the splx( ) routine to reset the CPU priority to the level that the s variable specifies, then returns. Otherwise, the simple lock was obtained.
9.1.2 Calling the el_start_locked Routine
The following code shows how the el_start( ) routine calls the el_start_locked( ) routine, which starts the transmit operation:
el_start_locked(sc, ifp);
1
1
Calls the el_start_locked( ) routine, which performs the tasks that are related to the start operation.
9.1.3 Releasing the Simple Lock and Resetting the IPL
The following code shows how the el_start( ) routine releases the simple lock and resets the IPL.
splx(s); 2
}
1
1
Calls the simple_unlock( ) routine to release a simple lock for the resource that is associated with the specified simple lock data structure.