You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/11/30 10:00:26 UTC

[GitHub] [nuttx] XinStellaris opened a new pull request, #7735: Add linux-like panic notifier.

XinStellaris opened a new pull request, #7735:
URL: https://github.com/apache/nuttx/pull/7735

   Signed-off-by: 田昕 <ti...@xiaomi.com>
   
   ## Summary
   Linux has a notifier mechanism for panic/reboot.... and so on. This is useful, for example if we want to gracefully close wifi when rebooting. I tried to implement similar thing in Nuttx in this PR.
   Also I used the notifier to redirect syslog output into flash when assert happens.
   ## Impact
   assert function is impacted.
   
   ## Testing
   Tested on ESP32C3
   


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7735: Add linux-like panic notifier.

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7735:
URL: https://github.com/apache/nuttx/pull/7735#discussion_r1037951675


##########
include/nuttx/notifier.h:
##########
@@ -0,0 +1,201 @@
+/****************************************************************************
+ * include/nuttx/notifier.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_NOTIFIER_H
+#define __INCLUDE_NUTTX_NOTIFIER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/irq.h>
+
+#include <debug.h>
+#include <errno.h>
+
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ATOMIC_NOTIFIER_INIT(name) {.head = NULL }

Review Comment:
   @XinStellaris try this:
   ```
   #define ATOMIC_NOTIFIER_INIT(name) {NULL}
   ```



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7735: Add linux-like panic notifier.

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7735:
URL: https://github.com/apache/nuttx/pull/7735#discussion_r1037443177


##########
include/nuttx/notifier.h:
##########
@@ -0,0 +1,197 @@
+/****************************************************************************
+ * include/nuttx/notifier.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_NOTIFIER_H
+#define __INCLUDE_NUTTX_NOTIFIER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/irq.h>
+
+#include <debug.h>
+#include <errno.h>
+
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ATOMIC_NOTIFIER_INIT(name) {.head = NULL }
+
+#define ATOMIC_NOTIFIER_HEAD(name) \
+  struct atomic_notifier_head name = ATOMIC_NOTIFIER_INIT(name)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct notifier_block;
+
+typedef int (*notifier_fn_t)(FAR struct notifier_block *nb,
+                             unsigned long action, FAR void *data);
+
+struct notifier_block
+{
+  notifier_fn_t              notifier_call;
+  FAR struct notifier_block *next;
+  int                        priority;
+};
+
+struct atomic_notifier_head
+{
+  FAR struct notifier_block *head;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#define notifier_chain_register(nhead, node, unique_priority) \
+  do \
+    { \
+      FAR struct notifier_block **nl = nhead; \

Review Comment:
   ```suggestion
         FAR struct notifier_block **nl = (nhead); \
   ```
   add  () for all macro parameter



##########
include/nuttx/notifier.h:
##########
@@ -0,0 +1,197 @@
+/****************************************************************************
+ * include/nuttx/notifier.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_NOTIFIER_H
+#define __INCLUDE_NUTTX_NOTIFIER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/irq.h>
+
+#include <debug.h>
+#include <errno.h>
+
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ATOMIC_NOTIFIER_INIT(name) {.head = NULL }
+
+#define ATOMIC_NOTIFIER_HEAD(name) \
+  struct atomic_notifier_head name = ATOMIC_NOTIFIER_INIT(name)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct notifier_block;
+
+typedef int (*notifier_fn_t)(FAR struct notifier_block *nb,

Review Comment:
   ```suggestion
   typedef CODE int (*notifier_fn_t)(FAR struct notifier_block *nb,
   ```



##########
include/nuttx/notifier.h:
##########
@@ -0,0 +1,197 @@
+/****************************************************************************
+ * include/nuttx/notifier.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_NOTIFIER_H
+#define __INCLUDE_NUTTX_NOTIFIER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/irq.h>
+
+#include <debug.h>
+#include <errno.h>
+
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ATOMIC_NOTIFIER_INIT(name) {.head = NULL }
+
+#define ATOMIC_NOTIFIER_HEAD(name) \
+  struct atomic_notifier_head name = ATOMIC_NOTIFIER_INIT(name)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct notifier_block;
+
+typedef int (*notifier_fn_t)(FAR struct notifier_block *nb,
+                             unsigned long action, FAR void *data);
+
+struct notifier_block
+{
+  notifier_fn_t              notifier_call;
+  FAR struct notifier_block *next;
+  int                        priority;
+};
+
+struct atomic_notifier_head
+{
+  FAR struct notifier_block *head;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#define notifier_chain_register(nhead, node, unique_priority) \
+  do \
+    { \
+      FAR struct notifier_block **nl = nhead; \
+      FAR struct notifier_block *n = node; \
+      int flag = 0; \
+      while (*nl != NULL) \
+        { \
+          if (*nl == n) \
+            { \
+              flag = -EEXIST; \
+              break; \
+            } \
+          if (n->priority > (*nl)->priority)  \
+              break; \
+          if (n->priority == (*nl)->priority && unique_priority) \
+            { \
+              flag = -EBUSY; \
+              break; \
+            } \
+          nl = &((*nl)->next); \
+        } \
+      if (flag == 0) \
+        { \
+          n->next = *nl; \
+          *nl = n; \
+        } \
+    } \
+  while (0)
+
+#define notifier_chain_unregister(nhead, node) \
+  do \
+    { \
+      FAR struct notifier_block **nl = nhead; \
+      FAR struct notifier_block *n = node; \
+      while (*nl != NULL) \
+        { \
+          if (*nl == n) \
+            { \
+              *nl = n->next; \
+              break; \
+            } \
+          nl = &((*nl)->next); \
+        } \
+    } \
+  while(0)
+
+#define notifier_call_chain(nhead, val, v, num_to_call, num_calls) \
+  do \
+    { \
+      FAR struct notifier_block *nb; \
+      FAR struct notifier_block *next_nb; \
+      int nr_to_call = num_to_call; \
+      FAR int *nr_calls = num_calls; \
+      nb = *nhead; \
+      while (nb && nr_to_call) \
+        { \
+          next_nb = nb->next; \
+          nb->notifier_call(nb, val, v); \
+          if (nr_calls) \
+              (*nr_calls)++; \
+          nb = next_nb; \
+          nr_to_call--; \
+        } \
+    } \
+  while(0)
+
+#define atomic_notifychain_reg(nhead, nb) \
+  do \
+    { \
+      FAR struct atomic_notifier_head *nh = nhead; \
+      irqstate_t flags; \
+      flags = enter_critical_section(); \
+      notifier_chain_register(&nh->head, nb, false); \

Review Comment:
   let's notifier_chain_register use & instead
   ```suggestion
         notifier_chain_register(nh->head, nb, false); \
   ```
   please apply to other similar place too



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] XinStellaris commented on a diff in pull request #7735: Add linux-like panic notifier.

Posted by GitBox <gi...@apache.org>.
XinStellaris commented on code in PR #7735:
URL: https://github.com/apache/nuttx/pull/7735#discussion_r1037935431


##########
include/nuttx/notifier.h:
##########
@@ -0,0 +1,201 @@
+/****************************************************************************
+ * include/nuttx/notifier.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_NOTIFIER_H
+#define __INCLUDE_NUTTX_NOTIFIER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/irq.h>
+
+#include <debug.h>
+#include <errno.h>
+
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ATOMIC_NOTIFIER_INIT(name) {.head = NULL }

Review Comment:
   Any suggestion how to modify?



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #7735: Add linux-like panic notifier.

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #7735:
URL: https://github.com/apache/nuttx/pull/7735#discussion_r1037933095


##########
include/nuttx/notifier.h:
##########
@@ -0,0 +1,201 @@
+/****************************************************************************
+ * include/nuttx/notifier.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_NOTIFIER_H
+#define __INCLUDE_NUTTX_NOTIFIER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/irq.h>
+
+#include <debug.h>
+#include <errno.h>
+
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ATOMIC_NOTIFIER_INIT(name) {.head = NULL }

Review Comment:
   C89 incompatible



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7735: Add linux-like panic notifier.

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7735:
URL: https://github.com/apache/nuttx/pull/7735#discussion_r1037857912


##########
include/nuttx/notifier.h:
##########
@@ -0,0 +1,199 @@
+/****************************************************************************
+ * include/nuttx/notifier.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_NOTIFIER_H
+#define __INCLUDE_NUTTX_NOTIFIER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/irq.h>
+
+#include <debug.h>
+#include <errno.h>
+
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ATOMIC_NOTIFIER_INIT(name) {.head = NULL }
+
+#define ATOMIC_NOTIFIER_HEAD(name) \
+  struct atomic_notifier_head name = ATOMIC_NOTIFIER_INIT(name)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct notifier_block;
+
+typedef CODE int (*notifier_fn_t)(FAR struct notifier_block *nb,
+                                  unsigned long action, FAR void *data);
+
+struct notifier_block
+{
+  notifier_fn_t              notifier_call;
+  FAR struct notifier_block *next;
+  int                        priority;
+};
+
+struct atomic_notifier_head
+{
+  FAR struct notifier_block *head;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#define notifier_chain_register(nhead, node, unique_priority) \
+  do \
+    { \
+      FAR struct notifier_block **nl = &(nhead); \
+      FAR struct notifier_block *n = (node); \
+      int flag = 0; \
+      while (*nl != NULL) \
+        { \
+          if (*nl == n) \
+            { \
+              flag = -EEXIST; \
+              break; \
+            } \
+          if (n->priority > (*nl)->priority)  \

Review Comment:
   add {}



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #7735: Add linux-like panic notifier.

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #7735:
URL: https://github.com/apache/nuttx/pull/7735#discussion_r1037773012


##########
include/nuttx/notifier.h:
##########
@@ -0,0 +1,197 @@
+/****************************************************************************
+ * include/nuttx/notifier.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_NOTIFIER_H
+#define __INCLUDE_NUTTX_NOTIFIER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/irq.h>
+
+#include <debug.h>
+#include <errno.h>
+
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ATOMIC_NOTIFIER_INIT(name) {.head = NULL }
+
+#define ATOMIC_NOTIFIER_HEAD(name) \
+  struct atomic_notifier_head name = ATOMIC_NOTIFIER_INIT(name)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct notifier_block;
+
+typedef CODE int (*notifier_fn_t)(FAR struct notifier_block *nb,
+                                  unsigned long action, FAR void *data);
+
+struct notifier_block
+{
+  notifier_fn_t              notifier_call;
+  FAR struct notifier_block *next;
+  int                        priority;
+};
+
+struct atomic_notifier_head
+{
+  FAR struct notifier_block *head;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#define notifier_chain_register(nhead, node, unique_priority) \
+  do \
+    { \
+      FAR struct notifier_block **nl = &(nhead); \
+      FAR struct notifier_block *n = (node); \
+      int flag = 0; \
+      while (*nl != NULL) \
+        { \
+          if (*nl == n) \
+            { \
+              flag = -EEXIST; \
+              break; \
+            } \
+          if (n->priority > (*nl)->priority)  \
+              break; \
+          if (n->priority == (*nl)->priority && (unique_priority)) \
+            { \
+              flag = -EBUSY; \
+              break; \
+            } \
+          nl = &((*nl)->next); \
+        } \
+      if (flag == 0) \
+        { \
+          n->next = *nl; \
+          *nl = n; \
+        } \
+    } \
+  while (0)
+
+#define notifier_chain_unregister(nhead, node) \
+  do \
+    { \
+      FAR struct notifier_block **nl = &(nhead); \
+      FAR struct notifier_block *n = (node); \
+      while (*nl != NULL) \
+        { \
+          if (*nl == n) \
+            { \
+              *nl = n->next; \
+              break; \
+            } \
+          nl = &((*nl)->next); \
+        } \
+    } \
+  while(0)
+
+#define notifier_call_chain(nhead, val, v, num_to_call, num_calls) \
+  do \
+    { \
+      FAR struct notifier_block *nb; \
+      FAR struct notifier_block *next_nb; \
+      int nr_to_call = (num_to_call); \
+      FAR int *nr_calls = (num_calls); \
+      nb = (nhead); \
+      while (nb && nr_to_call) \
+        { \
+          next_nb = nb->next; \
+          nb->notifier_call(nb, (val), (v)); \
+          if (nr_calls) \
+              (*nr_calls)++; \
+          nb = next_nb; \
+          nr_to_call--; \
+        } \
+    } \
+  while(0)
+
+#define atomic_notifychain_reg(nhead, nb) \
+  do \
+    { \
+      FAR struct atomic_notifier_head *nh = (nhead); \
+      irqstate_t flags; \
+      flags = enter_critical_section(); \
+      notifier_chain_register(nh->head, (nb), false); \
+      leave_critical_section(flags); \
+    } \
+  while(0)
+
+#define atomic_notifychain_reg_uniqueprio(nhead, nb) \

Review Comment:
   ```suggestion
   #define atomic_notifier_chain_register_unique_prio(nhead, nb) \
   ```



##########
include/nuttx/notifier.h:
##########
@@ -0,0 +1,197 @@
+/****************************************************************************
+ * include/nuttx/notifier.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_NOTIFIER_H
+#define __INCLUDE_NUTTX_NOTIFIER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/irq.h>
+
+#include <debug.h>
+#include <errno.h>
+
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ATOMIC_NOTIFIER_INIT(name) {.head = NULL }
+
+#define ATOMIC_NOTIFIER_HEAD(name) \
+  struct atomic_notifier_head name = ATOMIC_NOTIFIER_INIT(name)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct notifier_block;
+
+typedef CODE int (*notifier_fn_t)(FAR struct notifier_block *nb,
+                                  unsigned long action, FAR void *data);
+
+struct notifier_block
+{
+  notifier_fn_t              notifier_call;
+  FAR struct notifier_block *next;
+  int                        priority;
+};
+
+struct atomic_notifier_head
+{
+  FAR struct notifier_block *head;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#define notifier_chain_register(nhead, node, unique_priority) \
+  do \
+    { \
+      FAR struct notifier_block **nl = &(nhead); \
+      FAR struct notifier_block *n = (node); \
+      int flag = 0; \
+      while (*nl != NULL) \
+        { \
+          if (*nl == n) \
+            { \
+              flag = -EEXIST; \
+              break; \
+            } \
+          if (n->priority > (*nl)->priority)  \
+              break; \
+          if (n->priority == (*nl)->priority && (unique_priority)) \
+            { \
+              flag = -EBUSY; \
+              break; \
+            } \
+          nl = &((*nl)->next); \
+        } \
+      if (flag == 0) \
+        { \
+          n->next = *nl; \
+          *nl = n; \
+        } \
+    } \
+  while (0)
+
+#define notifier_chain_unregister(nhead, node) \
+  do \
+    { \
+      FAR struct notifier_block **nl = &(nhead); \
+      FAR struct notifier_block *n = (node); \
+      while (*nl != NULL) \
+        { \
+          if (*nl == n) \
+            { \
+              *nl = n->next; \
+              break; \
+            } \
+          nl = &((*nl)->next); \
+        } \
+    } \
+  while(0)
+
+#define notifier_call_chain(nhead, val, v, num_to_call, num_calls) \
+  do \
+    { \
+      FAR struct notifier_block *nb; \
+      FAR struct notifier_block *next_nb; \
+      int nr_to_call = (num_to_call); \
+      FAR int *nr_calls = (num_calls); \
+      nb = (nhead); \
+      while (nb && nr_to_call) \
+        { \
+          next_nb = nb->next; \
+          nb->notifier_call(nb, (val), (v)); \
+          if (nr_calls) \
+              (*nr_calls)++; \
+          nb = next_nb; \
+          nr_to_call--; \
+        } \
+    } \
+  while(0)
+
+#define atomic_notifychain_reg(nhead, nb) \
+  do \
+    { \
+      FAR struct atomic_notifier_head *nh = (nhead); \
+      irqstate_t flags; \
+      flags = enter_critical_section(); \
+      notifier_chain_register(nh->head, (nb), false); \
+      leave_critical_section(flags); \
+    } \
+  while(0)
+
+#define atomic_notifychain_reg_uniqueprio(nhead, nb) \
+  do \
+    { \
+      FAR struct atomic_notifier_head *nh = (nhead); \
+      irqstate_t flags; \
+      flags = enter_critical_section(); \
+      notifier_chain_register(nh->head, (nb), true); \
+      leave_critical_section(flags); \
+    } \
+  while(0)
+
+#define atomic_notifychain_unreg(nhead, nb) \

Review Comment:
   ```suggestion
   #define atomic_notifier_chain_unregister(nhead, nb) \
   ```



##########
include/nuttx/notifier.h:
##########
@@ -0,0 +1,197 @@
+/****************************************************************************
+ * include/nuttx/notifier.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_NOTIFIER_H
+#define __INCLUDE_NUTTX_NOTIFIER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/irq.h>
+
+#include <debug.h>
+#include <errno.h>
+
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ATOMIC_NOTIFIER_INIT(name) {.head = NULL }
+
+#define ATOMIC_NOTIFIER_HEAD(name) \
+  struct atomic_notifier_head name = ATOMIC_NOTIFIER_INIT(name)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct notifier_block;
+
+typedef CODE int (*notifier_fn_t)(FAR struct notifier_block *nb,
+                                  unsigned long action, FAR void *data);
+
+struct notifier_block
+{
+  notifier_fn_t              notifier_call;
+  FAR struct notifier_block *next;
+  int                        priority;
+};
+
+struct atomic_notifier_head
+{
+  FAR struct notifier_block *head;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#define notifier_chain_register(nhead, node, unique_priority) \
+  do \
+    { \
+      FAR struct notifier_block **nl = &(nhead); \
+      FAR struct notifier_block *n = (node); \
+      int flag = 0; \
+      while (*nl != NULL) \
+        { \
+          if (*nl == n) \
+            { \
+              flag = -EEXIST; \
+              break; \
+            } \
+          if (n->priority > (*nl)->priority)  \
+              break; \
+          if (n->priority == (*nl)->priority && (unique_priority)) \
+            { \
+              flag = -EBUSY; \
+              break; \
+            } \
+          nl = &((*nl)->next); \
+        } \
+      if (flag == 0) \
+        { \
+          n->next = *nl; \
+          *nl = n; \
+        } \
+    } \
+  while (0)
+
+#define notifier_chain_unregister(nhead, node) \
+  do \
+    { \
+      FAR struct notifier_block **nl = &(nhead); \
+      FAR struct notifier_block *n = (node); \
+      while (*nl != NULL) \
+        { \
+          if (*nl == n) \
+            { \
+              *nl = n->next; \
+              break; \
+            } \
+          nl = &((*nl)->next); \
+        } \
+    } \
+  while(0)
+
+#define notifier_call_chain(nhead, val, v, num_to_call, num_calls) \
+  do \
+    { \
+      FAR struct notifier_block *nb; \
+      FAR struct notifier_block *next_nb; \
+      int nr_to_call = (num_to_call); \
+      FAR int *nr_calls = (num_calls); \
+      nb = (nhead); \
+      while (nb && nr_to_call) \
+        { \
+          next_nb = nb->next; \
+          nb->notifier_call(nb, (val), (v)); \
+          if (nr_calls) \
+              (*nr_calls)++; \

Review Comment:
   add {}



##########
include/nuttx/notifier.h:
##########
@@ -0,0 +1,197 @@
+/****************************************************************************
+ * include/nuttx/notifier.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_NOTIFIER_H
+#define __INCLUDE_NUTTX_NOTIFIER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/irq.h>
+
+#include <debug.h>
+#include <errno.h>
+
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ATOMIC_NOTIFIER_INIT(name) {.head = NULL }
+
+#define ATOMIC_NOTIFIER_HEAD(name) \
+  struct atomic_notifier_head name = ATOMIC_NOTIFIER_INIT(name)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct notifier_block;
+
+typedef CODE int (*notifier_fn_t)(FAR struct notifier_block *nb,
+                                  unsigned long action, FAR void *data);
+
+struct notifier_block
+{
+  notifier_fn_t              notifier_call;
+  FAR struct notifier_block *next;
+  int                        priority;
+};
+
+struct atomic_notifier_head
+{
+  FAR struct notifier_block *head;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#define notifier_chain_register(nhead, node, unique_priority) \
+  do \
+    { \
+      FAR struct notifier_block **nl = &(nhead); \
+      FAR struct notifier_block *n = (node); \
+      int flag = 0; \
+      while (*nl != NULL) \
+        { \
+          if (*nl == n) \
+            { \
+              flag = -EEXIST; \
+              break; \
+            } \
+          if (n->priority > (*nl)->priority)  \
+              break; \
+          if (n->priority == (*nl)->priority && (unique_priority)) \
+            { \
+              flag = -EBUSY; \
+              break; \
+            } \
+          nl = &((*nl)->next); \
+        } \
+      if (flag == 0) \
+        { \
+          n->next = *nl; \
+          *nl = n; \
+        } \
+    } \
+  while (0)
+
+#define notifier_chain_unregister(nhead, node) \
+  do \
+    { \
+      FAR struct notifier_block **nl = &(nhead); \
+      FAR struct notifier_block *n = (node); \
+      while (*nl != NULL) \
+        { \
+          if (*nl == n) \
+            { \
+              *nl = n->next; \
+              break; \
+            } \
+          nl = &((*nl)->next); \
+        } \
+    } \
+  while(0)
+
+#define notifier_call_chain(nhead, val, v, num_to_call, num_calls) \
+  do \
+    { \
+      FAR struct notifier_block *nb; \
+      FAR struct notifier_block *next_nb; \
+      int nr_to_call = (num_to_call); \
+      FAR int *nr_calls = (num_calls); \
+      nb = (nhead); \
+      while (nb && nr_to_call) \
+        { \
+          next_nb = nb->next; \
+          nb->notifier_call(nb, (val), (v)); \
+          if (nr_calls) \
+              (*nr_calls)++; \
+          nb = next_nb; \
+          nr_to_call--; \
+        } \
+    } \
+  while(0)
+
+#define atomic_notifychain_reg(nhead, nb) \

Review Comment:
   ```suggestion
   #define atomic_notifier_chain_register(nhead, nb) \
   ```



##########
include/nuttx/notifier.h:
##########
@@ -0,0 +1,197 @@
+/****************************************************************************
+ * include/nuttx/notifier.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_NOTIFIER_H
+#define __INCLUDE_NUTTX_NOTIFIER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/irq.h>
+
+#include <debug.h>
+#include <errno.h>
+
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ATOMIC_NOTIFIER_INIT(name) {.head = NULL }
+
+#define ATOMIC_NOTIFIER_HEAD(name) \
+  struct atomic_notifier_head name = ATOMIC_NOTIFIER_INIT(name)
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+struct notifier_block;
+
+typedef CODE int (*notifier_fn_t)(FAR struct notifier_block *nb,
+                                  unsigned long action, FAR void *data);
+
+struct notifier_block
+{
+  notifier_fn_t              notifier_call;
+  FAR struct notifier_block *next;
+  int                        priority;
+};
+
+struct atomic_notifier_head
+{
+  FAR struct notifier_block *head;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#define notifier_chain_register(nhead, node, unique_priority) \
+  do \
+    { \
+      FAR struct notifier_block **nl = &(nhead); \
+      FAR struct notifier_block *n = (node); \
+      int flag = 0; \
+      while (*nl != NULL) \
+        { \
+          if (*nl == n) \
+            { \
+              flag = -EEXIST; \
+              break; \
+            } \
+          if (n->priority > (*nl)->priority)  \
+              break; \
+          if (n->priority == (*nl)->priority && (unique_priority)) \
+            { \
+              flag = -EBUSY; \
+              break; \
+            } \
+          nl = &((*nl)->next); \
+        } \
+      if (flag == 0) \
+        { \
+          n->next = *nl; \
+          *nl = n; \
+        } \
+    } \
+  while (0)
+
+#define notifier_chain_unregister(nhead, node) \
+  do \
+    { \
+      FAR struct notifier_block **nl = &(nhead); \
+      FAR struct notifier_block *n = (node); \
+      while (*nl != NULL) \
+        { \
+          if (*nl == n) \
+            { \
+              *nl = n->next; \
+              break; \
+            } \
+          nl = &((*nl)->next); \
+        } \
+    } \
+  while(0)
+
+#define notifier_call_chain(nhead, val, v, num_to_call, num_calls) \
+  do \
+    { \
+      FAR struct notifier_block *nb; \
+      FAR struct notifier_block *next_nb; \
+      int nr_to_call = (num_to_call); \
+      FAR int *nr_calls = (num_calls); \
+      nb = (nhead); \
+      while (nb && nr_to_call) \
+        { \
+          next_nb = nb->next; \
+          nb->notifier_call(nb, (val), (v)); \
+          if (nr_calls) \
+              (*nr_calls)++; \
+          nb = next_nb; \
+          nr_to_call--; \
+        } \
+    } \
+  while(0)
+
+#define atomic_notifychain_reg(nhead, nb) \
+  do \
+    { \
+      FAR struct atomic_notifier_head *nh = (nhead); \
+      irqstate_t flags; \
+      flags = enter_critical_section(); \
+      notifier_chain_register(nh->head, (nb), false); \
+      leave_critical_section(flags); \
+    } \
+  while(0)
+
+#define atomic_notifychain_reg_uniqueprio(nhead, nb) \
+  do \
+    { \
+      FAR struct atomic_notifier_head *nh = (nhead); \
+      irqstate_t flags; \
+      flags = enter_critical_section(); \
+      notifier_chain_register(nh->head, (nb), true); \
+      leave_critical_section(flags); \
+    } \
+  while(0)
+
+#define atomic_notifychain_unreg(nhead, nb) \
+  do \
+    { \
+      FAR struct atomic_notifier_head *nh = (nhead); \
+      irqstate_t flags; \
+      flags = enter_critical_section(); \
+      notifier_chain_unregister(nh->head, (nb); \
+      leave_critical_section(flags); \
+    } \
+  while(0)
+
+#define atomic_notifychain_call(nhead, val, v) \

Review Comment:
   ```suggestion
   #define atomic_notifier_call_chain(nhead, val, v) \
   ```



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 merged pull request #7735: Add linux-like panic notifier.

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #7735:
URL: https://github.com/apache/nuttx/pull/7735


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org