History

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.

Tejun Heo committed 13 years ago

Commit ebf44d11 parent bc3a1af1 file · +23 −24Browse files

Showing the changes to kernel/workqueue.c (1 of 1 file). Show all

Unified · Split

kernel/workqueue.c+23−24
@@ -1792,6 +1792,26 @@ static void start_worker(struct worker *worker) · 1791 unmodified lines
17921792 wake_up_process(worker->task);
17931793 }
17941794
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+ */
1801+static 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+
17951815 /**
17961816 * destroy_worker - destroy a workqueue worker
17971817 * @worker: worker to be destroyed
@@ -3542,7 +3562,6 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs) · 1744 unmodified lines
35423562 static DEFINE_MUTEX(create_mutex);
35433563 u32 hash = wqattrs_hash(attrs);
35443564 struct worker_pool *pool;
3545− struct worker *worker;
35463565
35473566 mutex_lock(&create_mutex);
35483567
@@ -3568,14 +3587,9 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs) · 19 unmodified lines
35683587 goto fail;
35693588
35703589 /* create and start the initial worker */
3571− worker = create_worker(pool);
3572− if (!worker)
3590+ if (create_and_start_worker(pool) < 0)
35733591 goto fail;
35743592
3575− spin_lock_irq(&pool->lock);
3576− start_worker(worker);
3577− spin_unlock_irq(&pool->lock);
3578−
35793593 /* install */
35803594 spin_lock_irq(&workqueue_lock);
35813595 hash_add(unbound_pool_hash, &pool->hash_node, hash);
@@ -4148,18 +4162,10 @@ static int __cpuinit workqueue_cpu_up_callback(struct notifier_block *nfb, · 566 unmodified lines
41484162 switch (action & ~CPU_TASKS_FROZEN) {
41494163 case CPU_UP_PREPARE:
41504164 for_each_cpu_worker_pool(pool, cpu) {
4151− struct worker *worker;
4152−
41534165 if (pool->nr_workers)
41544166 continue;
4155−
4156− worker = create_worker(pool);
4157− if (!worker)
4167+ if (create_and_start_worker(pool) < 0)
41584168 return NOTIFY_BAD;
4159−
4160− spin_lock_irq(&pool->lock);
4161− start_worker(worker);
4162− spin_unlock_irq(&pool->lock);
41634169 }
41644170 break;
41654171
@@ -4409,15 +4415,8 @@ static int __init init_workqueues(void) · 243 unmodified lines
44094415 struct worker_pool *pool;
44104416
44114417 for_each_cpu_worker_pool(pool, cpu) {
4412− struct worker *worker;
4413−
44144418 pool->flags &= ~POOL_DISASSOCIATED;
4415−
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);
4419+ BUG_ON(create_and_start_worker(pool) < 0);
44214420 }
44224421 }
44234422