函数源码

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source File:kernel\sched\completion.c Create Date:2022-07-27 10:41:54
首页 Copyright©Brick

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/**
 *  try_wait_for_completion - try to decrement a completion without blocking
 *  @x: completion structure
 *
 *  Return: 0 if a decrement cannot be done without blocking
 *       1 if a decrement succeeded.
 *
 *  If a completion is being used as a counting completion,
 *  attempt to decrement the counter without blocking. This
 *  enables us to avoid waiting if the resource the completion
 *  is protecting is not available.
 */
bool try_wait_for_completion(struct completion *x)
{
    unsigned long flags;
    bool ret = true;
 
    /*
     * Since x->done will need to be locked only
     * in the non-blocking case, we check x->done
     * first without taking the lock so we can
     * return early in the blocking case.
     */
    if (!READ_ONCE(x->done))
        return false;
 
    spin_lock_irqsave(&x->wait.lock, flags);
    if (!x->done)
        ret = false;
    else if (x->done != UINT_MAX)
        x->done--;
    spin_unlock_irqrestore(&x->wait.lock, flags);
    return ret;
}