toolbox

Check-in [f049f8915e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:radios-check: simplify job data structure
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:f049f8915ecd578895f8099f699dee277916c0abd7c585c9adf2be9d262e9429
User & Date: jef 2019-04-17 08:56:51
Context
2019-04-23
08:43
renew: add checks after popen calls check-in: 454cd3f8a2 user: jef tags: trunk
2019-04-17
08:56
radios-check: simplify job data structure check-in: f049f8915e user: jef tags: trunk
2019-04-16
12:26
radios-check: remove superfluous polling check-in: 90f21a92ca user: jef tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/radios-check/radios-check.c.

19
20
21
22
23
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
...
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
...
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
struct buffer {
	char *data;
	size_t cap;
	size_t size;
};

struct job {
	struct radio *radio;
	pid_t pid;
	int fd;
	struct job_res {
		struct radio *radio;
		int ok;
	} res;

};

struct radio {
	char *name;
	char *stream;
	int ok;
	TAILQ_ENTRY(radio) next;
................................................................................
	pid_t pid = fork();
	switch (pid) {
	case -1:
		die("fork error");
		break;
	case 0:
		close(fds[0]);
		radio_set_status(job->radio);
		job->res.radio = job->radio;
		job->res.ok = job->radio->ok;
		towrite = sizeof(job->res);
		if (write(fds[1], &job->res, towrite) != towrite)
			die("write error");
		close(fds[1]);
		exit(0);
		break;
	}

	close(fds[1]);
................................................................................
	int status;
	pid_t pid;
	struct job job;

	pid = waitpid(-1, &status, 0);
	for (i = 0; jobs[i].pid != pid; i++);
	job = jobs[i];
	if (read(job.fd, &job.res, sizeof(job.res)) == sizeof(job.res))
		job.res.radio->ok = job.res.ok;
	close(job.fd);
	memmove(jobs + i, jobs + i + 1, (size - i - 1) * sizeof(struct job));
}

void
radios_pcheck(struct radios *radios)
{
................................................................................

	TAILQ_FOREACH(radio, radios, next) {
		if (nrunning >= nthreads) {
			job_wait(jobs, nthreads);
			nrunning--;
		}

		jobs[nrunning].radio = radio;
		job_run(&jobs[nrunning]);
		nrunning++;
	}

	/* wait for pending jobs */
	while (nrunning > 0) {
		job_wait(jobs, nthreads);







<


|


<
>







 







|
|
<
|
|







 







|
|







 







|







19
20
21
22
23
24
25

26
27
28
29
30

31
32
33
34
35
36
37
38
...
201
202
203
204
205
206
207
208
209

210
211
212
213
214
215
216
217
218
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
struct buffer {
	char *data;
	size_t cap;
	size_t size;
};

struct job {

	pid_t pid;
	int fd;
	struct job_data {
		struct radio *radio;
		int ok;

	} data;
};

struct radio {
	char *name;
	char *stream;
	int ok;
	TAILQ_ENTRY(radio) next;
................................................................................
	pid_t pid = fork();
	switch (pid) {
	case -1:
		die("fork error");
		break;
	case 0:
		close(fds[0]);
		radio_set_status(job->data.radio);
		job->data.ok = job->data.radio->ok;

		towrite = sizeof(job->data);
		if (write(fds[1], &job->data, towrite) != towrite)
			die("write error");
		close(fds[1]);
		exit(0);
		break;
	}

	close(fds[1]);
................................................................................
	int status;
	pid_t pid;
	struct job job;

	pid = waitpid(-1, &status, 0);
	for (i = 0; jobs[i].pid != pid; i++);
	job = jobs[i];
	if (read(job.fd, &job.data, sizeof(job.data)) == sizeof(job.data))
		job.data.radio->ok = job.data.ok;
	close(job.fd);
	memmove(jobs + i, jobs + i + 1, (size - i - 1) * sizeof(struct job));
}

void
radios_pcheck(struct radios *radios)
{
................................................................................

	TAILQ_FOREACH(radio, radios, next) {
		if (nrunning >= nthreads) {
			job_wait(jobs, nthreads);
			nrunning--;
		}

		jobs[nrunning].data.radio = radio;
		job_run(&jobs[nrunning]);
		nrunning++;
	}

	/* wait for pending jobs */
	while (nrunning > 0) {
		job_wait(jobs, nthreads);