Add test_and_clear and test_and_set.
Unified · Split
| @@ -205,8 +205,7 @@ void blk_plug_device(struct request_queue *q) · 204 unmodified lines | ||
| 205 | 205 | if (blk_queue_stopped(q)) |
| 206 | 206 | return; |
| 207 | 207 | |
| 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)) { | |
| 210 | 209 | mod_timer(&q->unplug_timer, jiffies + q->unplug_delay); |
| 211 | 210 | blk_add_trace_generic(q, NULL, 0, BLK_TA_PLUG); |
| 212 | 211 | } |
| @@ -221,10 +220,9 @@ int blk_remove_plug(struct request_queue *q) · 8 unmodified lines | ||
| 221 | 220 | { |
| 222 | 221 | WARN_ON(!irqs_disabled()); |
| 223 | 222 | |
| 224 | − if (!test_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags)) | |
| 223 | + if (!queue_flag_test_and_clear(QUEUE_FLAG_PLUGGED, q)) | |
| 225 | 224 | return 0; |
| 226 | 225 | |
| 227 | − queue_flag_clear(QUEUE_FLAG_PLUGGED, q); | |
| 228 | 226 | del_timer(&q->unplug_timer); |
| 229 | 227 | return 1; |
| 230 | 228 | } |
| @@ -328,8 +326,7 @@ void blk_start_queue(struct request_queue *q) · 97 unmodified lines | ||
| 328 | 326 | * one level of recursion is ok and is much faster than kicking |
| 329 | 327 | * the unplug handling |
| 330 | 328 | */ |
| 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)) { | |
| 333 | 330 | q->request_fn(q); |
| 334 | 331 | queue_flag_clear(QUEUE_FLAG_REENTER, q); |
| 335 | 332 | } else { |
| @@ -394,8 +391,7 @@ void __blk_run_queue(struct request_queue *q) · 58 unmodified lines | ||
| 394 | 391 | * handling reinvoke the handler shortly if we already got there. |
| 395 | 392 | */ |
| 396 | 393 | 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)) { | |
| 399 | 395 | q->request_fn(q); |
| 400 | 396 | queue_flag_clear(QUEUE_FLAG_REENTER, q); |
| 401 | 397 | } else { |
| @@ -428,6 +428,32 @@ static inline void queue_flag_set_unlocked(unsigned int flag, · 427 unmodified lines | ||
| 428 | 428 | __set_bit(flag, &q->queue_flags); |
| 429 | 429 | } |
| 430 | 430 | |
| 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 | + | |
| 431 | 457 | static inline void queue_flag_set(unsigned int flag, struct request_queue *q) |
| 432 | 458 | { |
| 433 | 459 | WARN_ON_ONCE(!queue_is_locked(q)); |