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/06/09 08:30:30 UTC

[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #6376: nuttx/mutex: do not use non-nx interface in kernel except libs

pkarashchenko commented on code in PR #6376:
URL: https://github.com/apache/incubator-nuttx/pull/6376#discussion_r893222865


##########
include/mutex.h:
##########
@@ -0,0 +1,522 @@
+/****************************************************************************
+ * include/mutex.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_MUTEX_H
+#define __INCLUDE_MUTEX_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdbool.h>
+#include <errno.h>
+#include <assert.h>
+#include <unistd.h>
+#include <semaphore.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MUTEX_NO_HOLDER      (pid_t)-1
+
+/* Initializers */
+
+#define MUTEX_INITIALIZER    {SEM_INITIALIZER(1),MUTEX_NO_HOLDER}
+#define RMUTEX_INITIALIZER   {MUTEX_INITIALIZER,0}
+
+/****************************************************************************
+ * Public Type Declarations
+ ****************************************************************************/
+
+struct mutex_s
+{
+  sem_t sem;
+  pid_t holder;

Review Comment:
   In general mutex should have the holder stored and do not allow unlock not from a holder thread. We can even `DEBUGASSERT` if we try to unlock from not a mutex holder



-- 
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