Skip to content

Encapsulate util.cpp's own runtime state as static, not global - #5783

Merged
netmindz merged 1 commit into
wled:mainfrom
netmindz:refactor/utilcpp-globals
Aug 8, 2026
Merged

Encapsulate util.cpp's own runtime state as static, not global#5783
netmindz merged 1 commit into
wled:mainfrom
netmindz:refactor/utilcpp-globals

Conversation

@netmindz

@netmindz netmindz commented Aug 8, 2026

Copy link
Copy Markdown
Member

Summary

Part of an ongoing pass identifying WLED_GLOBAL declarations that are actually only referenced in one file (see #5777-#5782 for earlier ones). 2 more turned out to be private to util.cpp: jsonBufferLock, jsonBufferLockMutex.

Converted both to file-local static, preserving the #if defined(ARDUINO_ARCH_ESP32) guard around jsonBufferLockMutex (it's a FreeRTOS semaphore, ESP32-only).

No behavior change — purely a storage-class change.

Test plan

  • esp32dev: builds and links cleanly via pio run -e esp32dev — 1,320,319 bytes flash, no warnings.
  • Confirmed via repo-wide grep (wled00/, usermods/) that neither converted variable is referenced outside util.cpp.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Improved internal handling of JSON buffer locking on ESP32.
    • No user-facing behavior or functionality was changed.

2 WLED_GLOBAL variables were referenced only in util.cpp:
jsonBufferLock, jsonBufferLockMutex. Converted both to file-local
`static`, preserving the #if defined(ARDUINO_ARCH_ESP32) guard around
jsonBufferLockMutex.

No behavior change - purely a storage-class change.

Verified: esp32dev builds and links cleanly via `pio run -e esp32dev`
(1,320,319 bytes flash, no warnings from either changed file).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3927e22e-a09f-4e17-94b0-6fe3b23acf69

📥 Commits

Reviewing files that changed from the base of the PR and between 0869ef4 and c9ce5c6.

📒 Files selected for processing (2)
  • wled00/util.cpp
  • wled00/wled.h

Walkthrough

The change moves JSON buffer synchronization state into file-private storage in util.cpp. It removes the related global declarations from wled.h and preserves the existing JSON document declarations.

Changes

JSON buffer state encapsulation

Layer / File(s) Summary
Encapsulate JSON buffer lock state
wled00/util.cpp, wled00/wled.h
util.cpp adds file-private mutex and lock-owner state. wled.h removes their global declarations and retains the PSRAM-dependent pDoc and gDoc declarations.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

  • wled/WLED#5217: Both changes modify JSON buffer locking state and identifiers.
  • wled/WLED#5777: Both changes move file-specific synchronization state out of wled.h.
  • wled/WLED#5780: Both changes make JSON lock state file-local instead of globally declared.

Suggested labels: enhancement

Suggested reviewers: softhack007, dedehai

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: making util.cpp runtime state file-local static instead of global.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@netmindz
netmindz merged commit 7ce236c into wled:main Aug 8, 2026
30 checks passed
@netmindz
netmindz deleted the refactor/utilcpp-globals branch August 8, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants