Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clang-format and run it on the code-base #384

Merged
merged 6 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
BasedOnStyle: LLVM
Language: Cpp
IndentWidth: 2
BreakConstructorInitializersBeforeComma: 'true'
PointerAlignment: Left
IncludeBlocks: Preserve
SortIncludes: false
ColumnLimit: 120
16 changes: 16 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: clang-format-review

# You can be more specific, but it currently only works on pull requests
on: [pull_request]

jobs:
clang-format:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Install clang-tidy
run: |
sudo apt-get update
sudo apt-get install -y clang-tidy
- name: Analyze
run: make format-check
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file lets you format the code-base with a single command.
FILES := $(shell find . -name '*.c' -o -name '*.h')
.PHONY: format
format:
clang-format -i -style=file $(FILES)

.PHONY: format-check
format-check:
clang-format --dry-run --Werror -style=file $(FILES)
74 changes: 37 additions & 37 deletions core/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @copyright (c) 2020-2024, The University of California at Berkeley.
* License: <a href="https://github.com/lf-lang/reactor-c/blob/main/LICENSE.md">BSD 2-clause</a>
* @brief Implementations of functions in clock.h.
*/
*/
#include "clock.h"
#include "low_level_platform.h"

Expand All @@ -14,47 +14,47 @@

static instant_t last_read_physical_time = NEVER;

int lf_clock_gettime(instant_t *now) {
instant_t last_read_local;
int res = _lf_clock_gettime(now);
if (res != 0) {
return -1;
int lf_clock_gettime(instant_t* now) {
instant_t last_read_local;
int res = _lf_clock_gettime(now);
if (res != 0) {
return -1;
}
#if defined(_LF_CLOCK_SYNC_ON)
clock_sync_apply_offset(now);
#endif
do {
// Atomically fetch the last read value. This is done with
// atomics to guarantee that it works on 32bit platforms as well.
last_read_local = lf_atomic_fetch_add64(&last_read_physical_time, 0);

// Ensure monotonicity.
if (*now < last_read_local) {
*now = last_read_local + 1;
}
#if defined (_LF_CLOCK_SYNC_ON)
clock_sync_apply_offset(now);
#endif
do {
// Atomically fetch the last read value. This is done with
// atomics to guarantee that it works on 32bit platforms as well.
last_read_local = lf_atomic_fetch_add64(&last_read_physical_time, 0);

// Ensure monotonicity.
if (*now < last_read_local) {
*now = last_read_local+1;
}

// Update the last read value, atomically and also make sure that another
// thread has not been here in between and changed it. If so. We must redo
// the monotonicity calculation.
} while(!lf_atomic_bool_compare_and_swap64(&last_read_physical_time, last_read_local, *now));

return 0;

// Update the last read value, atomically and also make sure that another
// thread has not been here in between and changed it. If so. We must redo
// the monotonicity calculation.
} while (!lf_atomic_bool_compare_and_swap64(&last_read_physical_time, last_read_local, *now));

return 0;
}

int lf_clock_interruptable_sleep_until_locked(environment_t *env, instant_t wakeup_time) {
#if defined (_LF_CLOCK_SYNC_ON)
// Remove any clock sync offset and call the Platform API.
clock_sync_remove_offset(&wakeup_time);
#endif
return _lf_interruptable_sleep_until_locked(env, wakeup_time);
int lf_clock_interruptable_sleep_until_locked(environment_t* env, instant_t wakeup_time) {
#if defined(_LF_CLOCK_SYNC_ON)
// Remove any clock sync offset and call the Platform API.
clock_sync_remove_offset(&wakeup_time);
#endif
return _lf_interruptable_sleep_until_locked(env, wakeup_time);
}

#if !defined(LF_SINGLE_THREADED)
int lf_clock_cond_timedwait(lf_cond_t *cond, instant_t wakeup_time) {
#if defined (_LF_CLOCK_SYNC_ON)
// Remove any clock sync offset and call the Platform API.
clock_sync_remove_offset(&wakeup_time);
#endif
return _lf_cond_timedwait(cond, wakeup_time);
int lf_clock_cond_timedwait(lf_cond_t* cond, instant_t wakeup_time) {
#if defined(_LF_CLOCK_SYNC_ON)
// Remove any clock sync offset and call the Platform API.
clock_sync_remove_offset(&wakeup_time);
#endif
return _lf_cond_timedwait(cond, wakeup_time);
}
#endif
Loading
Loading