1af69d88dSmrg/* 2af69d88dSmrg * C11 <threads.h> emulation library 3af69d88dSmrg * 4af69d88dSmrg * (C) Copyright yohhoy 2012. 5af69d88dSmrg * Distributed under the Boost Software License, Version 1.0. 6af69d88dSmrg * 7af69d88dSmrg * Permission is hereby granted, free of charge, to any person or organization 8af69d88dSmrg * obtaining a copy of the software and accompanying documentation covered by 9af69d88dSmrg * this license (the "Software") to use, reproduce, display, distribute, 10af69d88dSmrg * execute, and transmit the Software, and to prepare [[derivative work]]s of the 11af69d88dSmrg * Software, and to permit third-parties to whom the Software is furnished to 12af69d88dSmrg * do so, all subject to the following: 13af69d88dSmrg * 14af69d88dSmrg * The copyright notices in the Software and this entire statement, including 15af69d88dSmrg * the above license grant, this restriction and the following disclaimer, 16af69d88dSmrg * must be included in all copies of the Software, in whole or in part, and 17af69d88dSmrg * all derivative works of the Software, unless such copies or derivative 18af69d88dSmrg * works are solely in the form of machine-executable object code generated by 19af69d88dSmrg * a source language processor. 20af69d88dSmrg * 21af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22af69d88dSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23af69d88dSmrg * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24af69d88dSmrg * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25af69d88dSmrg * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27af69d88dSmrg * DEALINGS IN THE SOFTWARE. 28af69d88dSmrg */ 29af69d88dSmrg#ifndef EMULATED_THREADS_H_INCLUDED_ 30af69d88dSmrg#define EMULATED_THREADS_H_INCLUDED_ 31af69d88dSmrg 32af69d88dSmrg#include <time.h> 33af69d88dSmrg 34af69d88dSmrg#ifndef TIME_UTC 35af69d88dSmrg#define TIME_UTC 1 36af69d88dSmrg#endif 37af69d88dSmrg 38af69d88dSmrg#include "c99_compat.h" /* for `inline` */ 39af69d88dSmrg 40af69d88dSmrg/*---------------------------- types ----------------------------*/ 41af69d88dSmrgtypedef void (*tss_dtor_t)(void*); 42af69d88dSmrgtypedef int (*thrd_start_t)(void*); 43af69d88dSmrg 44af69d88dSmrg 45af69d88dSmrg/*-------------------- enumeration constants --------------------*/ 46af69d88dSmrgenum { 47af69d88dSmrg mtx_plain = 0, 48af69d88dSmrg mtx_try = 1, 49af69d88dSmrg mtx_timed = 2, 50af69d88dSmrg mtx_recursive = 4 51af69d88dSmrg}; 52af69d88dSmrg 53af69d88dSmrgenum { 54af69d88dSmrg thrd_success = 0, // succeeded 55af69d88dSmrg thrd_timeout, // timeout 56af69d88dSmrg thrd_error, // failed 57af69d88dSmrg thrd_busy, // resource busy 58af69d88dSmrg thrd_nomem // out of memory 59af69d88dSmrg}; 60af69d88dSmrg 61af69d88dSmrg/*-------------------------- functions --------------------------*/ 62af69d88dSmrg 63af69d88dSmrg#if defined(_WIN32) && !defined(__CYGWIN__) 64af69d88dSmrg#include "threads_win32.h" 65af69d88dSmrg#elif defined(HAVE_PTHREAD) 66af69d88dSmrg#include "threads_posix.h" 67af69d88dSmrg#else 68af69d88dSmrg#error Not supported on this platform. 69af69d88dSmrg#endif 70af69d88dSmrg 71af69d88dSmrg 72af69d88dSmrg 73af69d88dSmrg#endif /* EMULATED_THREADS_H_INCLUDED_ */ 74