daniel-p-carvalho commented on code in PR #3782:
URL: https://github.com/apache/nuttx-apps/pull/3782#discussion_r4060909728


##########
netutils/ptpd/ptpd.c:
##########
@@ -181,6 +197,25 @@ struct ptp_state_s
   FAR const struct ptpd_config_s *config;
 };
 
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_BUILD_FLAT
+/* The status request of ptpd_status(). The daemon keeps its address until it
+ * answers, which can be after ptpd_status() gave up waiting and returned, so
+ * it lives in static memory and never on the stack of the caller. The lock
+ * lets only one caller use it at a time.
+ */
+
+static struct ptpd_statusreq_s g_statusreq =

Review Comment:
   The request cannot live on the stack of the caller: `ptpd_status()` gives up 
after one second if the daemon does not answer and returns, and the daemon 
keeps the pointer it got in the signal until it answers, which can be later. 
With a stack variable it would write in a frame that no longer exists. The lock 
is there because there is one shared request: without it two callers at the 
same time would overwrite each other.
   
   If you prefer no static object and no lock, I can allocate the request with 
a reference count, so that the caller and the daemon each drop their reference 
and the last one frees it. It is more code, so I kept the static one as the 
smaller change. Tell me which one you prefer and I will change it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to