History

block: extend queue_flag bitops

Add test_and_clear and test_and_set.

Jens Axboe committed 18 years ago

Commit e48ec691 parent e180f592 files · +30 −8Browse files

Unified · Split

2 files
  1. block/blk-core.c +4 −8
  2. include/linux/blkdev.h +26 −0
block/blk-core.c+4−8
@@ -205,8 +205,7 @@ void blk_plug_device(struct request_queue *q) · 204 unmodified lines
205205 if (blk_queue_stopped(q))
206206 return;
207207
208− if (!test_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags)) {
209− __set_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags);
208+ if (!queue_flag_test_and_set(QUEUE_FLAG_PLUGGED, q)) {
210209 mod_timer(&q->unplug_timer, jiffies + q->unplug_delay);
211210 blk_add_trace_generic(q, NULL, 0, BLK_TA_PLUG);
212211 }
@@ -221,10 +220,9 @@ int blk_remove_plug(struct request_queue *q) · 8 unmodified lines
221220 {
222221 WARN_ON(!irqs_disabled());
223222
224− if (!test_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags))
223+ if (!queue_flag_test_and_clear(QUEUE_FLAG_PLUGGED, q))
225224 return 0;
226225
227− queue_flag_clear(QUEUE_FLAG_PLUGGED, q);
228226 del_timer(&q->unplug_timer);
229227 return 1;
230228 }
@@ -328,8 +326,7 @@ void blk_start_queue(struct request_queue *q) · 97 unmodified lines
328326 * one level of recursion is ok and is much faster than kicking
329327 * the unplug handling
330328 */
331− if (!test_bit(QUEUE_FLAG_REENTER, &q->queue_flags)) {
332− queue_flag_set(QUEUE_FLAG_REENTER, q);
329+ if (!queue_flag_test_and_set(QUEUE_FLAG_REENTER, q)) {
333330 q->request_fn(q);
334331 queue_flag_clear(QUEUE_FLAG_REENTER, q);
335332 } else {
@@ -394,8 +391,7 @@ void __blk_run_queue(struct request_queue *q) · 58 unmodified lines
394391 * handling reinvoke the handler shortly if we already got there.
395392 */
396393 if (!elv_queue_empty(q)) {
397− if (!test_bit(QUEUE_FLAG_REENTER, &q->queue_flags)) {
398− queue_flag_set(QUEUE_FLAG_REENTER, q);
394+ if (!queue_flag_test_and_set(QUEUE_FLAG_REENTER, q)) {
399395 q->request_fn(q);
400396 queue_flag_clear(QUEUE_FLAG_REENTER, q);
401397 } else {
include/linux/blkdev.h+26−0
@@ -428,6 +428,32 @@ static inline void queue_flag_set_unlocked(unsigned int flag, · 427 unmodified lines
428428 __set_bit(flag, &q->queue_flags);
429429 }
430430
431+static inline int queue_flag_test_and_clear(unsigned int flag,
432+ struct request_queue *q)
433+{
434+ WARN_ON_ONCE(!queue_is_locked(q));
435+
436+ if (test_bit(flag, &q->queue_flags)) {
437+ __clear_bit(flag, &q->queue_flags);
438+ return 1;
439+ }
440+
441+ return 0;
442+}
443+
444+static inline int queue_flag_test_and_set(unsigned int flag,
445+ struct request_queue *q)
446+{
447+ WARN_ON_ONCE(!queue_is_locked(q));
448+
449+ if (!test_bit(flag, &q->queue_flags)) {
450+ __set_bit(flag, &q->queue_flags);
451+ return 0;
452+ }
453+
454+ return 1;
455+}
456+
431457 static inline void queue_flag_set(unsigned int flag, struct request_queue *q)
432458 {
433459 WARN_ON_ONCE(!queue_is_locked(q));