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

krakjoe / parallel / 20273776347

16 Dec 2025 03:42PM UTC coverage: 96.75% (-0.07%) from 96.815%
20273776347

Pull #357

github

web-flow
Merge 324a13a76 into 14042a874
Pull Request #357: Cleanup code formatting and docs

1527 of 1615 new or added lines in 27 files covered. (94.55%)

1 existing line in 1 file now uncovered.

2798 of 2892 relevant lines covered (96.75%)

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

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

30
    return monitor;
6,492✔
31
}
32

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

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

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

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

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

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

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

NEW
56
            return FAILURE;
×
57
        }
58
    }
59

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

62
    if (pthread_mutex_unlock(&monitor->mutex) != SUCCESS) {
2,184✔
NEW
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,888✔
70
{
71
    int32_t changed = FAILURE;
6,888✔
72
    int rc = SUCCESS;
6,888✔
73

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

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

82
    return changed;
6,888✔
83
}
84

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

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

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

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

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

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

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

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

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

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

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

119
    free(monitor);
6,492✔
120
}
6,492✔
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