diff options
| author | Andrew Morton <akpm@zip.com.au> | 2002-07-04 08:30:49 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@home.transmeta.com> | 2002-07-04 08:30:49 -0700 |
| commit | f42e6ed8b8c71b3cdc1f0ed7c3f8d2f0c0ec6427 (patch) | |
| tree | a770a4d0df553b44b134db75d1590ae249d25da5 | |
| parent | e7c8964639dbb27af8156afd99fd2f3f7b60d869 (diff) | |
[PATCH] add new list_splice_init()
A little cleanup: Most callers of list_splice() immediately
reinitialise the source list_head after calling list_splice().
So create a new list_splice_init() which does all that.
| -rw-r--r-- | drivers/block/ll_rw_blk.c | 3 | ||||
| -rw-r--r-- | drivers/ieee1394/ieee1394_core.c | 3 | ||||
| -rw-r--r-- | fs/fs-writeback.c | 14 | ||||
| -rw-r--r-- | fs/jfs/jfs_txnmgr.c | 5 | ||||
| -rw-r--r-- | fs/mpage.c | 14 | ||||
| -rw-r--r-- | fs/nfs/write.c | 3 | ||||
| -rw-r--r-- | include/linux/list.h | 36 |
7 files changed, 42 insertions, 36 deletions
diff --git a/drivers/block/ll_rw_blk.c b/drivers/block/ll_rw_blk.c index 318ff55529fb..bb57f0ab64a8 100644 --- a/drivers/block/ll_rw_blk.c +++ b/drivers/block/ll_rw_blk.c @@ -964,8 +964,7 @@ void blk_run_queues(void) return; } - list_splice(&blk_plug_list, &local_plug_list); - INIT_LIST_HEAD(&blk_plug_list); + list_splice_init(&blk_plug_list, &local_plug_list); spin_unlock_irq(&blk_plug_lock); while (!list_empty(&local_plug_list)) { diff --git a/drivers/ieee1394/ieee1394_core.c b/drivers/ieee1394/ieee1394_core.c index aa64a17f71ab..f72a0b9641af 100644 --- a/drivers/ieee1394/ieee1394_core.c +++ b/drivers/ieee1394/ieee1394_core.c @@ -740,8 +740,7 @@ void abort_requests(struct hpsb_host *host) host->ops->devctl(host, CANCEL_REQUESTS, 0); spin_lock_irqsave(&host->pending_pkt_lock, flags); - list_splice(&host->pending_packets, &llist); - INIT_LIST_HEAD(&host->pending_packets); + list_splice_init(&host->pending_packets, &llist); spin_unlock_irqrestore(&host->pending_pkt_lock, flags); list_for_each(lh, &llist) { diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index db84b9f8eec4..d5a3e1ffdb81 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -220,8 +220,7 @@ static void sync_sb_inodes(struct super_block *sb, int sync_mode, struct list_head *head; const unsigned long start = jiffies; /* livelock avoidance */ - list_splice(&sb->s_dirty, &sb->s_io); - INIT_LIST_HEAD(&sb->s_dirty); + list_splice_init(&sb->s_dirty, &sb->s_io); head = &sb->s_io; while ((tmp = head->prev) != head) { struct inode *inode = list_entry(tmp, struct inode, i_list); @@ -262,13 +261,10 @@ static void sync_sb_inodes(struct super_block *sb, int sync_mode, break; } out: - if (!list_empty(&sb->s_io)) { - /* - * Put the rest back, in the correct order. - */ - list_splice(&sb->s_io, sb->s_dirty.prev); - INIT_LIST_HEAD(&sb->s_io); - } + /* + * Put the rest back, in the correct order. + */ + list_splice_init(&sb->s_io, sb->s_dirty.prev); return; } diff --git a/fs/jfs/jfs_txnmgr.c b/fs/jfs/jfs_txnmgr.c index 83bdf2ee9586..5d152b888182 100644 --- a/fs/jfs/jfs_txnmgr.c +++ b/fs/jfs/jfs_txnmgr.c @@ -2975,10 +2975,7 @@ int jfs_sync(void) } } /* Add anon_list2 back to anon_list */ - if (!list_empty(&TxAnchor.anon_list2)) { - list_splice(&TxAnchor.anon_list2, &TxAnchor.anon_list); - INIT_LIST_HEAD(&TxAnchor.anon_list2); - } + list_splice_init(&TxAnchor.anon_list2, &TxAnchor.anon_list); add_wait_queue(&jfs_sync_thread_wait, &wq); set_current_state(TASK_INTERRUPTIBLE); TXN_UNLOCK(); diff --git a/fs/mpage.c b/fs/mpage.c index 187d75047979..5f9b62416492 100644 --- a/fs/mpage.c +++ b/fs/mpage.c @@ -490,8 +490,7 @@ mpage_writepages(struct address_space *mapping, write_lock(&mapping->page_lock); - list_splice(&mapping->dirty_pages, &mapping->io_pages); - INIT_LIST_HEAD(&mapping->dirty_pages); + list_splice_init(&mapping->dirty_pages, &mapping->io_pages); while (!list_empty(&mapping->io_pages) && !done) { struct page *page = list_entry(mapping->io_pages.prev, @@ -538,13 +537,10 @@ mpage_writepages(struct address_space *mapping, page_cache_release(page); write_lock(&mapping->page_lock); } - if (!list_empty(&mapping->io_pages)) { - /* - * Put the rest back, in the correct order. - */ - list_splice(&mapping->io_pages, mapping->dirty_pages.prev); - INIT_LIST_HEAD(&mapping->io_pages); - } + /* + * Put the rest back, in the correct order. + */ + list_splice_init(&mapping->io_pages, mapping->dirty_pages.prev); write_unlock(&mapping->page_lock); if (bio) mpage_bio_submit(WRITE, bio); diff --git a/fs/nfs/write.c b/fs/nfs/write.c index c57c01653abf..26fb344a3939 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -1110,8 +1110,7 @@ nfs_commit_rpcsetup(struct list_head *head, struct nfs_write_data *data) /* Set up the RPC argument and reply structs * NB: take care not to mess about with data->commit et al. */ - list_splice(head, &data->pages); - INIT_LIST_HEAD(head); + list_splice_init(head, &data->pages); first = nfs_list_entry(data->pages.next); last = nfs_list_entry(data->pages.prev); inode = first->wb_inode; diff --git a/include/linux/list.h b/include/linux/list.h index ac65cc310ab6..3e70aa03ac11 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -136,6 +136,19 @@ static inline int list_empty(list_t *head) return head->next == head; } +static inline void __list_splice(list_t *list, list_t *head) +{ + list_t *first = list->next; + list_t *last = list->prev; + list_t *at = head->next; + + first->prev = head; + head->next = first; + + last->next = at; + at->prev = last; +} + /** * list_splice - join two lists * @list: the new list to add. @@ -145,15 +158,22 @@ static inline void list_splice(list_t *list, list_t *head) { list_t *first = list->next; - if (first != list) { - list_t *last = list->prev; - list_t *at = head->next; - - first->prev = head; - head->next = first; + if (first != list) + __list_splice(list, head); +} - last->next = at; - at->prev = last; +/** + * list_splice_init - join two lists and reinitialise the emptied list. + * @list: the new list to add. + * @head: the place to add it in the first list. + * + * The list at @list is reinitialised + */ +static inline void list_splice_init(list_t *list, list_t *head) +{ + if (!list_empty(list)) { + __list_splice(list, head); + INIT_LIST_HEAD(list); } } |
