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

krakjoe / parallel / 20316825147

17 Dec 2025 08:49PM UTC coverage: 94.99% (+4.1%) from 90.94%
20316825147

push

github

realFlowControl
fix build

2844 of 2994 relevant lines covered (94.99%)

6435.16 hits per line

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

93.75
/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,570✔
24
{
25
        php_parallel_monitor_t *monitor = (php_parallel_monitor_t *)calloc(1, sizeof(php_parallel_monitor_t));
6,570✔
26

27
        php_parallel_mutex_init(&monitor->mutex, 1);
6,570✔
28
        php_parallel_cond_init(&monitor->condition);
6,570✔
29

30
        return monitor;
6,570✔
31
}
32

33
int     php_parallel_monitor_lock(php_parallel_monitor_t *monitor) { return pthread_mutex_lock(&monitor->mutex); }
13,969✔
34

35
int32_t php_parallel_monitor_check(php_parallel_monitor_t *monitor, int32_t state)
18,973✔
36
{
37
        return (monitor->state & (state));
18,973✔
38
}
39

40
int     php_parallel_monitor_unlock(php_parallel_monitor_t *monitor) { return pthread_mutex_unlock(&monitor->mutex); }
13,966✔
41

42
int32_t php_parallel_monitor_wait(php_parallel_monitor_t *monitor, int32_t state)
2,202✔
43
{
44
        int32_t changed = FAILURE;
2,202✔
45
        int     rc = SUCCESS;
2,202✔
46

47
        if (pthread_mutex_lock(&monitor->mutex) != SUCCESS) {
2,202✔
48
                return FAILURE;
49
        }
50

51
        while (!(changed = (monitor->state & state))) {
4,404✔
52

53
                if ((rc = pthread_cond_wait(&monitor->condition, &monitor->mutex)) != SUCCESS) {
2,202✔
54
                        pthread_mutex_unlock(&monitor->mutex);
×
55

56
                        return FAILURE;
×
57
                }
58
        }
59

60
        monitor->state ^= changed;
2,202✔
61

62
        if (pthread_mutex_unlock(&monitor->mutex) != SUCCESS) {
2,202✔
63
                return FAILURE;
×
64
        }
65

66
        return changed;
67
}
68

69
int32_t php_parallel_monitor_wait_locked(php_parallel_monitor_t *monitor, int32_t state)
6,950✔
70
{
71
        int32_t changed = FAILURE;
6,950✔
72
        int     rc = SUCCESS;
6,950✔
73

74
        while (!(changed = (monitor->state & state))) {
13,240✔
75
                if ((rc = pthread_cond_wait(&monitor->condition, &monitor->mutex)) != SUCCESS) {
6,290✔
76
                        return FAILURE;
77
                }
78
        }
79

80
        monitor->state ^= changed;
6,950✔
81

82
        return changed;
6,950✔
83
}
84

85
void php_parallel_monitor_set(php_parallel_monitor_t *monitor, int32_t state)
11,773✔
86
{
87
        pthread_mutex_lock(&monitor->mutex);
11,773✔
88

89
        monitor->state |= state;
11,773✔
90

91
        pthread_cond_signal(&monitor->condition);
11,773✔
92

93
        pthread_mutex_unlock(&monitor->mutex);
11,773✔
94
}
11,773✔
95

96
void php_parallel_monitor_add(php_parallel_monitor_t *monitor, int32_t state)
1,917✔
97
{
98
        pthread_mutex_lock(&monitor->mutex);
1,917✔
99

100
        monitor->state |= state;
1,918✔
101

102
        pthread_mutex_unlock(&monitor->mutex);
1,918✔
103
}
1,918✔
104

105
void php_parallel_monitor_remove(php_parallel_monitor_t *monitor, int32_t state)
3,936✔
106
{
107
        pthread_mutex_lock(&monitor->mutex);
3,936✔
108

109
        monitor->state &= ~state;
3,936✔
110

111
        pthread_mutex_unlock(&monitor->mutex);
3,936✔
112
}
3,936✔
113

114
void php_parallel_monitor_destroy(php_parallel_monitor_t *monitor)
6,570✔
115
{
116
        php_parallel_mutex_destroy(&monitor->mutex);
6,570✔
117
        php_parallel_cond_destroy(&monitor->condition);
6,570✔
118

119
        free(monitor);
6,570✔
120
}
6,570✔
121
#endif
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

© 2026 Coveralls, Inc