This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit efa5688ef30c36fa87746f4aac3288eb72ec0af3
Author: Szymon Janc <szymon.j...@codecoup.pl>
AuthorDate: Wed Aug 6 11:47:35 2025 +0200

    porting/linux: Fix some coding style issues
    
    This code didn't follow coding style guidelines.
---
 porting/npl/linux/include/nimble/nimble_npl_os.h   |  8 ++--
 .../npl/linux/include/nimble/nimble_npl_os_log.h   | 20 ++++-----
 porting/npl/linux/include/nimble/os_types.h        | 45 ++++++++++----------
 porting/npl/linux/src/os_callout.c                 | 46 +++++++++++----------
 porting/npl/linux/src/os_task.c                    | 48 +++++++++++++---------
 porting/npl/linux/src/os_time.c                    |  2 +
 6 files changed, 91 insertions(+), 78 deletions(-)

diff --git a/porting/npl/linux/include/nimble/nimble_npl_os.h 
b/porting/npl/linux/include/nimble/nimble_npl_os.h
index 1db56794a..0006f8b40 100644
--- a/porting/npl/linux/include/nimble/nimble_npl_os.h
+++ b/porting/npl/linux/include/nimble/nimble_npl_os.h
@@ -31,15 +31,15 @@
 extern "C" {
 #endif
 
-#define BLE_NPL_OS_ALIGNMENT    (__WORDSIZE / 8)
+#define BLE_NPL_OS_ALIGNMENT (__WORDSIZE / 8)
 
-#define BLE_NPL_TIME_FOREVER    UINT32_MAX
+#define BLE_NPL_TIME_FOREVER UINT32_MAX
 
-struct ble_npl_eventq * ble_npl_eventq_dflt_get(void);
+struct ble_npl_eventq *ble_npl_eventq_dflt_get(void);
 void ble_npl_eventq_run(struct ble_npl_eventq *evq);
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif  /* _NPL_H_ */
+#endif /* _NPL_H_ */
diff --git a/porting/npl/linux/include/nimble/nimble_npl_os_log.h 
b/porting/npl/linux/include/nimble/nimble_npl_os_log.h
index 24315a21a..2e359f878 100644
--- a/porting/npl/linux/include/nimble/nimble_npl_os_log.h
+++ b/porting/npl/linux/include/nimble/nimble_npl_os_log.h
@@ -24,14 +24,14 @@
 #include <stdio.h>
 
 /* Example on how to use macro to generate module logging functions */
-#define BLE_NPL_LOG_IMPL(lvl) \
-        static inline void _BLE_NPL_LOG_CAT(BLE_NPL_LOG_MODULE, \
-                _BLE_NPL_LOG_CAT(_, lvl))(const char *fmt, ...)\
-        {                               \
-            va_list args;               \
-            va_start(args, fmt);        \
-            vprintf(fmt, args);          \
-            va_end(args);               \
-        }
+#define BLE_NPL_LOG_IMPL(lvl)                                                 \
+    static inline void _BLE_NPL_LOG_CAT(                                      \
+        BLE_NPL_LOG_MODULE, _BLE_NPL_LOG_CAT(_, lvl))(const char *fmt, ...)   \
+    {                                                                         \
+        va_list args;                                                         \
+        va_start(args, fmt);                                                  \
+        vprintf(fmt, args);                                                   \
+        va_end(args);                                                         \
+    }
 
-#endif  /* _NIMBLE_NPL_OS_LOG_H_ */
+#endif /* _NIMBLE_NPL_OS_LOG_H_ */
diff --git a/porting/npl/linux/include/nimble/os_types.h 
b/porting/npl/linux/include/nimble/os_types.h
index aa24745f5..fa92cd182 100644
--- a/porting/npl/linux/include/nimble/os_types.h
+++ b/porting/npl/linux/include/nimble/os_types.h
@@ -32,50 +32,49 @@
 typedef uint32_t ble_npl_time_t;
 typedef int32_t ble_npl_stime_t;
 
-//typedef int os_sr_t;
 typedef int ble_npl_stack_t;
 
-
 struct ble_npl_event {
-    uint8_t                 ev_queued;
-    ble_npl_event_fn       *ev_cb;
-    void                   *ev_arg;
+    uint8_t ev_queued;
+    ble_npl_event_fn *ev_cb;
+    void *ev_arg;
 };
 
 struct ble_npl_eventq {
-    void               *q;
+    void *q;
 };
 
 struct ble_npl_callout {
-    struct ble_npl_event    c_ev;
-    struct ble_npl_eventq  *c_evq;
-    uint32_t                c_ticks;
-    timer_t                 c_timer;
-    bool                    c_active;
+    struct ble_npl_event c_ev;
+    struct ble_npl_eventq *c_evq;
+    uint32_t c_ticks;
+    timer_t c_timer;
+    bool c_active;
 };
 
 struct ble_npl_mutex {
-    pthread_mutex_t         lock;
-    pthread_mutexattr_t     attr;
-    struct timespec         wait;
+    pthread_mutex_t lock;
+    pthread_mutexattr_t attr;
+    struct timespec wait;
 };
 
 struct ble_npl_sem {
-    sem_t                   lock;
+    sem_t lock;
 };
 
 struct ble_npl_task {
-    pthread_t               handle;
-    pthread_attr_t          attr;
-    struct sched_param      param;
-    const char*             name;
+    pthread_t handle;
+    pthread_attr_t attr;
+    struct sched_param param;
+    const char *name;
 };
 
 typedef void *(*ble_npl_task_func_t)(void *);
 
-int ble_npl_task_init(struct ble_npl_task *t, const char *name, 
ble_npl_task_func_t func,
-                void *arg, uint8_t prio, ble_npl_time_t sanity_itvl,
-                ble_npl_stack_t *stack_bottom, uint16_t stack_size);
+int ble_npl_task_init(struct ble_npl_task *t, const char *name,
+                      ble_npl_task_func_t func, void *arg, uint8_t prio,
+                      ble_npl_time_t sanity_itvl,
+                      ble_npl_stack_t *stack_bottom, uint16_t stack_size);
 
 int ble_npl_task_remove(struct ble_npl_task *t);
 
@@ -83,4 +82,4 @@ uint8_t ble_npl_task_count(void);
 
 void ble_npl_task_yield(void);
 
-#endif // _NPL_OS_TYPES_H
+#endif /* _NPL_OS_TYPES_H */
diff --git a/porting/npl/linux/src/os_callout.c 
b/porting/npl/linux/src/os_callout.c
index 76c8b2eef..90c190cef 100644
--- a/porting/npl/linux/src/os_callout.c
+++ b/porting/npl/linux/src/os_callout.c
@@ -31,7 +31,9 @@ static void
 ble_npl_callout_timer_cb(union sigval sv)
 {
     struct ble_npl_callout *c = (struct ble_npl_callout *)sv.sival_ptr;
+
     assert(c);
+
     c->c_active = false;
     if (c->c_evq) {
         ble_npl_eventq_put(c->c_evq, &c->c_ev);
@@ -40,12 +42,11 @@ ble_npl_callout_timer_cb(union sigval sv)
     }
 }
 
-void ble_npl_callout_init(struct ble_npl_callout *c, 
-                          struct ble_npl_eventq *evq,
-                          ble_npl_event_fn *ev_cb, 
-                          void *ev_arg)
+void
+ble_npl_callout_init(struct ble_npl_callout *c, struct ble_npl_eventq *evq,
+                     ble_npl_event_fn *ev_cb, void *ev_arg)
 {
-    struct sigevent         event;
+    struct sigevent event;
 
     /* Initialize the callout. */
     memset(c, 0, sizeof(*c));
@@ -55,29 +56,32 @@ void ble_npl_callout_init(struct ble_npl_callout *c,
     c->c_active = false;
 
     event.sigev_notify = SIGEV_THREAD;
-    event.sigev_value.sival_ptr = c;     // put callout obj in signal args
+    event.sigev_value.sival_ptr = c; // put callout obj in signal args
     event.sigev_notify_function = ble_npl_callout_timer_cb;
     event.sigev_notify_attributes = NULL;
 
     timer_create(CLOCK_REALTIME, &event, &c->c_timer);
 }
 
-bool ble_npl_callout_is_active(struct ble_npl_callout *c)
+bool
+ble_npl_callout_is_active(struct ble_npl_callout *c)
 {
-    // TODO: seek native posix method to determine whether timer_t is active.
-    // TODO: fix bug where one-shot timer is still active after fired.
+    /* TODO: seek native posix method to determine whether timer_t is active.
+     * TODO: fix bug where one-shot timer is still active after fired.
+     */
     return c->c_active;
 }
 
-int ble_npl_callout_inited(struct ble_npl_callout *c)
+int
+ble_npl_callout_inited(struct ble_npl_callout *c)
 {
     return (c->c_timer != NULL);
 }
 
-ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *c,
-                                     ble_npl_time_t ticks)
+ble_npl_error_t
+ble_npl_callout_reset(struct ble_npl_callout *c, ble_npl_time_t ticks)
 {
-    struct itimerspec       its;
+    struct itimerspec its;
 
     if (ticks < 0) {
         return BLE_NPL_EINVAL;
@@ -90,7 +94,7 @@ ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout 
*c,
     c->c_ticks = ble_npl_time_get() + ticks;
 
     its.it_interval.tv_sec = 0;
-    its.it_interval.tv_nsec = 0;                     // one shot
+    its.it_interval.tv_nsec = 0; // one shot
     its.it_value.tv_sec = (ticks / 1000);
     its.it_value.tv_nsec = (ticks % 1000) * 1000000; // expiration
     its.it_value.tv_nsec %= 1000000000;
@@ -100,16 +104,17 @@ ble_npl_error_t ble_npl_callout_reset(struct 
ble_npl_callout *c,
     return BLE_NPL_OK;
 }
 
-int ble_npl_callout_queued(struct ble_npl_callout *c)
+int
+ble_npl_callout_queued(struct ble_npl_callout *c)
 {
     struct itimerspec its;
     timer_gettime(c->c_timer, &its);
 
-    return ((its.it_value.tv_sec > 0) ||
-            (its.it_value.tv_nsec > 0));
+    return ((its.it_value.tv_sec > 0) || (its.it_value.tv_nsec > 0));
 }
 
-void ble_npl_callout_stop(struct ble_npl_callout *c)
+void
+ble_npl_callout_stop(struct ble_npl_callout *c)
 {
     if (!ble_npl_callout_inited(c)) {
         return;
@@ -137,13 +142,12 @@ ble_npl_callout_set_arg(struct ble_npl_callout *co, void 
*arg)
 }
 
 uint32_t
-ble_npl_callout_remaining_ticks(struct ble_npl_callout *co,
-                                ble_npl_time_t now)
+ble_npl_callout_remaining_ticks(struct ble_npl_callout *co, ble_npl_time_t now)
 {
     ble_npl_time_t rt;
     uint32_t exp;
-
     struct itimerspec its;
+
     timer_gettime(co->c_timer, &its);
 
     exp = its.it_value.tv_sec * 1000;
diff --git a/porting/npl/linux/src/os_task.c b/porting/npl/linux/src/os_task.c
index b03deb066..c34507f15 100644
--- a/porting/npl/linux/src/os_task.c
+++ b/porting/npl/linux/src/os_task.c
@@ -34,23 +34,22 @@ extern "C" {
  * and sets the task as ready to run, and inserts it into the operating
  * system scheduler.
  *
- * @param t The task to initialize
- * @param name The name of the task to initialize
- * @param func The task function to call
- * @param arg The argument to pass to this task function
- * @param prio The priority at which to run this task
- * @param sanity_itvl The time at which this task should check in with the
- *                    sanity task.  OS_WAIT_FOREVER means never check in
- *                    here.
- * @param stack_bottom A pointer to the bottom of a task's stack
- * @param stack_size The overall size of the task's stack.
+ * @param t             The task to initialize
+ * @param name          The name of the task to initialize
+ * @param func          The task function to call
+ * @param arg           The argument to pass to this task function
+ * @param prio          The priority at which to run this task
+ * @param sanity_itvl   The time at which this task should check in with the
+ *                      sanity task.  OS_WAIT_FOREVER means never check in 
here.
+ * @param stack_bottom  A pointer to the bottom of a task's stack
+ * @param stack_size    The overall size of the task's stack.
  *
  * @return 0 on success, non-zero on failure.
  */
 int
 ble_npl_task_init(struct ble_npl_task *t, const char *name, 
ble_npl_task_func_t func,
-        void *arg, uint8_t prio, ble_npl_time_t sanity_itvl,
-        ble_npl_stack_t *stack_bottom, uint16_t stack_size)
+                  void *arg, uint8_t prio, ble_npl_time_t sanity_itvl,
+                  ble_npl_stack_t *stack_bottom, uint16_t stack_size)
 {
     int err;
     if ((t == NULL) || (func == NULL)) {
@@ -58,14 +57,21 @@ ble_npl_task_init(struct ble_npl_task *t, const char *name, 
ble_npl_task_func_t
     }
 
     err = pthread_attr_init(&t->attr);
-    if (err) return err;
-    err = pthread_attr_getschedparam (&t->attr, &t->param);
-    if (err) return err;
+    if (err)
+        return err;
+
+    err = pthread_attr_getschedparam(&t->attr, &t->param);
+    if (err)
+        return err;
+
     err = pthread_attr_setschedpolicy(&t->attr, SCHED_RR);
-    if (err) return err;
+    if (err)
+        return err;
+
     t->param.sched_priority = prio;
-    err = pthread_attr_setschedparam (&t->attr, &t->param);
-    if (err) return err;
+    err = pthread_attr_setschedparam(&t->attr, &t->param);
+    if (err)
+        return err;
 
     t->name = name;
     err = pthread_create(&t->handle, &t->attr, func, arg);
@@ -101,12 +107,14 @@ ble_npl_get_current_task_id(void)
     return (void *)pthread_self();
 }
 
-bool ble_npl_os_started(void)
+bool
+ble_npl_os_started(void)
 {
     return true;
 }
 
-void ble_npl_task_yield(void)
+void
+ble_npl_task_yield(void)
 {
     sched_yield();
 }
diff --git a/porting/npl/linux/src/os_time.c b/porting/npl/linux/src/os_time.c
index 4625159f2..2af544e5f 100644
--- a/porting/npl/linux/src/os_time.c
+++ b/porting/npl/linux/src/os_time.c
@@ -33,9 +33,11 @@ ble_npl_time_t
 ble_npl_time_get(void)
 {
     struct timespec now;
+
     if (clock_gettime(CLOCK_MONOTONIC, &now)) {
         return 0;
     }
+
     return now.tv_sec * 1000.0 + now.tv_nsec / 1000000.0;
 }
 

Reply via email to