• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aremmell / libsir / 1153

25 Jul 2023 04:30AM UTC coverage: 80.118% (-14.7%) from 94.801%
1153

push

travis-ci

aremmell
fix ternary

1 of 1 new or added line in 1 file covered. (100.0%)

2571 of 3209 relevant lines covered (80.12%)

24530.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.65
/src/sirmutex.c
1
/*
2
 * sirmutex.c
3
 *
4
 * Author:    Ryan M. Lederman <lederman@gmail.com>
5
 * Copyright: Copyright (c) 2018-2023
6
 * Version:   2.2.1
7
 * License:   The MIT License (MIT)
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
10
 * this software and associated documentation files (the "Software"), to deal in
11
 * the Software without restriction, including without limitation the rights to
12
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
13
 * the Software, and to permit persons to whom the Software is furnished to do so,
14
 * subject to the following conditions:
15
 *
16
 * The above copyright notice and this permission notice shall be included in all
17
 * copies or substantial portions of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
21
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
22
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
 */
26
#include "sir/mutex.h"
27
#include "sir/internal.h"
28
#include "sir/platform.h"
29

30
#if !defined(__WIN__) /* pthread implementation */
31
bool _sir_mutexcreate(sir_mutex* mutex) {
130✔
32
    if (_sir_validptr(mutex)) {
130✔
33
        pthread_mutexattr_t attr;
34
        int op = pthread_mutexattr_init(&attr);
127✔
35
        if (0 == op) {
127✔
36
            op = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
127✔
37
            if (0 == op) {
127✔
38
                op = pthread_mutex_init(mutex, &attr);
127✔
39
                if (0 == op)
127✔
40
                    return true;
127✔
41
            }
42
        }
43

44
        (void)_sir_handleerr(op);
×
45
    }
46

47
    return false;
×
48
}
49

50
bool _sir_mutexlock(sir_mutex* mutex) {
169,206✔
51
    if (_sir_validptr(mutex)) {
169,206✔
52
        int op = pthread_mutex_lock(mutex);
169,211✔
53
        return 0 == op ? true : _sir_handleerr(op);
169,169✔
54
    }
55

56
    return false;
×
57
}
58

59
bool _sir_mutextrylock(sir_mutex* mutex) {
6✔
60
    if (_sir_validptr(mutex)) {
6✔
61
        int op = pthread_mutex_trylock(mutex);
3✔
62
        return 0 == op ? true : _sir_handleerr(op);
3✔
63
    }
64

65
    return false;
×
66
}
67

68
bool _sir_mutexunlock(sir_mutex* mutex) {
169,213✔
69
    if (_sir_validptr(mutex)) {
169,213✔
70
        int op = pthread_mutex_unlock(mutex);
169,218✔
71
        return 0 == op ? true : _sir_handleerr(op);
169,217✔
72
    }
73

74
    return false;
×
75
}
76

77
bool _sir_mutexdestroy(sir_mutex* mutex) {
9✔
78
    if (_sir_validptr(mutex)) {
9✔
79
        int op = pthread_mutex_destroy(mutex);
6✔
80
        return 0 == op ? true : _sir_handleerr(op);
6✔
81
    }
82

83
    return false;
×
84
}
85
#else /* __WIN__ */
86
bool _sir_mutexcreate(sir_mutex* mutex) {
87
    if (_sir_validptr(mutex)) {
88
        InitializeCriticalSection(mutex);
89
        return true;
90
    }
91

92
    return false;
93
}
94

95
bool _sir_mutexlock(sir_mutex* mutex) {
96
    if (_sir_validptr(mutex)) {
97
        EnterCriticalSection(mutex);
98
        return true;
99
    }
100

101
    return false;
102
}
103

104
bool _sir_mutextrylock(sir_mutex* mutex) {
105
    if (_sir_validptr(mutex))
106
        return FALSE != TryEnterCriticalSection(mutex);
107

108
    return false;
109
}
110

111
bool _sir_mutexunlock(sir_mutex* mutex) {
112
    if (_sir_validptr(mutex)) {
113
        LeaveCriticalSection(mutex);
114
        return true;
115
    }
116

117
    return false;
118
}
119

120
bool _sir_mutexdestroy(sir_mutex* mutex) {
121
    if (_sir_validptr(mutex)) {
122
        DeleteCriticalSection(mutex);
123
        return true;
124
    }
125

126
    return false;
127
}
128
#endif /* !__WIN__ */
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc