Outline: Linux Implementation



device structure



device structure

struct device from include/linux/netdevice.h:



device structure, continued



device structure, continued



Locking and Unlocking

/* These two don't currently need to be
 * interrupt-safe but they may soon.
 * Do it properly anyway. */
extern __inline__
void  dev_lock_list(void)
{ unsigned long flags;
  save_flags(flags);
  cli();
  dev_lockct++;
  restore_flags(flags);
}
extern __inline__
void  dev_unlock_list(void)
{ unsigned long flags;
  save_flags(flags);
  cli();
  dev_lockct--;
  restore_flags(flags);
}



In-Class Exercise: test-and-set

Modify dev_lock_list to return the new value of dev_lockct



Linux scheduler



schedule



In-Class Exercise: spin lock

Modify dev_lock_list to only increment dev_lockct if the value is zero. Otherwise, dev_lock_list should call schedule() and loop