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

krakjoe / parallel / 30910510702

04 Aug 2026 12:43PM UTC coverage: 94.916% (-0.1%) from 95.041%
30910510702

Pull #392

github

web-flow
Merge acac9f4ee into 6447fd2a9
Pull Request #392: WIP

184 of 201 new or added lines in 4 files covered. (91.54%)

9 existing lines in 2 files now uncovered.

3062 of 3226 relevant lines covered (94.92%)

4736.36 hits per line

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

95.24
/src/monitor.c
1
/*
2
  +----------------------------------------------------------------------+
3
  | parallel                                                             |
4
  +----------------------------------------------------------------------+
5
  | Copyright (c) Joe Watkins 2019-2024                                  |
6
  +----------------------------------------------------------------------+
7
  | This source file is subject to version 3.01 of the PHP license,      |
8
  | that is bundled with this package in the file LICENSE, and is        |
9
  | available through the world-wide-web at the following url:           |
10
  | http://www.php.net/license/3_01.txt                                  |
11
  | If you did not receive a copy of the PHP license and are unable to   |
12
  | obtain it through the world-wide-web, please send a note to          |
13
  | license@php.net so we can mail you a copy immediately.               |
14
  +----------------------------------------------------------------------+
15
  | Author: krakjoe                                                      |
16
  +----------------------------------------------------------------------+
17
 */
18
#ifndef HAVE_PARALLEL_MONITOR
19
#define HAVE_PARALLEL_MONITOR
20

21
#include "parallel.h"
22

23
php_parallel_monitor_t *php_parallel_monitor_create(void)
6,945✔
24
{
25
        php_parallel_monitor_t *monitor = (php_parallel_monitor_t *)calloc(1, sizeof(php_parallel_monitor_t));
6,945✔
26

27
        php_parallel_mutex_init(&monitor->mutex, 1);
6,945✔
28
        php_parallel_cond_init(&monitor->condition);
6,945✔
29
        php_parallel_notify_init(&monitor->notify);
6,945✔
30

31
        return monitor;
6,945✔
32
}
33

34
int     php_parallel_monitor_lock(php_parallel_monitor_t *monitor) { return pthread_mutex_lock(&monitor->mutex); }
77,045✔
35

36
int32_t php_parallel_monitor_check(php_parallel_monitor_t *monitor, int32_t state)
64,751✔
37
{
38
        int32_t result;
64,751✔
39

40
        pthread_mutex_lock(&monitor->mutex);
64,751✔
41
        result = monitor->state & state;
64,751✔
42
        pthread_mutex_unlock(&monitor->mutex);
64,751✔
43

44
        return result;
64,751✔
45
}
46

47
int php_parallel_monitor_unlock(php_parallel_monitor_t *monitor) { return pthread_mutex_unlock(&monitor->mutex); }
77,045✔
48

49
static zend_always_inline void php_parallel_monitor_notify_sync(php_parallel_monitor_t *monitor)
28,385✔
50
{
51
        if (monitor->notify.read != -1) {
28,385✔
52
                php_parallel_notify_sync(&monitor->notify, monitor->state & PHP_PARALLEL_READY);
36✔
53
        }
54
}
55

56
int32_t php_parallel_monitor_wait(php_parallel_monitor_t *monitor, int32_t state)
2,274✔
57
{
58
        int32_t changed = FAILURE;
2,274✔
59
        int     rc = SUCCESS;
2,274✔
60

61
        if (pthread_mutex_lock(&monitor->mutex) != SUCCESS) {
2,274✔
62
                return FAILURE;
63
        }
64

65
        while (!(changed = (monitor->state & state))) {
4,548✔
66

67
                if ((rc = pthread_cond_wait(&monitor->condition, &monitor->mutex)) != SUCCESS) {
2,274✔
68
                        pthread_mutex_unlock(&monitor->mutex);
×
69

UNCOV
70
                        return FAILURE;
×
71
                }
72
        }
73

74
        monitor->state ^= changed;
2,274✔
75
        php_parallel_monitor_notify_sync(monitor);
2,274✔
76

77
        if (pthread_mutex_unlock(&monitor->mutex) != SUCCESS) {
2,274✔
UNCOV
78
                return FAILURE;
×
79
        }
80

81
        return changed;
82
}
83

84
int32_t php_parallel_monitor_wait_locked(php_parallel_monitor_t *monitor, int32_t state)
7,333✔
85
{
86
        int32_t changed = FAILURE;
7,333✔
87
        int     rc = SUCCESS;
7,333✔
88

89
        while (!(changed = (monitor->state & state))) {
13,973✔
90
                if ((rc = pthread_cond_wait(&monitor->condition, &monitor->mutex)) != SUCCESS) {
6,640✔
91
                        return FAILURE;
92
                }
93
        }
94

95
        monitor->state ^= changed;
7,333✔
96
        php_parallel_monitor_notify_sync(monitor);
7,333✔
97

98
        return changed;
99
}
100

101
void php_parallel_monitor_set(php_parallel_monitor_t *monitor, int32_t state)
12,534✔
102
{
103
        pthread_mutex_lock(&monitor->mutex);
12,534✔
104

105
        monitor->state |= state;
12,534✔
106
        php_parallel_monitor_notify_sync(monitor);
12,534✔
107

108
        pthread_cond_signal(&monitor->condition);
12,534✔
109

110
        pthread_mutex_unlock(&monitor->mutex);
12,534✔
111
}
12,534✔
112

113
void php_parallel_monitor_add(php_parallel_monitor_t *monitor, int32_t state)
2,082✔
114
{
115
        pthread_mutex_lock(&monitor->mutex);
2,082✔
116

117
        monitor->state |= state;
2,081✔
118
        php_parallel_monitor_notify_sync(monitor);
2,081✔
119

120
        pthread_mutex_unlock(&monitor->mutex);
2,081✔
121
}
2,081✔
122

123
void php_parallel_monitor_remove(php_parallel_monitor_t *monitor, int32_t state)
4,163✔
124
{
125
        pthread_mutex_lock(&monitor->mutex);
4,163✔
126

127
        monitor->state &= ~state;
4,163✔
128
        php_parallel_monitor_notify_sync(monitor);
4,163✔
129

130
        pthread_mutex_unlock(&monitor->mutex);
4,163✔
131
}
4,163✔
132

133
int php_parallel_monitor_notify(php_parallel_monitor_t *monitor)
36✔
134
{
135
        return php_parallel_notify_observe(&monitor->notify, monitor->state & PHP_PARALLEL_READY);
36✔
136
}
137

138
void php_parallel_monitor_destroy(php_parallel_monitor_t *monitor)
6,945✔
139
{
140
        php_parallel_notify_destroy(&monitor->notify);
6,945✔
141
        php_parallel_mutex_destroy(&monitor->mutex);
6,945✔
142
        php_parallel_cond_destroy(&monitor->condition);
6,945✔
143

144
        free(monitor);
6,945✔
145
}
6,945✔
146
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc