Skip to content

Commit f19e72f

Browse files
jackhumphriesdohyunkim-dev
authored andcommitted
ghOSt: Improve style of << overrides
PiperOrigin-RevId: 478907733
1 parent 4d9270e commit f19e72f

File tree

11 files changed

+20
-64
lines changed

11 files changed

+20
-64
lines changed

experiments/shared/thread_wait.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,10 @@ inline std::ostream& operator<<(std::ostream& os,
6262
ThreadWait::WaitType wait_type) {
6363
switch (wait_type) {
6464
case ThreadWait::WaitType::kSpin:
65-
os << "Spin";
66-
break;
65+
return os << "Spin";
6766
case ThreadWait::WaitType::kFutex:
68-
os << "Futex";
69-
break;
70-
// We will get a compile error if a new member is added to the
71-
// 'ThreadWait::WaitType' enum and a corresponding case is not added here.
67+
return os << "Futex";
7268
}
73-
return os;
7469
}
7570

7671
} // namespace ghost_test

lib/base.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ class Gtid {
187187
bool operator!() const { return id() == 0; }
188188

189189
friend std::ostream& operator<<(std::ostream& os, const Gtid& gtid) {
190-
os << gtid.id();
191-
return os;
190+
return os << gtid.id();
192191
}
193192

194193
// These are just some simple debug helpers to make things more readable.
@@ -342,20 +341,12 @@ class Notification {
342341
Notification::NotifiedState notified_state) {
343342
switch (notified_state) {
344343
case Notification::NotifiedState::kNoWaiter:
345-
os << "No Waiter";
346-
break;
344+
return os << "No Waiter";
347345
case Notification::NotifiedState::kWaiter:
348-
os << "Waiter";
349-
break;
346+
return os << "Waiter";
350347
case Notification::NotifiedState::kNotified:
351-
os << "Notified";
352-
break;
353-
default:
354-
GHOST_ERROR("`notified_state` has non-enumerator value %d.",
355-
static_cast<int>(notified_state));
356-
break;
348+
return os << "Notified";
357349
}
358-
return os;
359350
}
360351

361352
// The notification state.

lib/channel.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ class Message {
6464
}
6565

6666
friend std::ostream& operator<<(std::ostream& os, const Message& msg) {
67-
os << msg.stringify();
68-
return os;
67+
return os << msg.stringify();
6968
}
7069

7170
private:

lib/ghost.h

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -522,21 +522,14 @@ class GhostThread {
522522
GhostThread& operator=(const GhostThread&) = delete;
523523
~GhostThread();
524524

525-
friend std::ostream& operator<<(
526-
std::ostream& os, const GhostThread::KernelScheduler& kernel_scheduler) {
527-
switch (kernel_scheduler) {
525+
friend std::ostream& operator<<(std::ostream& os,
526+
GhostThread::KernelScheduler scheduler) {
527+
switch (scheduler) {
528528
case GhostThread::KernelScheduler::kCfs:
529-
os << "CFS";
530-
break;
529+
return os << "CFS";
531530
case GhostThread::KernelScheduler::kGhost:
532-
os << "ghOSt";
533-
break;
534-
default:
535-
GHOST_ERROR("`kernel_scheduler` has non-enumerator value %d.",
536-
static_cast<int>(kernel_scheduler));
537-
break;
531+
return os << "ghOSt";
538532
}
539-
return os;
540533
}
541534

542535
// Joins the thread.

lib/topology.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,7 @@ class CpuList : public CpuMap {
442442

443443
// Dumps the bitmap in hexadecimal, highest cpus to the left
444444
friend std::ostream& operator<<(std::ostream& os, const CpuList& clist) {
445-
os << clist.CpuMaskStr();
446-
return os;
445+
return os << clist.CpuMaskStr();
447446
}
448447

449448
private:

schedulers/cfs/cfs_scheduler.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,6 @@ std::ostream& operator<<(std::ostream& os, const CfsTaskState& state) {
894894
return os << "kRunnable";
895895
case CfsTaskState::kNumStates:
896896
return os << "SENTINEL";
897-
break;
898-
// No default (exhaustive switch)
899897
}
900898
}
901899

schedulers/edf/edf_scheduler.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ struct EdfTask : public Task<> {
6565

6666
friend inline std::ostream& operator<<(std::ostream& os,
6767
EdfTask::RunState run_state) {
68-
os << RunStateToString(run_state);
69-
return os;
68+
return os << RunStateToString(run_state);
7069
}
7170

7271
RunState run_state = RunState::kBlocked;

schedulers/fifo/centralized/fifo_scheduler.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,12 @@ struct FifoTask : public Task<> {
4848
return "OnCpu";
4949
case FifoTask::RunState::kYielding:
5050
return "Yielding";
51-
// We will get a compile error if a new member is added to the
52-
// `FifoTask::RunState` enum and a corresponding case is not added
53-
// here.
5451
}
55-
CHECK(false);
56-
return "Unknown run state";
5752
}
5853

5954
friend std::ostream& operator<<(std::ostream& os,
6055
FifoTask::RunState run_state) {
61-
os << RunStateToString(run_state);
62-
return os;
56+
return os << RunStateToString(run_state);
6357
}
6458

6559
RunState run_state = RunState::kBlocked;

schedulers/fifo/per_cpu/fifo_scheduler.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,7 @@ std::ostream& operator<<(std::ostream& os, const FifoTaskState& state) {
421421
return os << "kQueued";
422422
case FifoTaskState::kOnCpu:
423423
return os << "kOnCpu";
424-
// No default (exhaustive switch)
425424
}
426-
427-
return os << static_cast<int>(state); // 'state' has a non-enumerator value.
428425
}
429426

430427
} // namespace ghost

schedulers/shinjuku/shinjuku_scheduler.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,19 @@ struct ShinjukuTask : public Task<> {
8383

8484
friend std::ostream& operator<<(std::ostream& os,
8585
ShinjukuTask::RunState run_state) {
86-
os << RunStateToString(run_state);
87-
return os;
86+
return os << RunStateToString(run_state);
8887
}
8988

9089
friend std::ostream& operator<<(
9190
std::ostream& os, ShinjukuTask::UnscheduleLevel unschedule_level) {
9291
switch (unschedule_level) {
9392
case ShinjukuTask::UnscheduleLevel::kNoUnschedule:
94-
os << "No Unschedule";
95-
break;
93+
return os << "No Unschedule";
9694
case ShinjukuTask::UnscheduleLevel::kCouldUnschedule:
97-
os << "Could Unschedule";
98-
break;
95+
return os << "Could Unschedule";
9996
case ShinjukuTask::UnscheduleLevel::kMustUnschedule:
100-
os << "Must Unschedule";
101-
break;
102-
// We will get a compile error if a new member is added to the
103-
// `ShinjukuTask::UnscheduleLevel` enum and a corresponding case is not
104-
// added here.
97+
return os << "Must Unschedule";
10598
}
106-
return os;
10799
}
108100

109101
RunState run_state = RunState::kBlocked;

0 commit comments

Comments
 (0)