mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-19 15:33:56 +00:00
Fixed error checking of pthread(3) functions.
PR: 143807 Submitted by: pluknet (partly)
This commit is contained in:
parent
a66d183c7b
commit
2949bd100b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=203800
@ -113,7 +113,7 @@ main(__unused int argc, __unused char *argv[])
|
||||
err(-1, "bind");
|
||||
if (listen(listen_fd, -1) <0)
|
||||
err(-1, "listen");
|
||||
if (pthread_create(&accept_thread, NULL, do_accept, NULL) < 0)
|
||||
if (pthread_create(&accept_thread, NULL, do_accept, NULL) != 0)
|
||||
err(-1, "pthread_create");
|
||||
sleep(1); /* Easier than using a CV. */;
|
||||
do_fork();
|
||||
|
@ -241,7 +241,7 @@ main(int argc, char **argv) {
|
||||
fflush(stdout);
|
||||
for (i = 0; i < nworkers; i++) {
|
||||
if (pthread_create(&workers[i].w_thread, NULL, work,
|
||||
&workers[i]) == -1)
|
||||
&workers[i]) != 0)
|
||||
err(1, "creating worker %u", i);
|
||||
printf("%u%s", i, i == nworkers - 1 ? ".\n" : ", ");
|
||||
fflush(stdout);
|
||||
|
@ -368,7 +368,7 @@ int source(char *interface, struct in_addr *group, int pkt_size,
|
||||
args[i].packets = received[i];
|
||||
args[i].number = number / clients;
|
||||
args[i].client = base_port + i;
|
||||
if (pthread_create(&thread[i], NULL, server, &args[i]) < 0) {
|
||||
if (pthread_create(&thread[i], NULL, server, &args[i]) != 0) {
|
||||
perror("failed to create server thread");
|
||||
return -1;
|
||||
}
|
||||
@ -393,7 +393,7 @@ int source(char *interface, struct in_addr *group, int pkt_size,
|
||||
}
|
||||
|
||||
for (int i = 0; i < clients; i++) {
|
||||
if (pthread_join(thread[i], NULL) < 0) {
|
||||
if (pthread_join(thread[i], NULL) != 0) {
|
||||
perror("failed to join thread");
|
||||
return -1;
|
||||
}
|
||||
|
@ -300,15 +300,15 @@ main(int argc, char *argv[])
|
||||
|
||||
if (threaded) {
|
||||
if (pthread_barrier_init(&statep->start_barrier, NULL,
|
||||
numthreads) < 0)
|
||||
err(-1, "pthread_mutex_init");
|
||||
numthreads) != 0)
|
||||
err(-1, "pthread_barrier_init");
|
||||
}
|
||||
|
||||
for (i = 0; i < numthreads; i++) {
|
||||
statep->hwd[i].hwd_count = 0;
|
||||
if (threaded) {
|
||||
if (pthread_create(&statep->hwd[i].hwd_thread, NULL,
|
||||
http_worker, &statep->hwd[i]) < 0)
|
||||
http_worker, &statep->hwd[i]) != 0)
|
||||
err(-1, "pthread_create");
|
||||
} else {
|
||||
curthread = i;
|
||||
@ -339,7 +339,7 @@ main(int argc, char *argv[])
|
||||
for (i = 0; i < numthreads; i++) {
|
||||
if (threaded) {
|
||||
if (pthread_join(statep->hwd[i].hwd_thread, NULL)
|
||||
< 0)
|
||||
!= 0)
|
||||
err(-1, "pthread_join");
|
||||
} else {
|
||||
pid = waitpid(statep->hwd[i].hwd_pid, NULL, 0);
|
||||
|
@ -280,7 +280,7 @@ main(int argc, char *argv[])
|
||||
for (i = 0; i < THREADS; i++) {
|
||||
if (threaded) {
|
||||
if (pthread_create(&statep->hts[i].hts_thread, NULL,
|
||||
httpd_worker, &statep->hts[i]) < 0)
|
||||
httpd_worker, &statep->hts[i]) != 0)
|
||||
err(-1, "pthread_create");
|
||||
} else {
|
||||
pid = fork();
|
||||
@ -299,7 +299,7 @@ main(int argc, char *argv[])
|
||||
for (i = 0; i < THREADS; i++) {
|
||||
if (threaded) {
|
||||
if (pthread_join(statep->hts[i].hts_thread, NULL)
|
||||
< 0)
|
||||
!= 0)
|
||||
err(-1, "pthread_join");
|
||||
} else {
|
||||
pid = waitpid(statep->hts[i].hts_pid, NULL, 0);
|
||||
|
@ -301,15 +301,15 @@ juggling_thread(void *arg)
|
||||
|
||||
fd2 = *(int *)arg;
|
||||
|
||||
if (pthread_mutex_lock(&threaded_mtx) < 0)
|
||||
if (pthread_mutex_lock(&threaded_mtx) != 0)
|
||||
err(-1, "juggling_thread: pthread_mutex_lock");
|
||||
|
||||
threaded_child_ready = 1;
|
||||
|
||||
if (pthread_cond_signal(&threaded_cond) < 0)
|
||||
if (pthread_cond_signal(&threaded_cond) != 0)
|
||||
err(-1, "juggling_thread: pthread_cond_signal");
|
||||
|
||||
if (pthread_mutex_unlock(&threaded_mtx) < 0)
|
||||
if (pthread_mutex_unlock(&threaded_mtx) != 0)
|
||||
err(-1, "juggling_thread: pthread_mutex_unlock");
|
||||
|
||||
for (i = 0; i < NUMCYCLES; i++) {
|
||||
@ -334,21 +334,21 @@ thread_juggle(int fd1, int fd2, int pipeline)
|
||||
|
||||
threaded_pipeline = pipeline;
|
||||
|
||||
if (pthread_mutex_init(&threaded_mtx, NULL) < 0)
|
||||
if (pthread_mutex_init(&threaded_mtx, NULL) != 0)
|
||||
err(-1, "thread_juggle: pthread_mutex_init");
|
||||
|
||||
if (pthread_create(&thread, NULL, juggling_thread, &fd2) < 0)
|
||||
if (pthread_create(&thread, NULL, juggling_thread, &fd2) != 0)
|
||||
err(-1, "thread_juggle: pthread_create");
|
||||
|
||||
if (pthread_mutex_lock(&threaded_mtx) < 0)
|
||||
if (pthread_mutex_lock(&threaded_mtx) != 0)
|
||||
err(-1, "thread_juggle: pthread_mutex_lock");
|
||||
|
||||
while (!threaded_child_ready) {
|
||||
if (pthread_cond_wait(&threaded_cond, &threaded_mtx) < 0)
|
||||
if (pthread_cond_wait(&threaded_cond, &threaded_mtx) != 0)
|
||||
err(-1, "thread_juggle: pthread_cond_wait");
|
||||
}
|
||||
|
||||
if (pthread_mutex_unlock(&threaded_mtx) < 0)
|
||||
if (pthread_mutex_unlock(&threaded_mtx) != 0)
|
||||
err(-1, "thread_juggle: pthread_mutex_unlock");
|
||||
|
||||
if (clock_gettime(CLOCK_REALTIME, &tstart) < 0)
|
||||
@ -369,7 +369,7 @@ thread_juggle(int fd1, int fd2, int pipeline)
|
||||
if (clock_gettime(CLOCK_REALTIME, &tfinish) < 0)
|
||||
err(-1, "thread_juggle: clock_gettime");
|
||||
|
||||
if (pthread_join(thread, NULL) < 0)
|
||||
if (pthread_join(thread, NULL) != 0)
|
||||
err(-1, "thread_juggle: pthread_join");
|
||||
|
||||
timespecsub(&tfinish, &tstart);
|
||||
|
Loading…
Reference in New Issue
Block a user