Coverage Report

Created: 2025-08-18 06:36

/src/nss/lib/pk11wrap/pk11list.c
Line
Count
Source (jump to first uncovered line)
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
/*
5
 * Locking and queue management primatives
6
 *
7
 */
8
9
#include "seccomon.h"
10
#include "nssilock.h"
11
#include "secmod.h"
12
#include "secmodi.h"
13
#include "secmodti.h"
14
#include "nssrwlk.h"
15
16
/*
17
 * create a new lock for a Module List
18
 */
19
SECMODListLock *
20
SECMOD_NewListLock()
21
11
{
22
11
    return NSSRWLock_New(10, "moduleListLock");
23
11
}
24
25
/*
26
 * destroy the lock
27
 */
28
void
29
SECMOD_DestroyListLock(SECMODListLock *lock)
30
11
{
31
11
    NSSRWLock_Destroy(lock);
32
11
}
33
34
/*
35
 * Lock the list for reading.
36
 * Note: this uses a non-reentrant lock. Writers are given preference.
37
 */
38
void
39
SECMOD_GetReadLock(SECMODListLock *modLock)
40
33.2k
{
41
33.2k
    NSSRWLock_LockRead(modLock);
42
33.2k
}
43
44
/*
45
 * Release the Read lock
46
 */
47
void
48
SECMOD_ReleaseReadLock(SECMODListLock *modLock)
49
33.2k
{
50
33.2k
    NSSRWLock_UnlockRead(modLock);
51
33.2k
}
52
53
/*
54
 * lock the list for Write
55
 */
56
void
57
SECMOD_GetWriteLock(SECMODListLock *modLock)
58
22
{
59
22
    NSSRWLock_LockWrite(modLock);
60
22
}
61
62
/*
63
 * Release the Write Lock: NOTE, this code is pretty inefficient if you have
64
 * lots of write collisions.
65
 */
66
void
67
SECMOD_ReleaseWriteLock(SECMODListLock *modLock)
68
22
{
69
22
    NSSRWLock_UnlockWrite(modLock);
70
22
}
71
72
/*
73
 * must Hold the Write lock
74
 */
75
void
76
SECMOD_RemoveList(SECMODModuleList **parent, SECMODModuleList *child)
77
0
{
78
0
    *parent = child->next;
79
0
    child->next = NULL;
80
0
}
81
82
/*
83
 * if lock is not specified, it must already be held
84
 */
85
void
86
SECMOD_AddList(SECMODModuleList *parent, SECMODModuleList *child,
87
               SECMODListLock *lock)
88
0
{
89
0
    if (lock) {
90
0
        SECMOD_GetWriteLock(lock);
91
0
    }
92
93
0
    child->next = parent->next;
94
0
    parent->next = child;
95
96
0
    if (lock) {
97
0
        SECMOD_ReleaseWriteLock(lock);
98
0
    }
99
0
}