/usr/include/vigra/threading.hxx is in libvigraimpex-dev 1.10.0+git20160211.167be93+dfsg-5ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | /************************************************************************/
/* */
/* Copyright 2013-2014 by Ullrich Koethe */
/* */
/* This file is part of the VIGRA computer vision library. */
/* The VIGRA Website is */
/* http://hci.iwr.uni-heidelberg.de/vigra/ */
/* Please direct questions, bug reports, and contributions to */
/* ullrich.koethe@iwr.uni-heidelberg.de or */
/* vigra@informatik.uni-hamburg.de */
/* */
/* Permission is hereby granted, free of charge, to any person */
/* obtaining a copy of this software and associated documentation */
/* files (the "Software"), to deal in the Software without */
/* restriction, including without limitation the rights to use, */
/* copy, modify, merge, publish, distribute, sublicense, and/or */
/* sell copies of the Software, and to permit persons to whom the */
/* Software is furnished to do so, subject to the following */
/* conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the */
/* Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
/* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
/* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
/* OTHER DEALINGS IN THE SOFTWARE. */
/* */
/************************************************************************/
#ifndef VIGRA_THREADING_HXX
#define VIGRA_THREADING_HXX
/* Compatibility header to import threading-related functionality from boost
when the compiler doesn't yet support C++11.
*/
// ignore all threading if VIGRA_SINGLE_THREADED is defined
#ifndef VIGRA_SINGLE_THREADED
#ifndef VIGRA_NO_STD_THREADING
# if defined(__clang__)
# if (!__has_include(<thread>) || !__has_include(<mutex>) || !__has_include(<atomic>))
# define VIGRA_NO_STD_THREADING
# endif
# else
# if defined(__GNUC__) && (!defined(_GLIBCXX_HAS_GTHREADS) || !defined(_GLIBCXX_USE_C99_STDINT_TR1) || !defined(_GLIBCXX_USE_SCHED_YIELD))
# define VIGRA_NO_STD_THREADING
# endif
# endif
# if defined(_MSC_VER) && _MSC_VER <= 1600
# define VIGRA_NO_STD_THREADING
# endif
#endif
#ifdef USE_BOOST_THREAD
// Use the latest API version for Boost.Thread.
#define BOOST_THREAD_VERSION 4
# include <boost/thread.hpp>
# if BOOST_VERSION >= 105300
// At the moment, we only need the atomic headers, not the library.
# define BOOST_ATOMIC_NO_LIB 1
# include <boost/atomic.hpp>
# define VIGRA_HAS_ATOMIC 1
# endif
# define VIGRA_THREADING_NAMESPACE boost
#elif defined(VIGRA_NO_STD_THREADING)
# error "Your compiler does not support std::thread. If the boost libraries are available, consider running cmake with -DWITH_BOOST_THREAD=1"
#else
# include <condition_variable>
# include <future>
# include <thread>
# include <mutex>
// # include <shared_mutex> // C++14
# include <atomic>
# define VIGRA_HAS_ATOMIC 1
# define VIGRA_THREADING_NAMESPACE std
#endif
#if defined(_MSC_VER) && !defined(VIGRA_HAS_ATOMIC)
# include "windows.h"
#endif
namespace vigra { namespace threading {
// contents of <thread>
using VIGRA_THREADING_NAMESPACE::thread;
namespace this_thread {
using VIGRA_THREADING_NAMESPACE::this_thread::yield;
using VIGRA_THREADING_NAMESPACE::this_thread::get_id;
using VIGRA_THREADING_NAMESPACE::this_thread::sleep_for;
using VIGRA_THREADING_NAMESPACE::this_thread::sleep_until;
} // namespace this_thread
// contents of <mutex>
using VIGRA_THREADING_NAMESPACE::mutex;
using VIGRA_THREADING_NAMESPACE::recursive_mutex;
#ifdef __APPLE__
# ifdef __GNUC__
# ifdef USE_BOOST_THREAD
using VIGRA_THREADING_NAMESPACE::timed_mutex;
using VIGRA_THREADING_NAMESPACE::recursive_timed_mutex;
# endif
# else
using VIGRA_THREADING_NAMESPACE::timed_mutex;
using VIGRA_THREADING_NAMESPACE::recursive_timed_mutex;
# endif
#else
using VIGRA_THREADING_NAMESPACE::timed_mutex;
using VIGRA_THREADING_NAMESPACE::recursive_timed_mutex;
#endif
using VIGRA_THREADING_NAMESPACE::lock_guard;
using VIGRA_THREADING_NAMESPACE::unique_lock;
using VIGRA_THREADING_NAMESPACE::defer_lock_t;
using VIGRA_THREADING_NAMESPACE::try_to_lock_t;
using VIGRA_THREADING_NAMESPACE::adopt_lock_t;
using VIGRA_THREADING_NAMESPACE::defer_lock;
using VIGRA_THREADING_NAMESPACE::try_to_lock;
using VIGRA_THREADING_NAMESPACE::adopt_lock;
using VIGRA_THREADING_NAMESPACE::try_lock;
using VIGRA_THREADING_NAMESPACE::lock;
using VIGRA_THREADING_NAMESPACE::once_flag;
using VIGRA_THREADING_NAMESPACE::call_once;
// contents of <shared_mutex>
// using VIGRA_THREADING_NAMESPACE::shared_mutex; // C++14
// using VIGRA_THREADING_NAMESPACE::shared_lock; // C++14
// Futures.
using VIGRA_THREADING_NAMESPACE::future;
// Condition variables.
using VIGRA_THREADING_NAMESPACE::condition_variable;
// Packaged task.
using VIGRA_THREADING_NAMESPACE::packaged_task;
#ifdef VIGRA_HAS_ATOMIC
// contents of <atomic>
using VIGRA_THREADING_NAMESPACE::atomic_flag;
using VIGRA_THREADING_NAMESPACE::atomic;
using VIGRA_THREADING_NAMESPACE::atomic_char;
using VIGRA_THREADING_NAMESPACE::atomic_schar;
using VIGRA_THREADING_NAMESPACE::atomic_uchar;
using VIGRA_THREADING_NAMESPACE::atomic_short;
using VIGRA_THREADING_NAMESPACE::atomic_ushort;
using VIGRA_THREADING_NAMESPACE::atomic_int;
using VIGRA_THREADING_NAMESPACE::atomic_uint;
using VIGRA_THREADING_NAMESPACE::atomic_long;
using VIGRA_THREADING_NAMESPACE::atomic_ulong;
using VIGRA_THREADING_NAMESPACE::atomic_llong;
using VIGRA_THREADING_NAMESPACE::atomic_ullong;
// using VIGRA_THREADING_NAMESPACE::atomic_char16_t; // not in boost
// using VIGRA_THREADING_NAMESPACE::atomic_char32_t; // not in boost
using VIGRA_THREADING_NAMESPACE::atomic_wchar_t;
using VIGRA_THREADING_NAMESPACE::atomic_int_least8_t;
using VIGRA_THREADING_NAMESPACE::atomic_uint_least8_t;
using VIGRA_THREADING_NAMESPACE::atomic_int_least16_t;
using VIGRA_THREADING_NAMESPACE::atomic_uint_least16_t;
using VIGRA_THREADING_NAMESPACE::atomic_int_least32_t;
using VIGRA_THREADING_NAMESPACE::atomic_uint_least32_t;
using VIGRA_THREADING_NAMESPACE::atomic_int_least64_t;
using VIGRA_THREADING_NAMESPACE::atomic_uint_least64_t;
using VIGRA_THREADING_NAMESPACE::atomic_int_fast8_t;
using VIGRA_THREADING_NAMESPACE::atomic_uint_fast8_t;
using VIGRA_THREADING_NAMESPACE::atomic_int_fast16_t;
using VIGRA_THREADING_NAMESPACE::atomic_uint_fast16_t;
using VIGRA_THREADING_NAMESPACE::atomic_int_fast32_t;
using VIGRA_THREADING_NAMESPACE::atomic_uint_fast32_t;
using VIGRA_THREADING_NAMESPACE::atomic_int_fast64_t;
using VIGRA_THREADING_NAMESPACE::atomic_uint_fast64_t;
using VIGRA_THREADING_NAMESPACE::atomic_intptr_t;
using VIGRA_THREADING_NAMESPACE::atomic_uintptr_t;
using VIGRA_THREADING_NAMESPACE::atomic_size_t;
using VIGRA_THREADING_NAMESPACE::atomic_ptrdiff_t;
using VIGRA_THREADING_NAMESPACE::atomic_intmax_t;
using VIGRA_THREADING_NAMESPACE::atomic_uintmax_t;
using VIGRA_THREADING_NAMESPACE::memory_order;
using VIGRA_THREADING_NAMESPACE::memory_order_relaxed;
using VIGRA_THREADING_NAMESPACE::memory_order_release;
using VIGRA_THREADING_NAMESPACE::memory_order_acquire;
using VIGRA_THREADING_NAMESPACE::memory_order_consume;
using VIGRA_THREADING_NAMESPACE::memory_order_acq_rel;
using VIGRA_THREADING_NAMESPACE::memory_order_seq_cst;
using VIGRA_THREADING_NAMESPACE::atomic_thread_fence;
using VIGRA_THREADING_NAMESPACE::atomic_signal_fence;
// using VIGRA_THREADING_NAMESPACE::atomic_is_lock_free;
// using VIGRA_THREADING_NAMESPACE::atomic_storeatomic_store_explicit;
// using VIGRA_THREADING_NAMESPACE::atomic_loadatomic_load_explicit;
// using VIGRA_THREADING_NAMESPACE::atomic_exchangeatomic_exchange_explicit;
// using VIGRA_THREADING_NAMESPACE::atomic_compare_exchange_weak;
// using VIGRA_THREADING_NAMESPACE::atomic_compare_exchange_weak_explicit;
// using VIGRA_THREADING_NAMESPACE::atomic_compare_exchange_strong;
// using VIGRA_THREADING_NAMESPACE::atomic_compare_exchange_strong_explicit;
// using VIGRA_THREADING_NAMESPACE::atomic_fetch_addatomic_fetch_add_explicit;
// using VIGRA_THREADING_NAMESPACE::atomic_fetch_subatomic_fetch_sub_explicit;
// using VIGRA_THREADING_NAMESPACE::atomic_fetch_andatomic_fetch_and_explicit;
// using VIGRA_THREADING_NAMESPACE::atomic_fetch_oratomic_fetch_or_explicit;
// using VIGRA_THREADING_NAMESPACE::atomic_fetch_xoratomic_fetch_xor_explicit;
// using VIGRA_THREADING_NAMESPACE::atomic_flag_test_and_setatomic_flag_test_and_set_explicit;
// using VIGRA_THREADING_NAMESPACE::atomic_flag_clearatomic_flag_clear_explicit;
// using VIGRA_THREADING_NAMESPACE::atomic_init;
// using VIGRA_THREADING_NAMESPACE::kill_dependency;
#else // VIGRA_HAS_ATOMIC not defined
enum memory_order {
memory_order_relaxed,
memory_order_release,
memory_order_acquire,
memory_order_consume,
memory_order_acq_rel,
memory_order_seq_cst
};
#ifdef _MSC_VER
template <int SIZE=4>
struct atomic_long_impl
{
typedef LONG value_type;
static long load(value_type const & val)
{
long res = val;
MemoryBarrier();
return res;
}
static void store(value_type & dest, long val)
{
MemoryBarrier();
dest = val;
}
static long add(value_type & dest, long val)
{
return InterlockedExchangeAdd(&dest, val);
}
static long sub(value_type & dest, long val)
{
return InterlockedExchangeAdd(&dest, -val);
}
static bool compare_exchange(value_type & dest, long & old_val, long new_val)
{
long check_val = old_val;
old_val = InterlockedCompareExchange(&dest, new_val, old_val);
return check_val == old_val;
}
};
template <>
struct atomic_long_impl<8>
{
typedef LONGLONG value_type;
static long load(value_type const & val)
{
long res = val;
MemoryBarrier();
return res;
}
static void store(value_type & dest, long val)
{
MemoryBarrier();
dest = val;
}
static long add(value_type & dest, long val)
{
return InterlockedExchangeAdd64(&dest, val);
}
static long sub(value_type & dest, long val)
{
return InterlockedExchangeAdd64(&dest, -val);
}
static bool compare_exchange(value_type & dest, long & old_val, long new_val)
{
long check_val = old_val;
old_val = InterlockedCompareExchange64(&dest, new_val, old_val);
return check_val == old_val;
}
};
#else
template <int SIZE=4>
struct atomic_long_impl
{
typedef long value_type;
static long load(value_type const & val)
{
long res = val;
__sync_synchronize();
return res;
}
static void store(value_type & dest, long val)
{
__sync_synchronize();
dest = val;
}
static long add(value_type & dest, long val)
{
return __sync_fetch_and_add(&dest, val);
}
static long sub(value_type & dest, long val)
{
return __sync_fetch_and_sub(&dest, val);
}
static bool compare_exchange(value_type & dest, long & old_val, long new_val)
{
long check_val = old_val;
old_val = __sync_val_compare_and_swap(&dest, old_val, new_val);
return check_val == old_val;
}
};
#endif // _MSC_VER
struct atomic_long
{
typedef atomic_long_impl<sizeof(long)>::value_type value_type;
atomic_long(long v = 0)
: value_(v)
{}
atomic_long & operator=(long val)
{
store(val);
return *this;
}
bool operator==(long val) const
{
return load() == val;
}
void operator++()
{
fetch_add(1);
}
void operator--()
{
fetch_sub(1);
}
long load(memory_order = memory_order_seq_cst) const
{
return atomic_long_impl<sizeof(long)>::load(value_);
}
void store(long v, memory_order = memory_order_seq_cst)
{
atomic_long_impl<sizeof(long)>::store(value_, v);
}
long fetch_add(long v, memory_order = memory_order_seq_cst)
{
return atomic_long_impl<sizeof(long)>::add(value_, v);
}
long fetch_sub(long v, memory_order = memory_order_seq_cst)
{
return atomic_long_impl<sizeof(long)>::sub(value_, v);
}
bool compare_exchange_strong(long & old_val, long new_val, memory_order = memory_order_seq_cst)
{
return atomic_long_impl<sizeof(long)>::compare_exchange(value_, old_val, new_val);
}
bool compare_exchange_weak(long & old_val, long new_val, memory_order = memory_order_seq_cst)
{
return atomic_long_impl<sizeof(long)>::compare_exchange(value_, old_val, new_val);
}
value_type value_;
};
#endif // VIGRA_HAS_ATOMIC
}} // namespace vigra::threading
#undef VIGRA_THREADING_NAMESPACE
#endif // not VIGRA_SINGLE_THREADED
#endif // VIGRA_THREADING_HXX
|