Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-19 09:50:41

0001 #ifndef Py_CPYTHON_PTRHEAD_STUBS_H
0002 #define Py_CPYTHON_PTRHEAD_STUBS_H
0003 
0004 #if !defined(HAVE_PTHREAD_STUBS)
0005 #  error "this header file requires stubbed pthreads."
0006 #endif
0007 
0008 #ifndef _POSIX_THREADS
0009 #  define _POSIX_THREADS 1
0010 #endif
0011 
0012 /* Minimal pthread stubs for CPython.
0013  *
0014  * The stubs implement the minimum pthread API for CPython.
0015  * - pthread_create() fails.
0016  * - pthread_exit() calls exit(0).
0017  * - pthread_key_*() functions implement minimal TSS without destructor.
0018  * - all other functions do nothing and return 0.
0019  */
0020 
0021 #ifdef __wasi__
0022 // WASI's bits/alltypes.h provides type definitions when __NEED_ is set.
0023 // The header file can be included multiple times.
0024 //
0025 // <sys/types.h> may also define these macros.
0026 #  ifndef __NEED_pthread_cond_t
0027 #    define __NEED_pthread_cond_t 1
0028 #  endif
0029 #  ifndef __NEED_pthread_condattr_t
0030 #    define __NEED_pthread_condattr_t 1
0031 #  endif
0032 #  ifndef __NEED_pthread_mutex_t
0033 #    define __NEED_pthread_mutex_t 1
0034 #  endif
0035 #  ifndef __NEED_pthread_mutexattr_t
0036 #    define __NEED_pthread_mutexattr_t 1
0037 #  endif
0038 #  ifndef __NEED_pthread_key_t
0039 #    define __NEED_pthread_key_t 1
0040 #  endif
0041 #  ifndef __NEED_pthread_t
0042 #    define __NEED_pthread_t 1
0043 #  endif
0044 #  ifndef __NEED_pthread_attr_t
0045 #    define __NEED_pthread_attr_t 1
0046 #  endif
0047 #  include <bits/alltypes.h>
0048 #else
0049 typedef struct { void *__x; } pthread_cond_t;
0050 typedef struct { unsigned __attr; } pthread_condattr_t;
0051 typedef struct { void *__x; } pthread_mutex_t;
0052 typedef struct { unsigned __attr; } pthread_mutexattr_t;
0053 typedef unsigned pthread_key_t;
0054 typedef unsigned pthread_t;
0055 typedef struct { unsigned __attr; } pthread_attr_t;
0056 #endif
0057 
0058 // mutex
0059 PyAPI_FUNC(int) pthread_mutex_init(pthread_mutex_t *restrict mutex,
0060                                    const pthread_mutexattr_t *restrict attr);
0061 PyAPI_FUNC(int) pthread_mutex_destroy(pthread_mutex_t *mutex);
0062 PyAPI_FUNC(int) pthread_mutex_trylock(pthread_mutex_t *mutex);
0063 PyAPI_FUNC(int) pthread_mutex_lock(pthread_mutex_t *mutex);
0064 PyAPI_FUNC(int) pthread_mutex_unlock(pthread_mutex_t *mutex);
0065 
0066 // condition
0067 PyAPI_FUNC(int) pthread_cond_init(pthread_cond_t *restrict cond,
0068                                   const pthread_condattr_t *restrict attr);
0069 PyAPI_FUNC(int) pthread_cond_destroy(pthread_cond_t *cond);
0070 PyAPI_FUNC(int) pthread_cond_wait(pthread_cond_t *restrict cond,
0071                                   pthread_mutex_t *restrict mutex);
0072 PyAPI_FUNC(int) pthread_cond_timedwait(pthread_cond_t *restrict cond,
0073                                        pthread_mutex_t *restrict mutex,
0074                                        const struct timespec *restrict abstime);
0075 PyAPI_FUNC(int) pthread_cond_signal(pthread_cond_t *cond);
0076 PyAPI_FUNC(int) pthread_condattr_init(pthread_condattr_t *attr);
0077 PyAPI_FUNC(int) pthread_condattr_setclock(
0078     pthread_condattr_t *attr, clockid_t clock_id);
0079 
0080 // pthread
0081 PyAPI_FUNC(int) pthread_create(pthread_t *restrict thread,
0082                                const pthread_attr_t *restrict attr,
0083                                void *(*start_routine)(void *),
0084                                void *restrict arg);
0085 PyAPI_FUNC(int) pthread_detach(pthread_t thread);
0086 PyAPI_FUNC(int) pthread_join(pthread_t thread, void** value_ptr);
0087 PyAPI_FUNC(pthread_t) pthread_self(void);
0088 PyAPI_FUNC(int) pthread_exit(void *retval) __attribute__ ((__noreturn__));
0089 PyAPI_FUNC(int) pthread_attr_init(pthread_attr_t *attr);
0090 PyAPI_FUNC(int) pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
0091 PyAPI_FUNC(int) pthread_attr_destroy(pthread_attr_t *attr);
0092 
0093 
0094 // pthread_key
0095 #ifndef PTHREAD_KEYS_MAX
0096 #  define PTHREAD_KEYS_MAX 128
0097 #endif
0098 
0099 PyAPI_FUNC(int) pthread_key_create(pthread_key_t *key,
0100                                    void (*destr_function)(void *));
0101 PyAPI_FUNC(int) pthread_key_delete(pthread_key_t key);
0102 PyAPI_FUNC(void *) pthread_getspecific(pthread_key_t key);
0103 PyAPI_FUNC(int) pthread_setspecific(pthread_key_t key, const void *value);
0104 
0105 #endif // Py_CPYTHON_PTRHEAD_STUBS_H