@@ -80,14 +80,37 @@ static inline int is_single_threaded(struct workqueue_struct *wq)
8080 return list_empty (& wq -> list );
8181}
8282
83+ static inline void set_wq_data (struct work_struct * work , void * wq )
84+ {
85+ unsigned long new , old , res ;
86+
87+ /* assume the pending flag is already set and that the task has already
88+ * been queued on this workqueue */
89+ new = (unsigned long ) wq | (1UL << WORK_STRUCT_PENDING );
90+ res = work -> management ;
91+ if (res != new ) {
92+ do {
93+ old = res ;
94+ new = (unsigned long ) wq ;
95+ new |= (old & WORK_STRUCT_FLAG_MASK );
96+ res = cmpxchg (& work -> management , old , new );
97+ } while (res != old );
98+ }
99+ }
100+
101+ static inline void * get_wq_data (struct work_struct * work )
102+ {
103+ return (void * ) (work -> management & WORK_STRUCT_WQ_DATA_MASK );
104+ }
105+
83106/* Preempt must be disabled. */
84107static void __queue_work (struct cpu_workqueue_struct * cwq ,
85108 struct work_struct * work )
86109{
87110 unsigned long flags ;
88111
89112 spin_lock_irqsave (& cwq -> lock , flags );
90- work -> wq_data = cwq ;
113+ set_wq_data ( work , cwq ) ;
91114 list_add_tail (& work -> entry , & cwq -> worklist );
92115 cwq -> insert_sequence ++ ;
93116 wake_up (& cwq -> more_work );
@@ -108,7 +131,7 @@ int fastcall queue_work(struct workqueue_struct *wq, struct work_struct *work)
108131{
109132 int ret = 0 , cpu = get_cpu ();
110133
111- if (!test_and_set_bit (0 , & work -> pending )) {
134+ if (!test_and_set_bit (WORK_STRUCT_PENDING , & work -> management )) {
112135 if (unlikely (is_single_threaded (wq )))
113136 cpu = singlethread_cpu ;
114137 BUG_ON (!list_empty (& work -> entry ));
@@ -123,7 +146,7 @@ EXPORT_SYMBOL_GPL(queue_work);
123146static void delayed_work_timer_fn (unsigned long __data )
124147{
125148 struct delayed_work * dwork = (struct delayed_work * )__data ;
126- struct workqueue_struct * wq = dwork -> work . wq_data ;
149+ struct workqueue_struct * wq = get_wq_data ( & dwork -> work ) ;
127150 int cpu = smp_processor_id ();
128151
129152 if (unlikely (is_single_threaded (wq )))
@@ -150,12 +173,12 @@ int fastcall queue_delayed_work(struct workqueue_struct *wq,
150173 if (delay == 0 )
151174 return queue_work (wq , work );
152175
153- if (!test_and_set_bit (0 , & work -> pending )) {
176+ if (!test_and_set_bit (WORK_STRUCT_PENDING , & work -> management )) {
154177 BUG_ON (timer_pending (timer ));
155178 BUG_ON (!list_empty (& work -> entry ));
156179
157180 /* This stores wq for the moment, for the timer_fn */
158- work -> wq_data = wq ;
181+ set_wq_data ( work , wq ) ;
159182 timer -> expires = jiffies + delay ;
160183 timer -> data = (unsigned long )dwork ;
161184 timer -> function = delayed_work_timer_fn ;
@@ -182,12 +205,12 @@ int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
182205 struct timer_list * timer = & dwork -> timer ;
183206 struct work_struct * work = & dwork -> work ;
184207
185- if (!test_and_set_bit (0 , & work -> pending )) {
208+ if (!test_and_set_bit (WORK_STRUCT_PENDING , & work -> management )) {
186209 BUG_ON (timer_pending (timer ));
187210 BUG_ON (!list_empty (& work -> entry ));
188211
189212 /* This stores wq for the moment, for the timer_fn */
190- work -> wq_data = wq ;
213+ set_wq_data ( work , wq ) ;
191214 timer -> expires = jiffies + delay ;
192215 timer -> data = (unsigned long )dwork ;
193216 timer -> function = delayed_work_timer_fn ;
@@ -223,8 +246,8 @@ static void run_workqueue(struct cpu_workqueue_struct *cwq)
223246 list_del_init (cwq -> worklist .next );
224247 spin_unlock_irqrestore (& cwq -> lock , flags );
225248
226- BUG_ON (work -> wq_data != cwq );
227- clear_bit (0 , & work -> pending );
249+ BUG_ON (get_wq_data ( work ) != cwq );
250+ clear_bit (WORK_STRUCT_PENDING , & work -> management );
228251 f (data );
229252
230253 spin_lock_irqsave (& cwq -> lock , flags );
0 commit comments