函数源码

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source File:ipc\sem.c Create Date:2022-07-27 18:19:22
首页 Copyright©Brick

1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
/* The following counts are associated to each semaphore:
 *   semncnt        number of tasks waiting on semval being nonzero
 *   semzcnt        number of tasks waiting on semval being zero
 *
 * Per definition, a task waits only on the semaphore of the first semop
 * that cannot proceed, even if additional operation would block, too.
 */
static int count_semcnt(struct sem_array *sma, ushort semnum,
            bool count_zero)
{
    struct list_head *l;
    struct sem_queue *q;
    int semcnt;
 
    semcnt = 0;
    /* First: check the simple operations. They are easy to evaluate */
    if (count_zero)
        l = &sma->sems[semnum].pending_const;
    else
        l = &sma->sems[semnum].pending_alter;
 
    list_for_each_entry(q, l, list) {
        /* all task on a per-semaphore list sleep on exactly
         * that semaphore
         */
        semcnt++;
    }
 
    /* Then: check the complex operations. */
    list_for_each_entry(q, &sma->pending_alter, list) {
        semcnt += check_qop(sma, semnum, q, count_zero);
    }
    if (count_zero) {
        list_for_each_entry(q, &sma->pending_const, list) {
            semcnt += check_qop(sma, semnum, q, count_zero);
        }
    }
    return semcnt;
}