diff options
author | Alan Cox <alan@lxorguk.ukuu.org.uk> | 2008-04-30 03:54:18 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-30 11:29:47 -0400 |
commit | 39c2e60f8c584c1b29b5c4375dd49df7995386bb (patch) | |
tree | fcb7e742d38c6e4655660d89be01e61d58ceebc4 | |
parent | 8cd64518a3d166a21f5c69ac7860b3add0369dd0 (diff) |
tty: add throttle/unthrottle helpers
Something Arjan suggested which allows us to clean up the code nicely
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Arjan van de Ven <arjan@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/bluetooth/hci_ldisc.c | 4 | ||||
-rw-r--r-- | drivers/char/n_tty.c | 14 | ||||
-rw-r--r-- | drivers/char/tty_ioctl.c | 16 | ||||
-rw-r--r-- | drivers/net/hamradio/6pack.c | 4 | ||||
-rw-r--r-- | drivers/net/hamradio/mkiss.c | 4 | ||||
-rw-r--r-- | drivers/net/ppp_async.c | 4 | ||||
-rw-r--r-- | drivers/net/ppp_synctty.c | 4 | ||||
-rw-r--r-- | include/linux/tty.h | 2 | ||||
-rw-r--r-- | include/linux/tty_driver.h | 4 |
9 files changed, 31 insertions, 25 deletions
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index a6c2619ec782..e5cd856a2fea 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c | |||
@@ -370,9 +370,7 @@ static void hci_uart_tty_receive(struct tty_struct *tty, const u8 *data, char *f | |||
370 | hu->hdev->stat.byte_rx += count; | 370 | hu->hdev->stat.byte_rx += count; |
371 | spin_unlock(&hu->rx_lock); | 371 | spin_unlock(&hu->rx_lock); |
372 | 372 | ||
373 | if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && | 373 | tty_unthrottle(tty); |
374 | tty->ops->unthrottle) | ||
375 | tty->ops->unthrottle(tty); | ||
376 | } | 374 | } |
377 | 375 | ||
378 | static int hci_uart_register_dev(struct hci_uart *hu) | 376 | static int hci_uart_register_dev(struct hci_uart *hu) |
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c index abc93a93dcdd..19105ec203f7 100644 --- a/drivers/char/n_tty.c +++ b/drivers/char/n_tty.c | |||
@@ -147,10 +147,8 @@ static void put_tty_queue(unsigned char c, struct tty_struct *tty) | |||
147 | 147 | ||
148 | static void check_unthrottle(struct tty_struct *tty) | 148 | static void check_unthrottle(struct tty_struct *tty) |
149 | { | 149 | { |
150 | if (tty->count && | 150 | if (tty->count) |
151 | test_and_clear_bit(TTY_THROTTLED, &tty->flags) && | 151 | tty_unthrottle(tty); |
152 | tty->ops->unthrottle) | ||
153 | tty->ops->unthrottle(tty); | ||
154 | } | 152 | } |
155 | 153 | ||
156 | /** | 154 | /** |
@@ -982,12 +980,8 @@ static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp, | |||
982 | * mode. We don't want to throttle the driver if we're in | 980 | * mode. We don't want to throttle the driver if we're in |
983 | * canonical mode and don't have a newline yet! | 981 | * canonical mode and don't have a newline yet! |
984 | */ | 982 | */ |
985 | if (tty->receive_room < TTY_THRESHOLD_THROTTLE) { | 983 | if (tty->receive_room < TTY_THRESHOLD_THROTTLE) |
986 | /* check TTY_THROTTLED first so it indicates our state */ | 984 | tty_throttle(tty); |
987 | if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) && | ||
988 | tty->ops->throttle) | ||
989 | tty->ops->throttle(tty); | ||
990 | } | ||
991 | } | 985 | } |
992 | 986 | ||
993 | int is_ignored(int sig) | 987 | int is_ignored(int sig) |
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c index c10d40c4c5ca..b1a757a5ee27 100644 --- a/drivers/char/tty_ioctl.c +++ b/drivers/char/tty_ioctl.c | |||
@@ -67,6 +67,22 @@ void tty_driver_flush_buffer(struct tty_struct *tty) | |||
67 | 67 | ||
68 | EXPORT_SYMBOL(tty_driver_flush_buffer); | 68 | EXPORT_SYMBOL(tty_driver_flush_buffer); |
69 | 69 | ||
70 | void tty_throttle(struct tty_struct *tty) | ||
71 | { | ||
72 | /* check TTY_THROTTLED first so it indicates our state */ | ||
73 | if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) && | ||
74 | tty->ops->throttle) | ||
75 | tty->ops->throttle(tty); | ||
76 | } | ||
77 | EXPORT_SYMBOL(tty_throttle); | ||
78 | |||
79 | void tty_unthrottle(struct tty_struct *tty) | ||
80 | { | ||
81 | if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && | ||
82 | tty->ops->unthrottle) | ||
83 | tty->ops->unthrottle(tty); | ||
84 | } | ||
85 | EXPORT_SYMBOL(tty_unthrottle); | ||
70 | 86 | ||
71 | /** | 87 | /** |
72 | * tty_wait_until_sent - wait for I/O to finish | 88 | * tty_wait_until_sent - wait for I/O to finish |
diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c index 82a36266dfc9..9d5721287d6f 100644 --- a/drivers/net/hamradio/6pack.c +++ b/drivers/net/hamradio/6pack.c | |||
@@ -491,9 +491,7 @@ static void sixpack_receive_buf(struct tty_struct *tty, | |||
491 | sixpack_decode(sp, buf, count1); | 491 | sixpack_decode(sp, buf, count1); |
492 | 492 | ||
493 | sp_put(sp); | 493 | sp_put(sp); |
494 | if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) | 494 | tty_unthrottle(tty); |
495 | && tty->ops->unthrottle) | ||
496 | tty->ops->unthrottle(tty); | ||
497 | } | 495 | } |
498 | 496 | ||
499 | /* | 497 | /* |
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c index ebcc5adee7cc..65166035aca0 100644 --- a/drivers/net/hamradio/mkiss.c +++ b/drivers/net/hamradio/mkiss.c | |||
@@ -936,9 +936,7 @@ static void mkiss_receive_buf(struct tty_struct *tty, const unsigned char *cp, | |||
936 | } | 936 | } |
937 | 937 | ||
938 | mkiss_put(ax); | 938 | mkiss_put(ax); |
939 | if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) | 939 | tty_unthrottle(tty); |
940 | && tty->ops->unthrottle) | ||
941 | tty->ops->unthrottle(tty); | ||
942 | } | 940 | } |
943 | 941 | ||
944 | /* | 942 | /* |
diff --git a/drivers/net/ppp_async.c b/drivers/net/ppp_async.c index 1c4b7e37912c..f1a52def1241 100644 --- a/drivers/net/ppp_async.c +++ b/drivers/net/ppp_async.c | |||
@@ -361,9 +361,7 @@ ppp_asynctty_receive(struct tty_struct *tty, const unsigned char *buf, | |||
361 | if (!skb_queue_empty(&ap->rqueue)) | 361 | if (!skb_queue_empty(&ap->rqueue)) |
362 | tasklet_schedule(&ap->tsk); | 362 | tasklet_schedule(&ap->tsk); |
363 | ap_put(ap); | 363 | ap_put(ap); |
364 | if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) | 364 | tty_unthrottle(tty); |
365 | && tty->ops->unthrottle) | ||
366 | tty->ops->unthrottle(tty); | ||
367 | } | 365 | } |
368 | 366 | ||
369 | static void | 367 | static void |
diff --git a/drivers/net/ppp_synctty.c b/drivers/net/ppp_synctty.c index 48ed5fdbfe18..b8f0369a71e7 100644 --- a/drivers/net/ppp_synctty.c +++ b/drivers/net/ppp_synctty.c | |||
@@ -401,9 +401,7 @@ ppp_sync_receive(struct tty_struct *tty, const unsigned char *buf, | |||
401 | if (!skb_queue_empty(&ap->rqueue)) | 401 | if (!skb_queue_empty(&ap->rqueue)) |
402 | tasklet_schedule(&ap->tsk); | 402 | tasklet_schedule(&ap->tsk); |
403 | sp_put(ap); | 403 | sp_put(ap); |
404 | if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) | 404 | tty_unthrottle(tty); |
405 | && tty->ops->unthrottle) | ||
406 | tty->ops->unthrottle(tty); | ||
407 | } | 405 | } |
408 | 406 | ||
409 | static void | 407 | static void |
diff --git a/include/linux/tty.h b/include/linux/tty.h index c36a76da2ae2..7f7121f9c968 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h | |||
@@ -303,6 +303,8 @@ extern int tty_put_char(struct tty_struct *tty, unsigned char c); | |||
303 | extern int tty_chars_in_buffer(struct tty_struct *tty); | 303 | extern int tty_chars_in_buffer(struct tty_struct *tty); |
304 | extern int tty_write_room(struct tty_struct *tty); | 304 | extern int tty_write_room(struct tty_struct *tty); |
305 | extern void tty_driver_flush_buffer(struct tty_struct *tty); | 305 | extern void tty_driver_flush_buffer(struct tty_struct *tty); |
306 | extern void tty_throttle(struct tty_struct *tty); | ||
307 | extern void tty_unthrottle(struct tty_struct *tty); | ||
306 | 308 | ||
307 | extern int is_current_pgrp_orphaned(void); | 309 | extern int is_current_pgrp_orphaned(void); |
308 | extern struct pid *tty_get_pgrp(struct tty_struct *tty); | 310 | extern struct pid *tty_get_pgrp(struct tty_struct *tty); |
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h index f80d73b690f6..59f1c0bd8f9c 100644 --- a/include/linux/tty_driver.h +++ b/include/linux/tty_driver.h | |||
@@ -100,6 +100,8 @@ | |||
100 | * This routine notifies the tty driver that input buffers for | 100 | * This routine notifies the tty driver that input buffers for |
101 | * the line discipline are close to full, and it should somehow | 101 | * the line discipline are close to full, and it should somehow |
102 | * signal that no more characters should be sent to the tty. | 102 | * signal that no more characters should be sent to the tty. |
103 | * | ||
104 | * Optional: Always invoke via tty_throttle(); | ||
103 | * | 105 | * |
104 | * void (*unthrottle)(struct tty_struct * tty); | 106 | * void (*unthrottle)(struct tty_struct * tty); |
105 | * | 107 | * |
@@ -107,6 +109,8 @@ | |||
107 | * that characters can now be sent to the tty without fear of | 109 | * that characters can now be sent to the tty without fear of |
108 | * overrunning the input buffers of the line disciplines. | 110 | * overrunning the input buffers of the line disciplines. |
109 | * | 111 | * |
112 | * Optional: Always invoke via tty_unthrottle(); | ||
113 | * | ||
110 | * void (*stop)(struct tty_struct *tty); | 114 | * void (*stop)(struct tty_struct *tty); |
111 | * | 115 | * |
112 | * This routine notifies the tty driver that it should stop | 116 | * This routine notifies the tty driver that it should stop |