"Fossies" - the Fresh Open Source Software Archive

Member "gnuastro-0.8/bootstrapped/tests/glthread/yield.h" (28 Dec 2018, 2536 Bytes) of package /linux/privat/gnuastro-0.8.tar.lz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "yield.h": 0.5_vs_0.6.

    1 /* Yielding the processor to other threads and processes.
    2    Copyright (C) 2005-2018 Free Software Foundation, Inc.
    3 
    4    This program is free software; you can redistribute it and/or modify
    5    it under the terms of the GNU General Public License as published by
    6    the Free Software Foundation; either version 3, or (at your option)
    7    any later version.
    8 
    9    This program is distributed in the hope that it will be useful,
   10    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12    GNU General Public License for more details.
   13 
   14    You should have received a copy of the GNU General Public License
   15    along with this program; if not, see <https://www.gnu.org/licenses/>.  */
   16 
   17 /* This file contains a primitive for yielding the processor to other threads.
   18      extern void gl_thread_yield (void);
   19  */
   20 
   21 #ifndef _GLTHREAD_YIELD_H
   22 #define _GLTHREAD_YIELD_H
   23 
   24 #include <errno.h>
   25 
   26 /* ========================================================================= */
   27 
   28 #if USE_POSIX_THREADS
   29 
   30 /* Use the POSIX threads library.  */
   31 
   32 # include <sched.h>
   33 
   34 # ifdef __cplusplus
   35 extern "C" {
   36 # endif
   37 
   38 # define gl_thread_yield() \
   39     sched_yield ()
   40 
   41 # ifdef __cplusplus
   42 }
   43 # endif
   44 
   45 #endif
   46 
   47 /* ========================================================================= */
   48 
   49 #if USE_PTH_THREADS
   50 
   51 /* Use the GNU Pth threads library.  */
   52 
   53 # include <pth.h>
   54 
   55 # ifdef __cplusplus
   56 extern "C" {
   57 # endif
   58 
   59 # define gl_thread_yield() \
   60     pth_yield (NULL)
   61 
   62 # ifdef __cplusplus
   63 }
   64 # endif
   65 
   66 #endif
   67 
   68 /* ========================================================================= */
   69 
   70 #if USE_SOLARIS_THREADS
   71 
   72 /* Use the old Solaris threads library.  */
   73 
   74 # include <thread.h>
   75 
   76 # ifdef __cplusplus
   77 extern "C" {
   78 # endif
   79 
   80 # define gl_thread_yield() \
   81     thr_yield ()
   82 
   83 # ifdef __cplusplus
   84 }
   85 # endif
   86 
   87 #endif
   88 
   89 /* ========================================================================= */
   90 
   91 #if USE_WINDOWS_THREADS
   92 
   93 # define WIN32_LEAN_AND_MEAN  /* avoid including junk */
   94 # include <windows.h>
   95 
   96 # ifdef __cplusplus
   97 extern "C" {
   98 # endif
   99 
  100 # define gl_thread_yield() \
  101     Sleep (0)
  102 
  103 # ifdef __cplusplus
  104 }
  105 # endif
  106 
  107 #endif
  108 
  109 /* ========================================================================= */
  110 
  111 #if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WINDOWS_THREADS)
  112 
  113 /* Provide dummy implementation if threads are not supported.  */
  114 
  115 # define gl_thread_yield() 0
  116 
  117 #endif
  118 
  119 /* ========================================================================= */
  120 
  121 #endif /* _GLTHREAD_YIELD_H */