sched/sched/sched_getcpu.c: Implement non-standard interface.

If SMP is enabled this function will return the number of the CPU that the thread is running on.  This is non-standard but follows GLIBC if __GNU_SOURCE is enabled.  The returned CPU number is, however, worthless since it returns the CPU number of the CPU that was executing the task when the function was called.  The application can never know the true CPU number of the CPU tht it is running on since that value is volatile and change change at any time.
This commit is contained in:
Gregory Nutt
2020-01-31 20:25:15 +00:00
committed by Ouss4
parent 80277d1630
commit 2def8035db
7 changed files with 108 additions and 13 deletions
+4 -2
View File
@@ -1,8 +1,8 @@
/********************************************************************************
* include/sched.h
*
* Copyright (C) 2007-2009, 2011, 2013, 2015-2016 Gregory Nutt. All rights
* reserved.
* Copyright (C) 2007-2009, 2011, 2013, 2015-2016, 2020 Gregory Nutt. All
* rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,7 @@
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/sched.h>
/********************************************************************************
@@ -265,6 +266,7 @@ int sched_setaffinity(pid_t pid, size_t cpusetsize,
FAR const cpu_set_t *mask);
int sched_getaffinity(pid_t pid, size_t cpusetsize, FAR cpu_set_t *mask);
int sched_cpu_count(FAR const cpu_set_t *set);
int sched_getcpu(void);
#endif /* CONFIG_SMP */
/* Task Switching Interfaces (non-standard) */