Skip to content

Commit

Permalink
fixup: bug in FileDescriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneo committed Dec 17, 2024
1 parent 76b432f commit 01f96b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/core/lib/event_engine/posix_engine/file_descriptors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ class ThreadLocalCounter {
}

void FdLocked(const FileDescriptors* descriptors) {
if (descriptors != nullptr && !IsThreadAlive()) {
if (descriptors != nullptr && IsThreadAlive()) {
++thread_locks_count_[descriptors];
}
}

void FdUnlocked(const FileDescriptors* descriptors) {
if (descriptors != nullptr && !IsThreadAlive()) {
if (descriptors != nullptr && IsThreadAlive()) {
--thread_locks_count_[descriptors];
CHECK_GE(thread_locks_count_[descriptors], 0);
}
Expand Down Expand Up @@ -78,7 +78,7 @@ class ThreadLocalCounter {

static int GetTid() { return gettid(); }
#elif
static bool IsThreadAlive() { return true; }
static bool IsThreadAlive() { return false; }
static int GetTid() { return -1; }
#endif // GPR_HAS_PTHREAD_H

Expand Down
4 changes: 4 additions & 0 deletions test/core/event_engine/posix/file_descriptors_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <vector>

#include "absl/cleanup/cleanup.h"
#include "absl/log/log.h"

namespace grpc_event_engine {
namespace experimental {
Expand Down Expand Up @@ -68,8 +69,11 @@ TEST(FileDescriptorsTest, DetectsIfThreadHasIOLock) {
FileDescriptors fds;
FileDescriptor fd = fds.Add(1);
auto locked = fds.Lock(fd);
LOG(INFO) << "before";
absl::Status status = fds.Stop();
LOG(INFO) << 5;
EXPECT_EQ(status.code(), absl::StatusCode::kFailedPrecondition) << status;
LOG(INFO) << 6;
}

} // namespace experimental
Expand Down

0 comments on commit 01f96b1

Please sign in to comment.