File: magma_yield.cpp

package info (click to toggle)
magma 2.9.0%2Bds-3
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 83,556 kB
  • sloc: cpp: 709,115; fortran: 121,916; ansic: 32,343; python: 25,603; f90: 15,208; makefile: 945; xml: 253; csh: 232; sh: 203; perl: 104
file content (63 lines) | stat: -rw-r--r-- 1,671 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
    -- MAGMA (version 2.9.0) --
       Univ. of Tennessee, Knoxville
       Univ. of California, Berkeley
       Univ. of Colorado, Denver
       @date January 2025

       @author Azzam Haidar

*/
#include "magma_internal.h"

#if defined(linux) || defined(__linux) || defined(__linux__)
    #define MAGMA_OS_LINUX 1
    #ifndef _GNU_SOURCE
    #define _GNU_SOURCE
    #endif

    #include <unistd.h>
    #include <sched.h>

#elif defined(__FreeBSD__)
    #define MAGMA_OS_FREEBSD 1
    #include <unistd.h>
    #include <inttypes.h>
    #include <sys/param.h>
    #include <sys/cpuset.h>
    #include <sched.h>

#elif defined( _WIN32 ) || defined( _WIN64 )
    #define MAGMA_OS_WINDOWS 1
    #include <Windows.h>

#elif (defined __APPLE__) || (defined macintosh) || (defined __MACOSX__)
    #define MAGMA_OS_MACOS 1
    #include <sys/param.h>
    #include <sys/sysctl.h>
    #include <mach/mach_init.h>
    #include <mach/thread_policy.h>

#elif (defined _AIX)
    #define MAGMA_OS_AIX 1

#else
    #error "Cannot determine the OS, or OS not supported. Supported systems are: Linux, FreeBSD, Windows, MacOS X, AIX."
#endif

/***************************************************************************//**
    Yield the CPU to let another thread of lower priority run,
    for example, for I/O.

    @ingroup magma_thread
*******************************************************************************/
magma_int_t magma_yield()
{
#if (defined MAGMA_OS_LINUX) || (defined MAGMA_OS_FREEBSD) || (defined MAGMA_OS_MACOS) || (defined MAGMA_OS_AIX)
    return sched_yield();
#elif MAGMA_OS_WINDOWS
    return SleepEx(0,0);
#else
    return MAGMA_ERR_NOT_SUPPORTED;
#endif
}