51
51
#include <assert.h>
52
52
#include <errno.h>
53
53
#include <poll.h>
54
+ #include <stdbool.h>
54
55
#include <string.h>
55
56
#include <sys/socket.h>
56
57
#include <unistd.h>
@@ -88,9 +89,9 @@ struct grpc_fd {
88
89
gpr_atm refst ;
89
90
90
91
gpr_mu mu ;
91
- int shutdown ;
92
- int closed ;
93
- int released ;
92
+ bool shutdown ;
93
+ bool closed ;
94
+ bool released ;
94
95
95
96
/* The watcher list.
96
97
@@ -186,8 +187,8 @@ typedef struct grpc_cached_wakeup_fd {
186
187
187
188
struct grpc_pollset_worker {
188
189
grpc_cached_wakeup_fd * wakeup_fd ;
189
- int reevaluate_polling_on_wakeup ;
190
- int kicked_specifically ;
190
+ bool reevaluate_polling_on_wakeup ;
191
+ bool kicked_specifically ;
191
192
struct grpc_pollset_worker * next ;
192
193
struct grpc_pollset_worker * prev ;
193
194
};
@@ -201,9 +202,9 @@ struct grpc_pollset {
201
202
gpr_mu mu ;
202
203
grpc_pollset_worker root_worker ;
203
204
int in_flight_cbs ;
204
- int shutting_down ;
205
- int called_shutdown ;
206
- int kicked_without_pollers ;
205
+ bool shutting_down ;
206
+ bool called_shutdown ;
207
+ bool kicked_without_pollers ;
207
208
grpc_closure * shutdown_done ;
208
209
grpc_closure_list idle_jobs ;
209
210
union {
@@ -332,7 +333,7 @@ static grpc_fd *alloc_fd(int fd) {
332
333
333
334
gpr_mu_lock (& r -> mu );
334
335
gpr_atm_rel_store (& r -> refst , 1 );
335
- r -> shutdown = 0 ;
336
+ r -> shutdown = false ;
336
337
r -> read_closure = CLOSURE_NOT_READY ;
337
338
r -> write_closure = CLOSURE_NOT_READY ;
338
339
r -> fd = fd ;
@@ -341,8 +342,8 @@ static grpc_fd *alloc_fd(int fd) {
341
342
r -> freelist_next = NULL ;
342
343
r -> read_watcher = r -> write_watcher = NULL ;
343
344
r -> on_done_closure = NULL ;
344
- r -> closed = 0 ;
345
- r -> released = 0 ;
345
+ r -> closed = false ;
346
+ r -> released = false ;
346
347
gpr_mu_unlock (& r -> mu );
347
348
return r ;
348
349
}
@@ -455,7 +456,7 @@ static int has_watchers(grpc_fd *fd) {
455
456
}
456
457
457
458
static void close_fd_locked (grpc_exec_ctx * exec_ctx , grpc_fd * fd ) {
458
- fd -> closed = 1 ;
459
+ fd -> closed = true ;
459
460
if (!fd -> released ) {
460
461
close (fd -> fd );
461
462
} else {
@@ -538,28 +539,28 @@ static void notify_on_locked(grpc_exec_ctx *exec_ctx, grpc_fd *fd,
538
539
}
539
540
}
540
541
541
- /* returns 1 if state becomes not ready */
542
- static int set_ready_locked (grpc_exec_ctx * exec_ctx , grpc_fd * fd ,
543
- grpc_closure * * st ) {
542
+ /* returns true if state becomes not ready */
543
+ static bool set_ready_locked (grpc_exec_ctx * exec_ctx , grpc_fd * fd ,
544
+ grpc_closure * * st ) {
544
545
if (* st == CLOSURE_READY ) {
545
546
/* duplicate ready ==> ignore */
546
- return 0 ;
547
+ return false ;
547
548
} else if (* st == CLOSURE_NOT_READY ) {
548
549
/* not ready, and not waiting ==> flag ready */
549
550
* st = CLOSURE_READY ;
550
- return 0 ;
551
+ return false ;
551
552
} else {
552
553
/* waiting ==> queue closure */
553
554
grpc_exec_ctx_push (exec_ctx , * st , fd_shutdown_error (fd -> shutdown ), NULL );
554
555
* st = CLOSURE_NOT_READY ;
555
- return 1 ;
556
+ return true ;
556
557
}
557
558
}
558
559
559
560
static void fd_shutdown (grpc_exec_ctx * exec_ctx , grpc_fd * fd ) {
560
561
gpr_mu_lock (& fd -> mu );
561
562
GPR_ASSERT (!fd -> shutdown );
562
- fd -> shutdown = 1 ;
563
+ fd -> shutdown = true ;
563
564
set_ready_locked (exec_ctx , fd , & fd -> read_closure );
564
565
set_ready_locked (exec_ctx , fd , & fd -> write_closure );
565
566
gpr_mu_unlock (& fd -> mu );
@@ -632,8 +633,8 @@ static uint32_t fd_begin_poll(grpc_fd *fd, grpc_pollset *pollset,
632
633
633
634
static void fd_end_poll (grpc_exec_ctx * exec_ctx , grpc_fd_watcher * watcher ,
634
635
int got_read , int got_write ) {
635
- int was_polling = 0 ;
636
- int kick = 0 ;
636
+ bool was_polling = false ;
637
+ bool kick = false ;
637
638
grpc_fd * fd = watcher -> fd ;
638
639
639
640
if (fd == NULL ) {
@@ -644,17 +645,17 @@ static void fd_end_poll(grpc_exec_ctx *exec_ctx, grpc_fd_watcher *watcher,
644
645
645
646
if (watcher == fd -> read_watcher ) {
646
647
/* remove read watcher, kick if we still need a read */
647
- was_polling = 1 ;
648
+ was_polling = true ;
648
649
if (!got_read ) {
649
- kick = 1 ;
650
+ kick = true ;
650
651
}
651
652
fd -> read_watcher = NULL ;
652
653
}
653
654
if (watcher == fd -> write_watcher ) {
654
655
/* remove write watcher, kick if we still need a write */
655
- was_polling = 1 ;
656
+ was_polling = true ;
656
657
if (!got_write ) {
657
- kick = 1 ;
658
+ kick = true ;
658
659
}
659
660
fd -> write_watcher = NULL ;
660
661
}
@@ -665,12 +666,12 @@ static void fd_end_poll(grpc_exec_ctx *exec_ctx, grpc_fd_watcher *watcher,
665
666
}
666
667
if (got_read ) {
667
668
if (set_ready_locked (exec_ctx , fd , & fd -> read_closure )) {
668
- kick = 1 ;
669
+ kick = true ;
669
670
}
670
671
}
671
672
if (got_write ) {
672
673
if (set_ready_locked (exec_ctx , fd , & fd -> write_closure )) {
673
- kick = 1 ;
674
+ kick = true ;
674
675
}
675
676
}
676
677
if (kick ) {
@@ -753,23 +754,23 @@ static grpc_error *pollset_kick_ext(grpc_pollset *p,
753
754
kick_append_error (
754
755
& error , grpc_wakeup_fd_wakeup (& specific_worker -> wakeup_fd -> fd ));
755
756
}
756
- p -> kicked_without_pollers = 1 ;
757
+ p -> kicked_without_pollers = true ;
757
758
GPR_TIMER_END ("pollset_kick_ext.broadcast" , 0 );
758
759
} else if (gpr_tls_get (& g_current_thread_worker ) !=
759
760
(intptr_t )specific_worker ) {
760
761
GPR_TIMER_MARK ("different_thread_worker" , 0 );
761
762
if ((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP ) != 0 ) {
762
- specific_worker -> reevaluate_polling_on_wakeup = 1 ;
763
+ specific_worker -> reevaluate_polling_on_wakeup = true ;
763
764
}
764
- specific_worker -> kicked_specifically = 1 ;
765
+ specific_worker -> kicked_specifically = true ;
765
766
kick_append_error (& error ,
766
767
grpc_wakeup_fd_wakeup (& specific_worker -> wakeup_fd -> fd ));
767
768
} else if ((flags & GRPC_POLLSET_CAN_KICK_SELF ) != 0 ) {
768
769
GPR_TIMER_MARK ("kick_yoself" , 0 );
769
770
if ((flags & GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP ) != 0 ) {
770
- specific_worker -> reevaluate_polling_on_wakeup = 1 ;
771
+ specific_worker -> reevaluate_polling_on_wakeup = true ;
771
772
}
772
- specific_worker -> kicked_specifically = 1 ;
773
+ specific_worker -> kicked_specifically = true ;
773
774
kick_append_error (& error ,
774
775
grpc_wakeup_fd_wakeup (& specific_worker -> wakeup_fd -> fd ));
775
776
}
@@ -797,7 +798,7 @@ static grpc_error *pollset_kick_ext(grpc_pollset *p,
797
798
}
798
799
} else {
799
800
GPR_TIMER_MARK ("kicked_no_pollers" , 0 );
800
- p -> kicked_without_pollers = 1 ;
801
+ p -> kicked_without_pollers = true ;
801
802
}
802
803
}
803
804
@@ -839,12 +840,11 @@ static void pollset_init(grpc_pollset *pollset, gpr_mu **mu) {
839
840
* mu = & pollset -> mu ;
840
841
pollset -> root_worker .next = pollset -> root_worker .prev = & pollset -> root_worker ;
841
842
pollset -> in_flight_cbs = 0 ;
842
- pollset -> shutting_down = 0 ;
843
- pollset -> called_shutdown = 0 ;
844
- pollset -> kicked_without_pollers = 0 ;
843
+ pollset -> shutting_down = false ;
844
+ pollset -> called_shutdown = false ;
845
+ pollset -> kicked_without_pollers = false ;
845
846
pollset -> idle_jobs .head = pollset -> idle_jobs .tail = NULL ;
846
847
pollset -> local_wakeup_cache = NULL ;
847
- pollset -> kicked_without_pollers = 0 ;
848
848
become_basic_pollset (pollset , NULL );
849
849
}
850
850
@@ -868,9 +868,9 @@ static void pollset_reset(grpc_pollset *pollset) {
868
868
GPR_ASSERT (!pollset_has_workers (pollset ));
869
869
GPR_ASSERT (pollset -> idle_jobs .head == pollset -> idle_jobs .tail );
870
870
pollset -> vtable -> destroy (pollset );
871
- pollset -> shutting_down = 0 ;
872
- pollset -> called_shutdown = 0 ;
873
- pollset -> kicked_without_pollers = 0 ;
871
+ pollset -> shutting_down = false ;
872
+ pollset -> called_shutdown = false ;
873
+ pollset -> kicked_without_pollers = false ;
874
874
become_basic_pollset (pollset , NULL );
875
875
}
876
876
@@ -909,7 +909,7 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
909
909
GPR_TIMER_BEGIN ("pollset_work" , 0 );
910
910
/* this must happen before we (potentially) drop pollset->mu */
911
911
worker .next = worker .prev = NULL ;
912
- worker .reevaluate_polling_on_wakeup = 0 ;
912
+ worker .reevaluate_polling_on_wakeup = false ;
913
913
if (pollset -> local_wakeup_cache != NULL ) {
914
914
worker .wakeup_fd = pollset -> local_wakeup_cache ;
915
915
pollset -> local_wakeup_cache = worker .wakeup_fd -> next ;
@@ -920,7 +920,7 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
920
920
return error ;
921
921
}
922
922
}
923
- worker .kicked_specifically = 0 ;
923
+ worker .kicked_specifically = false ;
924
924
/* If there's work waiting for the pollset to be idle, and the
925
925
pollset is idle, then do that work */
926
926
if (!pollset_has_workers (pollset ) &&
@@ -962,7 +962,7 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
962
962
gpr_tls_set (& g_current_thread_poller , 0 );
963
963
} else {
964
964
GPR_TIMER_MARK ("pollset_work.kicked_without_pollers" , 0 );
965
- pollset -> kicked_without_pollers = 0 ;
965
+ pollset -> kicked_without_pollers = false ;
966
966
}
967
967
/* Finished execution - start cleaning up.
968
968
Note that we may arrive here from outside the enclosing while() loop.
@@ -978,8 +978,8 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
978
978
GRPC_POLLSET_REEVALUATE_POLLING_ON_WAKEUP) then we land here and force
979
979
a loop */
980
980
if (worker .reevaluate_polling_on_wakeup && error == GRPC_ERROR_NONE ) {
981
- worker .reevaluate_polling_on_wakeup = 0 ;
982
- pollset -> kicked_without_pollers = 0 ;
981
+ worker .reevaluate_polling_on_wakeup = false ;
982
+ pollset -> kicked_without_pollers = false ;
983
983
if (queued_work || worker .kicked_specifically ) {
984
984
/* If there's queued work on the list, then set the deadline to be
985
985
immediate so we get back out of the polling loop quickly */
@@ -1000,7 +1000,7 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
1000
1000
if (pollset_has_workers (pollset )) {
1001
1001
pollset_kick (pollset , NULL );
1002
1002
} else if (!pollset -> called_shutdown && pollset -> in_flight_cbs == 0 ) {
1003
- pollset -> called_shutdown = 1 ;
1003
+ pollset -> called_shutdown = true ;
1004
1004
gpr_mu_unlock (& pollset -> mu );
1005
1005
finish_shutdown (exec_ctx , pollset );
1006
1006
grpc_exec_ctx_flush (exec_ctx );
@@ -1024,15 +1024,15 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
1024
1024
static void pollset_shutdown (grpc_exec_ctx * exec_ctx , grpc_pollset * pollset ,
1025
1025
grpc_closure * closure ) {
1026
1026
GPR_ASSERT (!pollset -> shutting_down );
1027
- pollset -> shutting_down = 1 ;
1027
+ pollset -> shutting_down = true ;
1028
1028
pollset -> shutdown_done = closure ;
1029
1029
pollset_kick (pollset , GRPC_POLLSET_KICK_BROADCAST );
1030
1030
if (!pollset_has_workers (pollset )) {
1031
1031
grpc_exec_ctx_enqueue_list (exec_ctx , & pollset -> idle_jobs , NULL );
1032
1032
}
1033
1033
if (!pollset -> called_shutdown && pollset -> in_flight_cbs == 0 &&
1034
1034
!pollset_has_workers (pollset )) {
1035
- pollset -> called_shutdown = 1 ;
1035
+ pollset -> called_shutdown = true ;
1036
1036
finish_shutdown (exec_ctx , pollset );
1037
1037
}
1038
1038
}
@@ -1096,7 +1096,7 @@ static void basic_do_promote(grpc_exec_ctx *exec_ctx, void *args,
1096
1096
if (pollset -> shutting_down ) {
1097
1097
/* We don't care about this pollset anymore. */
1098
1098
if (pollset -> in_flight_cbs == 0 && !pollset -> called_shutdown ) {
1099
- pollset -> called_shutdown = 1 ;
1099
+ pollset -> called_shutdown = true ;
1100
1100
finish_shutdown (exec_ctx , pollset );
1101
1101
}
1102
1102
} else if (fd_is_orphaned (fd )) {
@@ -1622,7 +1622,7 @@ static void perform_delayed_add(grpc_exec_ctx *exec_ctx, void *arg,
1622
1622
if (da -> pollset -> shutting_down ) {
1623
1623
/* We don't care about this pollset anymore. */
1624
1624
if (da -> pollset -> in_flight_cbs == 0 && !da -> pollset -> called_shutdown ) {
1625
- da -> pollset -> called_shutdown = 1 ;
1625
+ da -> pollset -> called_shutdown = true ;
1626
1626
grpc_exec_ctx_push (exec_ctx , da -> pollset -> shutdown_done , GRPC_ERROR_NONE ,
1627
1627
NULL );
1628
1628
}
0 commit comments