Re: Scope of variables flagged by code inspector

2021-10-11 Thread Chris Johns
On 11/10/21 10:14 pm, Sebastian Huber wrote:
> Hello Zack,
> 
> On 10/10/2021 20:25, zack leung wrote:
>> I recently was invited to look at a new code review tool by Joel. It's used
>> to help with reducing technical debt. It suggests various fixes and
>> highlights various possible errors. One of them relates to the fact that
>> some of the variable scopes and be reduced. For example, we can define
>> variables when they are needed not at the beginning of functions. I don't
>> know if it matters much. Maybe it helps with memory due to the timing of
>> things allocated on the stack.  This also helps with the compiler not
>> needing to analyze long lifespans. This also prevents the variable to be
>> flagged as uninitialized.
> 
> I guess modern compiler don't care about when you define a variable. It is
> probably more an issue for the human reader.
> 
>> But personally, I feel it's easier to read if we don't change where
>> variables are defined. An example of this is found in
>> testsuites/mptests/mp09/task1.c. An array called recieve_Buffer could be
>> defined later. I'm not sure if this matters much. I want to know your
>> input.
> 
> Moving the variable to the most local scope is already covered by the current
> coding style (I hope). Maybe this needs to be clarified in the coding style.
> 
> From my point of view we should go one step further and allow the declaration
> and preferably also the initialization of local variables as close to their
> first use as possible in contrast to only the scope begin.

I am OK with this if we have a suitable means to detect and handle shadowed
variables.

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH] score: Simplify _Watchdog_Next_first()

2021-10-11 Thread Gedare Bloom
ok

On Mon, Oct 11, 2021 at 5:24 AM Sebastian Huber
 wrote:
>
> ---
>  cpukit/include/rtems/score/watchdogimpl.h | 55 +++
>  1 file changed, 36 insertions(+), 19 deletions(-)
>
> diff --git a/cpukit/include/rtems/score/watchdogimpl.h 
> b/cpukit/include/rtems/score/watchdogimpl.h
> index 7b364b8828..ba1a884a3d 100644
> --- a/cpukit/include/rtems/score/watchdogimpl.h
> +++ b/cpukit/include/rtems/score/watchdogimpl.h
> @@ -351,33 +351,50 @@ RTEMS_INLINE_ROUTINE bool _Watchdog_Is_scheduled(
>  }
>
>  /**
> - * @brief Sets the first node of the header.
> + * @brief Sets the first watchdog of the watchdog collection to the next
> + * watchdog of the current first watchdog.
>   *
> - * Sets the first node of the header to either the leftmost child node of the
> - *  watchdog control node, or if not present sets it to the right child node 
> of
> - * the watchdog control node. if both are not present, the new first node is
> - * the parent node of the current first node.
> + * This function may be used during watchdog removals, see _Watchdog_Remove()
> + * and _Watchdog_Tickle().
>   *
> - * @param[in, out] header The watchdog header.
> - * @param the_watchdog The watchdog control node for the operation.
> + * @param[in, out] header is the watchdog collection header.
> + *
> + * @param first is the current first watchdog which should be removed
> + *   afterwards.
>   */
>  RTEMS_INLINE_ROUTINE void _Watchdog_Next_first(
> -  Watchdog_Header  *header,
> -  Watchdog_Control *the_watchdog
> +  Watchdog_Header*header,
> +  const Watchdog_Control *first
>  )
>  {
> -  RBTree_Node *node = _RBTree_Right( _watchdog->Node.RBTree );
> -
> -  if ( node != NULL ) {
> -RBTree_Node *left;
> -
> -while ( ( left = _RBTree_Left( node ) ) != NULL ) {
> -  node = left;
> -}
> +  RBTree_Node *right;
>
> -header->first = node;
> +  /*
> +   * This function uses the following properties of red-black trees:
> +   *
> +   * 1. Every leaf (NULL) is black.
> +   *
> +   * 2. If a node is red, then both its children are black.
> +   *
> +   * 3. Every simple path from a node to a descendant leaf contains the same
> +   *number of black nodes.
> +   *
> +   * The first node has no left child.  So every path from the first node has
> +   * exactly one black node (including leafs).  The first node cannot have a
> +   * non-leaf black right child.  It may have a red right child.  In this 
> case
> +   * both children must be leafs.
> +   */
> +  _Assert( header->first == >Node.RBTree );
> +  _Assert( _RBTree_Left( >Node.RBTree ) == NULL );
> +  right = _RBTree_Right( >Node.RBTree );
> +
> +  if ( right != NULL ) {
> +_Assert( RB_COLOR( right, Node ) == RB_RED );
> +_Assert( _RBTree_Left( right ) == NULL );
> +_Assert( _RBTree_Right( right ) == NULL );
> +header->first = right;
>} else {
> -header->first = _RBTree_Parent( _watchdog->Node.RBTree );
> +header->first = _RBTree_Parent( >Node.RBTree );
>}
>  }
>
> --
> 2.31.1
>
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH] rtems: Add new clock manager directives

2021-10-11 Thread Sebastian Huber
Update #4527.
---
 cpukit/include/rtems/rtems/clock.h | 590 +
 cpukit/score/src/kern_tc.c |  56 +++
 2 files changed, 646 insertions(+)

diff --git a/cpukit/include/rtems/rtems/clock.h 
b/cpukit/include/rtems/rtems/clock.h
index 8511cb9cef..16b838a842 100644
--- a/cpukit/include/rtems/rtems/clock.h
+++ b/cpukit/include/rtems/rtems/clock.h
@@ -81,6 +81,11 @@ extern "C" {
  *   related capabilities.
  */
 
+/* Generated from spec:/rtems/clock/if/bintime */
+
+/* Forward declaration */
+struct bintime;
+
 /* Generated from spec:/rtems/clock/if/set */
 
 /**
@@ -217,6 +222,591 @@ rtems_status_code rtems_clock_get_tod( rtems_time_of_day 
*time_of_day );
  */
 rtems_status_code rtems_clock_get_tod_timeval( struct timeval *time_of_day );
 
+/* Generated from spec:/rtems/clock/if/get-realtime */
+
+/**
+ * @ingroup RTEMSAPIClassicClock
+ *
+ * @brief Gets the time elapsed since the Unix epoch measured using
+ *   CLOCK_REALTIME in seconds and nanoseconds format.
+ *
+ * @param[out] time_snapshot is the pointer to a struct timespec object.  The
+ *   time elapsed since the Unix epoch measured using the CLOCK_REALTIME at
+ *   some time point during the directive call will be stored in this object.
+ *   Calling the directive with a pointer equal to NULL is undefined behaviour.
+ *
+ * @par Notes
+ * @parblock
+ * The directive accesses a device provided by the Clock Driver to get the time
+ * in the highest precision available to the system.  Alternatively, the
+ * rtems_clock_get_realtime_coarse() directive may be used to get the time with
+ * less presision and less runtime overhead.
+ *
+ * See rtems_clock_get_realtime_bintime() and
+ * rtems_clock_get_realtime_timeval() to get the time in alternative formats.
+ * @endparblock
+ *
+ * @par Constraints
+ * @parblock
+ * The following constraints apply to this directive:
+ *
+ * * The directive may be called from within any runtime context.
+ *
+ * * The directive will not cause the calling task to be preempted.
+ *
+ * * The directive requires a Clock Driver.
+ * @endparblock
+ */
+void rtems_clock_get_realtime( struct timespec *time_snapshot );
+
+/* Generated from spec:/rtems/clock/if/get-realtime-bintime */
+
+/**
+ * @ingroup RTEMSAPIClassicClock
+ *
+ * @brief Gets the time elapsed since the Unix epoch measured using
+ *   CLOCK_REALTIME in binary time format.
+ *
+ * @param[out] time_snapshot is the pointer to a bintime object.  The time
+ *   elapsed since the Unix epoch measured using the CLOCK_REALTIME at some
+ *   time point during the directive call will be stored in this object.
+ *   Calling the directive with a pointer equal to NULL is undefined behaviour.
+ *
+ * @par Notes
+ * @parblock
+ * The directive accesses a device provided by the Clock Driver to get the time
+ * in the highest precision available to the system.  Alternatively, the
+ * rtems_clock_get_realtime_coarse_bintime() directive may be used to get the
+ * time with less presision and less runtime overhead.
+ *
+ * See rtems_clock_get_realtime() and rtems_clock_get_realtime_timeval() to get
+ * the time in alternative formats.
+ * @endparblock
+ *
+ * @par Constraints
+ * @parblock
+ * The following constraints apply to this directive:
+ *
+ * * The directive may be called from within any runtime context.
+ *
+ * * The directive will not cause the calling task to be preempted.
+ *
+ * * The directive requires a Clock Driver.
+ * @endparblock
+ */
+void rtems_clock_get_realtime_bintime( struct bintime *time_snapshot );
+
+/* Generated from spec:/rtems/clock/if/get-realtime-timeval */
+
+/**
+ * @ingroup RTEMSAPIClassicClock
+ *
+ * @brief Gets the time elapsed since the Unix epoch measured using
+ *   CLOCK_REALTIME in seconds and microseconds format.
+ *
+ * @param[out] time_snapshot is the pointer to a struct timeval object.  The
+ *   time elapsed since the Unix epoch measured using the CLOCK_REALTIME at
+ *   some time point during the directive call will be stored in this object.
+ *   Calling the directive with a pointer equal to NULL is undefined behaviour.
+ *
+ * @par Notes
+ * @parblock
+ * The directive accesses a device provided by the Clock Driver to get the time
+ * in the highest precision available to the system.  Alternatively, the
+ * rtems_clock_get_realtime_coarse_timeval() directive may be used to get the
+ * time with less presision and less runtime overhead.
+ *
+ * See rtems_clock_get_realtime() and rtems_clock_get_realtime_bintime() to get
+ * the time in alternative formats.
+ * @endparblock
+ *
+ * @par Constraints
+ * @parblock
+ * The following constraints apply to this directive:
+ *
+ * * The directive may be called from within any runtime context.
+ *
+ * * The directive will not cause the calling task to be preempted.
+ *
+ * * The directive requires a Clock Driver.
+ * @endparblock
+ */
+void rtems_clock_get_realtime_timeval( struct timeval *time_snapshot );
+
+/* Generated from 

[PATCH] c-user: Document new clock manager directives

2021-10-11 Thread Sebastian Huber
Add new clock manager directives to get all times provided by the
timehands.

Update #4527.
---

For an updated document to review see:

https://ftp.rtems.org/pub/rtems/people/sebh/c-user.pdf

 c-user/clock/directives.rst   | 830 ++
 c-user/clock/introduction.rst |  80 
 2 files changed, 910 insertions(+)

diff --git a/c-user/clock/directives.rst b/c-user/clock/directives.rst
index bdb7680..e9db48c 100644
--- a/c-user/clock/directives.rst
+++ b/c-user/clock/directives.rst
@@ -224,6 +224,836 @@ The following constraints apply to this directive:
   Applications which are restricted to only use interfaces of the pre-qualified
   feature set of RTEMS shall not use the directive.
 
+.. Generated from spec:/rtems/clock/if/get-realtime
+
+.. raw:: latex
+
+\clearpage
+
+.. index:: rtems_clock_get_realtime()
+
+.. _InterfaceRtemsClockGetRealtime:
+
+rtems_clock_get_realtime()
+--
+
+Gets the time elapsed since the :term:`Unix epoch` measured using
+:term:`CLOCK_REALTIME` in seconds and nanoseconds format.
+
+.. rubric:: CALLING SEQUENCE:
+
+.. code-block:: c
+
+void rtems_clock_get_realtime( struct timespec *time_snapshot );
+
+.. rubric:: PARAMETERS:
+
+``time_snapshot``
+This parameter is the pointer to a `struct timespec
+`_ object.  The time
+elapsed since the :term:`Unix epoch` measured using the
+:term:`CLOCK_REALTIME` at some time point during the directive call will be
+stored in this object.  Calling the directive with a pointer equal to `NULL
+`_ is undefined behaviour.
+
+.. rubric:: NOTES:
+
+The directive accesses a device provided by the :term:`Clock Driver` to get the
+time in the highest precision available to the system.  Alternatively, the
+:ref:`InterfaceRtemsClockGetRealtimeCoarse` directive may be used to get the
+time with less presision and less runtime overhead.
+
+See :ref:`InterfaceRtemsClockGetRealtimeBintime` and
+:ref:`InterfaceRtemsClockGetRealtimeTimeval` to get the time in alternative
+formats.
+
+.. rubric:: CONSTRAINTS:
+
+The following constraints apply to this directive:
+
+* The directive may be called from within any runtime context.
+
+* The directive will not cause the calling task to be preempted.
+
+* The directive requires a :term:`Clock Driver`.
+
+.. Generated from spec:/rtems/clock/if/get-realtime-bintime
+
+.. raw:: latex
+
+\clearpage
+
+.. index:: rtems_clock_get_realtime_bintime()
+
+.. _InterfaceRtemsClockGetRealtimeBintime:
+
+rtems_clock_get_realtime_bintime()
+--
+
+Gets the time elapsed since the :term:`Unix epoch` measured using
+:term:`CLOCK_REALTIME` in binary time format.
+
+.. rubric:: CALLING SEQUENCE:
+
+.. code-block:: c
+
+void rtems_clock_get_realtime_bintime( struct bintime *time_snapshot );
+
+.. rubric:: PARAMETERS:
+
+``time_snapshot``
+This parameter is the pointer to a :c:type:`bintime` object.  The time
+elapsed since the :term:`Unix epoch` measured using the
+:term:`CLOCK_REALTIME` at some time point during the directive call will be
+stored in this object.  Calling the directive with a pointer equal to `NULL
+`_ is undefined behaviour.
+
+.. rubric:: NOTES:
+
+The directive accesses a device provided by the :term:`Clock Driver` to get the
+time in the highest precision available to the system.  Alternatively, the
+:ref:`InterfaceRtemsClockGetRealtimeCoarseBintime` directive may be used to get
+the time with less presision and less runtime overhead.
+
+See :ref:`InterfaceRtemsClockGetRealtime` and
+:ref:`InterfaceRtemsClockGetRealtimeTimeval` to get the time in alternative
+formats.
+
+.. rubric:: CONSTRAINTS:
+
+The following constraints apply to this directive:
+
+* The directive may be called from within any runtime context.
+
+* The directive will not cause the calling task to be preempted.
+
+* The directive requires a :term:`Clock Driver`.
+
+.. Generated from spec:/rtems/clock/if/get-realtime-timeval
+
+.. raw:: latex
+
+\clearpage
+
+.. index:: rtems_clock_get_realtime_timeval()
+
+.. _InterfaceRtemsClockGetRealtimeTimeval:
+
+rtems_clock_get_realtime_timeval()
+--
+
+Gets the time elapsed since the :term:`Unix epoch` measured using
+:term:`CLOCK_REALTIME` in seconds and microseconds format.
+
+.. rubric:: CALLING SEQUENCE:
+
+.. code-block:: c
+
+void rtems_clock_get_realtime_timeval( struct timeval *time_snapshot );
+
+.. rubric:: PARAMETERS:
+
+``time_snapshot``
+This parameter is the pointer to a `struct timeval
+
`_
+object.  The time elapsed since the :term:`Unix epoch` measured using the
+:term:`CLOCK_REALTIME` at some time point during the directive call will be
+stored in this object.  Calling the directive 

[PATCH] score: Simplify _Watchdog_Next_first()

2021-10-11 Thread Sebastian Huber
---
 cpukit/include/rtems/score/watchdogimpl.h | 55 +++
 1 file changed, 36 insertions(+), 19 deletions(-)

diff --git a/cpukit/include/rtems/score/watchdogimpl.h 
b/cpukit/include/rtems/score/watchdogimpl.h
index 7b364b8828..ba1a884a3d 100644
--- a/cpukit/include/rtems/score/watchdogimpl.h
+++ b/cpukit/include/rtems/score/watchdogimpl.h
@@ -351,33 +351,50 @@ RTEMS_INLINE_ROUTINE bool _Watchdog_Is_scheduled(
 }
 
 /**
- * @brief Sets the first node of the header.
+ * @brief Sets the first watchdog of the watchdog collection to the next
+ * watchdog of the current first watchdog.
  *
- * Sets the first node of the header to either the leftmost child node of the
- *  watchdog control node, or if not present sets it to the right child node of
- * the watchdog control node. if both are not present, the new first node is
- * the parent node of the current first node.
+ * This function may be used during watchdog removals, see _Watchdog_Remove()
+ * and _Watchdog_Tickle().
  *
- * @param[in, out] header The watchdog header.
- * @param the_watchdog The watchdog control node for the operation.
+ * @param[in, out] header is the watchdog collection header.
+ *
+ * @param first is the current first watchdog which should be removed
+ *   afterwards.
  */
 RTEMS_INLINE_ROUTINE void _Watchdog_Next_first(
-  Watchdog_Header  *header,
-  Watchdog_Control *the_watchdog
+  Watchdog_Header*header,
+  const Watchdog_Control *first
 )
 {
-  RBTree_Node *node = _RBTree_Right( _watchdog->Node.RBTree );
-
-  if ( node != NULL ) {
-RBTree_Node *left;
-
-while ( ( left = _RBTree_Left( node ) ) != NULL ) {
-  node = left;
-}
+  RBTree_Node *right;
 
-header->first = node;
+  /*
+   * This function uses the following properties of red-black trees:
+   *
+   * 1. Every leaf (NULL) is black.
+   *
+   * 2. If a node is red, then both its children are black.
+   *
+   * 3. Every simple path from a node to a descendant leaf contains the same
+   *number of black nodes.
+   *
+   * The first node has no left child.  So every path from the first node has
+   * exactly one black node (including leafs).  The first node cannot have a
+   * non-leaf black right child.  It may have a red right child.  In this case
+   * both children must be leafs.
+   */
+  _Assert( header->first == >Node.RBTree );
+  _Assert( _RBTree_Left( >Node.RBTree ) == NULL );
+  right = _RBTree_Right( >Node.RBTree );
+
+  if ( right != NULL ) {
+_Assert( RB_COLOR( right, Node ) == RB_RED );
+_Assert( _RBTree_Left( right ) == NULL );
+_Assert( _RBTree_Right( right ) == NULL );
+header->first = right;
   } else {
-header->first = _RBTree_Parent( _watchdog->Node.RBTree );
+header->first = _RBTree_Parent( >Node.RBTree );
   }
 }
 
-- 
2.31.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 1/1] v2: Implement clockrdlock / clockwrlock and test

2021-10-11 Thread Matt Joyce
Added implementations of the pthread_rwlock_clockrdlock and the
pthread_rwlock_clockwrlock methods to cpukit/posix/src. Both of these
methods have been newly added to the POSIX Issue 8 Standard.

Added psxrwlock02 test to testsuites/psxtests to test the newly
added methods.
---
 cpukit/posix/src/prwlockclockrdlock.c | 111 +
 cpukit/posix/src/prwlockclockwrlock.c | 112 +
 spec/build/testsuites/psxtests/grp.yml|   2 +
 .../build/testsuites/psxtests/psxrwlock02.yml |  21 +
 testsuites/psxtests/Makefile.am   |   9 +
 testsuites/psxtests/configure.ac  |   1 +
 testsuites/psxtests/psxrwlock02/main.c| 391 ++
 7 files changed, 647 insertions(+)
 create mode 100644 cpukit/posix/src/prwlockclockrdlock.c
 create mode 100644 cpukit/posix/src/prwlockclockwrlock.c
 create mode 100644 spec/build/testsuites/psxtests/psxrwlock02.yml
 create mode 100644 testsuites/psxtests/psxrwlock02/main.c

diff --git a/cpukit/posix/src/prwlockclockrdlock.c 
b/cpukit/posix/src/prwlockclockrdlock.c
new file mode 100644
index 00..1d7dfc2cd8
--- /dev/null
+++ b/cpukit/posix/src/prwlockclockrdlock.c
@@ -0,0 +1,111 @@
+/**
+ * @file
+ *
+ * @ingroup POSIXAPI
+ *
+ * @brief Attempt to Obtain a Read Lock on a RWLock Instance
+ */
+
+/*
+ *  POSIX RWLock Manager -- Attempt to Obtain a Read Lock on a RWLock Instance.
+ *  The timeout is specified by abstime on the clock specified by clock_id.
+ */
+
+/* 
+* Copyright (C) 2021 Matthew Joyce
+* COPYRIGHT (c) 1989-2008
+* On-Line Applications Research Corporation (OAR)
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*notice, this list of conditions and the following disclaimer in the
+*documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Defining to have access to function prototype in libc/include/pthread.h */
+#define _GNU_SOURCE
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include 
+#include 
+#include 
+
+/* The POSIX Issue 8 Standard adds pthread_rwlock_clockrdlock */
+int pthread_rwlock_clockrdlock(
+  pthread_rwlock_t  *rwlock,
+  clockid_t clock_id,
+  const struct timespec *abstime
+)
+{
+  POSIX_RWLock_Control  *the_rwlock;
+  Thread_queue_Context  queue_context;
+  Status_Controlstatus;
+
+  the_rwlock = _POSIX_RWLock_Get( rwlock );
+  POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
+
+  _Thread_queue_Context_initialize( _context );
+
+  /* 
+   * The POSIX Issue 8 Standard specifies a return value of EINVAL if
+   * the abstime nsec value is less than zero or greater than or equal to
+   * 1 billion.  
+   */
+  if ( abstime->tv_nsec < 0 ) {
+return EINVAL; 
+  }
+   
+  if ( abstime->tv_nsec >= 10 ) {
+return EINVAL; 
+  }
+
+  if ( clock_id == CLOCK_REALTIME ) {
+_Thread_queue_Context_set_enqueue_timeout_realtime_timespec(
+  _context,
+  abstime,
+  true
+);
+  }
+  
+  else if ( clock_id == CLOCK_MONOTONIC ) {
+_Thread_queue_Context_set_enqueue_timeout_monotonic_timespec(
+  _context,
+  abstime,
+  true
+);
+  }
+
+  /* 
+   * The POSIX Issue 8 Standard specifies a return value of EINVAL if
+   * the clock_id parameter is not CLOCK_REALTIME or CLOCK_MONOTONIC 
+   */
+  else {
+return EINVAL;
+  }
+
+  status = _CORE_RWLock_Seize_for_reading(
+_rwlock->RWLock,
+true,
+_context
+  );
+  return _POSIX_Get_error( status );
+}
diff --git a/cpukit/posix/src/prwlockclockwrlock.c 
b/cpukit/posix/src/prwlockclockwrlock.c
new file mode 100644
index 00..ac17ae13f8
--- /dev/null
+++ b/cpukit/posix/src/prwlockclockwrlock.c
@@ -0,0 +1,112 @@
+/**
+ * @file
+ *
+ * @ingroup POSIXAPI
+ *
+ * @brief Attempt to Obtain a Write lock on a RWLock instance 
+ */
+
+/*
+ *  POSIX RWLock Manager -- Attempt to Obtain a Write Lock on a RWLock Instance
+ *  The timeout is specified by 

[PATCH 0/1] v2: Implement clockrdlock / clockwrlock and test

2021-10-11 Thread Matt Joyce
Dr. Joel,

Thanks very much for your review! Please see the updated version with
pared-down test, check for invalid clock, and check for invalid
abstime->tv_nsec.

Sincerely,

Matt

Matt Joyce (1):
  Added implementations of the pthread_rwlock_clockrdlock and the
pthread_rwlock_clockwrlock methods to cpukit/posix/src. Both of
these methods have been newly added to the POSIX Issue 8 Standard.

 cpukit/posix/src/prwlockclockrdlock.c | 111 +
 cpukit/posix/src/prwlockclockwrlock.c | 112 +
 spec/build/testsuites/psxtests/grp.yml|   2 +
 .../build/testsuites/psxtests/psxrwlock02.yml |  21 +
 testsuites/psxtests/Makefile.am   |   9 +
 testsuites/psxtests/configure.ac  |   1 +
 testsuites/psxtests/psxrwlock02/main.c| 391 ++
 7 files changed, 647 insertions(+)
 create mode 100644 cpukit/posix/src/prwlockclockrdlock.c
 create mode 100644 cpukit/posix/src/prwlockclockwrlock.c
 create mode 100644 spec/build/testsuites/psxtests/psxrwlock02.yml
 create mode 100644 testsuites/psxtests/psxrwlock02/main.c

-- 
2.31.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: Scope of variables flagged by code inspector

2021-10-11 Thread Sebastian Huber

Hello Zack,

On 10/10/2021 20:25, zack leung wrote:

I recently was invited to look at a new code review tool by Joel. It's used
to help with reducing technical debt. It suggests various fixes and
highlights various possible errors. One of them relates to the fact that
some of the variable scopes and be reduced. For example, we can define
variables when they are needed not at the beginning of functions. I don't
know if it matters much. Maybe it helps with memory due to the timing of
things allocated on the stack.  This also helps with the compiler not
needing to analyze long lifespans. This also prevents the variable to be
flagged as uninitialized.


I guess modern compiler don't care about when you define a variable. It 
is probably more an issue for the human reader.



But personally, I feel it's easier to read if we don't change where
variables are defined. An example of this is found in
testsuites/mptests/mp09/task1.c. An array called recieve_Buffer could be
defined later. I'm not sure if this matters much. I want to know your
input.


Moving the variable to the most local scope is already covered by the 
current coding style (I hope). Maybe this needs to be clarified in the 
coding style.


From my point of view we should go one step further and allow the 
declaration and preferably also the initialization of local variables as 
close to their first use as possible in contrast to only the scope begin.


--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.hu...@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel