Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
linux_common.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2018 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16 
17 
18 
19 */
20 
21 #ifndef __TBB_machine_H
22 #error Do not #include this internal file directly; use public TBB headers instead.
23 #endif
24 
25 #include <sched.h>
26 #define __TBB_Yield() sched_yield()
27 
28 #include <unistd.h>
29 /* Futex definitions */
30 #include <sys/syscall.h>
31 
32 #if defined(SYS_futex)
33 
34 #define __TBB_USE_FUTEX 1
35 #include <limits.h>
36 #include <errno.h>
37 // Unfortunately, some versions of Linux do not have a header that defines FUTEX_WAIT and FUTEX_WAKE.
38 
39 #ifdef FUTEX_WAIT
40 #define __TBB_FUTEX_WAIT FUTEX_WAIT
41 #else
42 #define __TBB_FUTEX_WAIT 0
43 #endif
44 
45 #ifdef FUTEX_WAKE
46 #define __TBB_FUTEX_WAKE FUTEX_WAKE
47 #else
48 #define __TBB_FUTEX_WAKE 1
49 #endif
50 
51 #ifndef __TBB_ASSERT
52 #error machine specific headers must be included after tbb_stddef.h
53 #endif
54 
55 namespace tbb {
56 
57 namespace internal {
58 
59 inline int futex_wait( void *futex, int comparand ) {
60  int r = syscall( SYS_futex,futex,__TBB_FUTEX_WAIT,comparand,NULL,NULL,0 );
61 #if TBB_USE_ASSERT
62  int e = errno;
63  __TBB_ASSERT( r==0||r==EWOULDBLOCK||(r==-1&&(e==EAGAIN||e==EINTR)), "futex_wait failed." );
64 #endif /* TBB_USE_ASSERT */
65  return r;
66 }
67 
68 inline int futex_wakeup_one( void *futex ) {
69  int r = ::syscall( SYS_futex,futex,__TBB_FUTEX_WAKE,1,NULL,NULL,0 );
70  __TBB_ASSERT( r==0||r==1, "futex_wakeup_one: more than one thread woken up?" );
71  return r;
72 }
73 
74 inline int futex_wakeup_all( void *futex ) {
75  int r = ::syscall( SYS_futex,futex,__TBB_FUTEX_WAKE,INT_MAX,NULL,NULL,0 );
76  __TBB_ASSERT( r>=0, "futex_wakeup_all: error in waking up threads" );
77  return r;
78 }
79 
80 } /* namespace internal */
81 
82 } /* namespace tbb */
83 
84 #endif /* SYS_futex */
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
The graph class.

Copyright © 2005-2018 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.