xiaoxiang781216 commented on code in PR #10572:
URL: https://github.com/apache/nuttx/pull/10572#discussion_r1327962137


##########
libs/libc/sched/sched_gettid.c:
##########
@@ -0,0 +1,65 @@
+/****************************************************************************
+ * libs/libc/sched/sched_gettid.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/tls.h>
+
+#include <unistd.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxsched_gettid
+ *
+ * Description:
+ *   Utilise thread local storage to get the thread ID of the currently
+ *   executing thread and cache the result for further queries. Caching this
+ *   result reduces system call loading when using CONFIG_BUILD_KERNEL.
+ *
+ * Input parameters:
+ *   None
+ *
+ * Returned Value:
+ *   On success, returns the thread ID of the calling process.
+ *
+ ****************************************************************************/
+
+#if !defined(CONFIG_BUILD_FLAT) && defined(CONFIG_SCHED_THREAD_LOCAL) && 
!defined(__KERNEL__)
+
+pid_t sched_gettid(void)
+{
+  FAR struct tls_info_s *tlsinfo = tls_get_info();
+
+  DEBUGASSERT(tlsinfo);
+
+  if (tlsinfo->tl_tid <= 0)

Review Comment:
   let's fill tl_tid in tls_init_info



##########
libs/libc/sched/sched_gettid.c:
##########
@@ -0,0 +1,65 @@
+/****************************************************************************
+ * libs/libc/sched/sched_gettid.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/tls.h>
+
+#include <unistd.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxsched_gettid
+ *
+ * Description:
+ *   Utilise thread local storage to get the thread ID of the currently
+ *   executing thread and cache the result for further queries. Caching this
+ *   result reduces system call loading when using CONFIG_BUILD_KERNEL.
+ *
+ * Input parameters:
+ *   None
+ *
+ * Returned Value:
+ *   On success, returns the thread ID of the calling process.
+ *
+ ****************************************************************************/
+
+#if !defined(CONFIG_BUILD_FLAT) && defined(CONFIG_SCHED_THREAD_LOCAL) && 
!defined(__KERNEL__)
+
+pid_t sched_gettid(void)

Review Comment:
   ```suggestion
   pid_t gettid(void)
   ```
   and remove the old implementation from nuttx/sched and nuttx/syscall.



##########
include/nuttx/sched.h:
##########
@@ -160,7 +160,11 @@
 #  define _SCHED_ERRNO(r)            (-(r))
 #  define _SCHED_ERRVAL(r)           (r)
 #else
+#if defined(CONFIG_SCHED_THREAD_LOCAL)
+#  define _SCHED_GETTID()            sched_gettid()

Review Comment:
   remove _SCHED_GETTID since we don't have the different implementation 
between kernel and userspace.



##########
libs/libc/sched/sched_gettid.c:
##########
@@ -0,0 +1,65 @@
+/****************************************************************************
+ * libs/libc/sched/sched_gettid.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/tls.h>
+
+#include <unistd.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxsched_gettid
+ *
+ * Description:
+ *   Utilise thread local storage to get the thread ID of the currently
+ *   executing thread and cache the result for further queries. Caching this
+ *   result reduces system call loading when using CONFIG_BUILD_KERNEL.
+ *
+ * Input parameters:
+ *   None
+ *
+ * Returned Value:
+ *   On success, returns the thread ID of the calling process.
+ *
+ ****************************************************************************/
+
+#if !defined(CONFIG_BUILD_FLAT) && defined(CONFIG_SCHED_THREAD_LOCAL) && 
!defined(__KERNEL__)

Review Comment:
   remove, the implementation should work for all build.



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