DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Notes and examples for multithreaded TTY drivers

Modifying the open(D2oddi) routine

This first fragment of code illustrates the initial changes that need to be made to the TTY driver's open(D2oddi) routine:

Multithreaded open(D2oddi) routine for TTY driver

  1 xxopen(dev, flag)
  2 int dev, flag;
  3 {      ...
  4 int whole_dev = dev;

5 dev = minor(dev); 6 if (all_io(MP_ATBUS)) { 7 cdistributed(whole_dev, DIST_CDEV_READ | DIST_BDEV_STRATEGY); 8 iopolldistributed(poll); 9 } 10 tc_tlock(tp); /* replacing: oldspl = spl5(); */ 11 if (carrier required) { 12 tp->t_state |= CARR_ON; 13 wakeup((caddr_t) &tp->t_canq); 14 while ((tp->t_state & CARR_ON) == 0) { 15 tp->t_state |= WOPEN; 16 sleep((caddr_t) &tp->t_canq, TTIPRI); 17 } 18 } else 19 tp->t_state |= CARR_ON;

20 tc_tunlock(tp,...) /* replacing: splx(oldspl); */

21 /* replacing: (*linesw[tp->t_line].l_open) (tp); */ 22 run_ld(tp, DIST_LINESW_OPEN);


line 4
Save the major device number so it can be passed to the cdistributed(D3oddi) routine in line 7.

line 8
The poll(D2oddi) routine rather than the interrupt is distributed.

What is the iopolldistributed(D3oddi) function?


line 14
Check if the carrier is on.

lines 15-16
If the carrier is not on, the code flags that it is waiting for the carrier and then sleeps. If the code were not locked, a situation could arise in which the carrier came on after the flag had been set, and before the call to sleep(D3oddi). If this happened, the wakeup(D3oddi) call would be executed before sleep( ) and the sleep( ) would never be awakened.

lines 20
Unlock the critical code.

lines 23-25
The call to run_ld determines whether the line discipline is multithreaded. This is a precaution in case your driver works with a line discipline that is not multithreaded. The call to run_ld replaces a call to linesw that would have been called in a uniprocessor environment:
   (*linesw[tp->t_line].l_open) (tp);
At the moment, the tty line discipline is the only supported line discipline, so if, for example, a mouse is configured, it will context-switch to an appropriate processor within run_ld; the driver does not have to worry about this situation.

© 2005 The SCO Group, Inc. All rights reserved.