Coverage Report

Created: 2024-11-21 07:03

/src/nss-nspr/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
2
{
22
2
    return NSSRWLock_New(10, "moduleListLock");
23
2
}
24
25
/*
26
 * destroy the lock
27
 */
28
void
29
SECMOD_DestroyListLock(SECMODListLock *lock)
30
0
{
31
0
    NSSRWLock_Destroy(lock);
32
0
}
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
49
{
41
49
    NSSRWLock_LockRead(modLock);
42
49
}
43
44
/*
45
 * Release the Read lock
46
 */
47
void
48
SECMOD_ReleaseReadLock(SECMODListLock *modLock)
49
49
{
50
49
    NSSRWLock_UnlockRead(modLock);
51
49
}
52
53
/*
54
 * lock the list for Write
55
 */
56
void
57
SECMOD_GetWriteLock(SECMODListLock *modLock)
58
4
{
59
4
    NSSRWLock_LockWrite(modLock);
60
4
}
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
4
{
69
4
    NSSRWLock_UnlockWrite(modLock);
70
4
}
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
}