aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/workqueue.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-03-13 22:47:39 -0400
committerTejun Heo <tj@kernel.org>2013-03-13 22:47:39 -0400
commitebf44d16ec4619c8a8daeacd987dd86d420ea2c3 (patch)
tree501bb8fbeda2ff67d71af733c3c56150053a4351 /kernel/workqueue.c
parentbc3a1afc92aea46d6df18d38e5d15867b17c69f6 (diff)
workqueue: factor out initial worker creation into create_and_start_worker()
get_unbound_pool(), workqueue_cpu_up_callback() and init_workqueues() have similar code pieces to create and start the initial worker factor those out into create_and_start_worker(). This patch doesn't introduce any functional changes. Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel/workqueue.c')
-rw-r--r--kernel/workqueue.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index bc25bdfb4b42..cac710646cbc 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1793,6 +1793,26 @@ static void start_worker(struct worker *worker)
1793} 1793}
1794 1794
1795/** 1795/**
1796 * create_and_start_worker - create and start a worker for a pool
1797 * @pool: the target pool
1798 *
1799 * Create and start a new worker for @pool.
1800 */
1801static int create_and_start_worker(struct worker_pool *pool)
1802{
1803 struct worker *worker;
1804
1805 worker = create_worker(pool);
1806 if (worker) {
1807 spin_lock_irq(&pool->lock);
1808 start_worker(worker);
1809 spin_unlock_irq(&pool->lock);
1810 }
1811
1812 return worker ? 0 : -ENOMEM;
1813}
1814
1815/**
1796 * destroy_worker - destroy a workqueue worker 1816 * destroy_worker - destroy a workqueue worker
1797 * @worker: worker to be destroyed 1817 * @worker: worker to be destroyed
1798 * 1818 *
@@ -3542,7 +3562,6 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs)
3542 static DEFINE_MUTEX(create_mutex); 3562 static DEFINE_MUTEX(create_mutex);
3543 u32 hash = wqattrs_hash(attrs); 3563 u32 hash = wqattrs_hash(attrs);
3544 struct worker_pool *pool; 3564 struct worker_pool *pool;
3545 struct worker *worker;
3546 3565
3547 mutex_lock(&create_mutex); 3566 mutex_lock(&create_mutex);
3548 3567
@@ -3568,14 +3587,9 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs)
3568 goto fail; 3587 goto fail;
3569 3588
3570 /* create and start the initial worker */ 3589 /* create and start the initial worker */
3571 worker = create_worker(pool); 3590 if (create_and_start_worker(pool) < 0)
3572 if (!worker)
3573 goto fail; 3591 goto fail;
3574 3592
3575 spin_lock_irq(&pool->lock);
3576 start_worker(worker);
3577 spin_unlock_irq(&pool->lock);
3578
3579 /* install */ 3593 /* install */
3580 spin_lock_irq(&workqueue_lock); 3594 spin_lock_irq(&workqueue_lock);
3581 hash_add(unbound_pool_hash, &pool->hash_node, hash); 3595 hash_add(unbound_pool_hash, &pool->hash_node, hash);
@@ -4148,18 +4162,10 @@ static int __cpuinit workqueue_cpu_up_callback(struct notifier_block *nfb,
4148 switch (action & ~CPU_TASKS_FROZEN) { 4162 switch (action & ~CPU_TASKS_FROZEN) {
4149 case CPU_UP_PREPARE: 4163 case CPU_UP_PREPARE:
4150 for_each_cpu_worker_pool(pool, cpu) { 4164 for_each_cpu_worker_pool(pool, cpu) {
4151 struct worker *worker;
4152
4153 if (pool->nr_workers) 4165 if (pool->nr_workers)
4154 continue; 4166 continue;
4155 4167 if (create_and_start_worker(pool) < 0)
4156 worker = create_worker(pool);
4157 if (!worker)
4158 return NOTIFY_BAD; 4168 return NOTIFY_BAD;
4159
4160 spin_lock_irq(&pool->lock);
4161 start_worker(worker);
4162 spin_unlock_irq(&pool->lock);
4163 } 4169 }
4164 break; 4170 break;
4165 4171
@@ -4409,15 +4415,8 @@ static int __init init_workqueues(void)
4409 struct worker_pool *pool; 4415 struct worker_pool *pool;
4410 4416
4411 for_each_cpu_worker_pool(pool, cpu) { 4417 for_each_cpu_worker_pool(pool, cpu) {
4412 struct worker *worker;
4413
4414 pool->flags &= ~POOL_DISASSOCIATED; 4418 pool->flags &= ~POOL_DISASSOCIATED;
4415 4419 BUG_ON(create_and_start_worker(pool) < 0);
4416 worker = create_worker(pool);
4417 BUG_ON(!worker);
4418 spin_lock_irq(&pool->lock);
4419 start_worker(worker);
4420 spin_unlock_irq(&pool->lock);
4421 } 4420 }
4422 } 4421 }
4423 4422