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

krakjoe / parallel / 30916206264

04 Aug 2026 01:54PM UTC coverage: 94.962% (-0.08%) from 95.041%
30916206264

Pull #392

github

web-flow
Merge 04e87b26a into e0b2788fa
Pull Request #392: Replace `Events` polling with notifications

156 of 171 new or added lines in 4 files covered. (91.23%)

20 existing lines in 1 file now uncovered.

3035 of 3196 relevant lines covered (94.96%)

4863.22 hits per line

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

90.0
/src/notify.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_NOTIFY
19
#define HAVE_PARALLEL_NOTIFY
20

21
#include "notify.h"
22

23
#ifndef _WIN32
24
#include <errno.h>
25
#include <fcntl.h>
26
#include <unistd.h>
27
#endif
28

29
void php_parallel_notify_init(php_parallel_notify_t *notify)
45,165✔
30
{
31
        notify->read = -1;
45,165✔
32
        notify->write = -1;
45,165✔
33
        notify->raised = false;
45,165✔
34
}
45,165✔
35

36
#ifndef _WIN32
37
static bool php_parallel_notify_flags(int descriptor)
18,630✔
38
{
39
        int flags = fcntl(descriptor, F_GETFL);
18,630✔
40

41
        if (flags == -1 || fcntl(descriptor, F_SETFL, flags | O_NONBLOCK) == -1) {
18,630✔
NEW
42
                return false;
×
43
        }
44

45
        flags = fcntl(descriptor, F_GETFD);
18,630✔
46

47
        return flags != -1 && fcntl(descriptor, F_SETFD, flags | FD_CLOEXEC) != -1;
18,630✔
48
}
49

50
static bool php_parallel_notify_create(php_parallel_notify_t *notify)
9,315✔
51
{
52
        int descriptors[2];
9,315✔
53

54
        if (pipe(descriptors) == -1) {
9,315✔
55
                return false;
56
        }
57

58
        if (!php_parallel_notify_flags(descriptors[0]) || !php_parallel_notify_flags(descriptors[1])) {
9,315✔
NEW
59
                close(descriptors[0]);
×
NEW
60
                close(descriptors[1]);
×
NEW
61
                return false;
×
62
        }
63

64
        notify->read = descriptors[0];
9,315✔
65
        notify->write = descriptors[1];
9,315✔
66

67
        return true;
9,315✔
68
}
69

70
#endif
71

72
int php_parallel_notify_observe(php_parallel_notify_t *notify, bool ready)
12,875✔
73
{
74
#ifdef _WIN32
75
        return -1;
76
#else
77
        if (notify->read == -1 && !php_parallel_notify_create(notify)) {
12,875✔
78
                return -1;
79
        }
80

81
        php_parallel_notify_sync(notify, ready);
12,875✔
82

83
        return notify->read;
12,875✔
84
#endif
85
}
86

87
void php_parallel_notify_sync(php_parallel_notify_t *notify, bool ready)
48,634✔
88
{
89
#ifndef _WIN32
90
        char    byte = 0;
48,634✔
91
        ssize_t result;
48,634✔
92

93
        if (notify->read == -1 || notify->raised == ready) {
48,634✔
94
                return;
41,258✔
95
        }
96

97
        do {
7,376✔
98
                result = ready ? write(notify->write, &byte, sizeof(byte)) : read(notify->read, &byte, sizeof(byte));
7,376✔
99
        } while (result == -1 && errno == EINTR);
7,376✔
100

101
        if (result == sizeof(byte) || (result == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))) {
7,376✔
102
                notify->raised = ready;
7,376✔
103
        }
104
#endif
105
}
106

107
void php_parallel_notify_destroy(php_parallel_notify_t *notify)
45,165✔
108
{
109
#ifndef _WIN32
110
        if (notify->read != -1) {
45,165✔
111
                close(notify->read);
9,315✔
112
                close(notify->write);
9,315✔
113
        }
114
#endif
115
}
45,165✔
116
#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