Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:18:04

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 #  define __NEED_pthread_cond_t 1
0025 #  define __NEED_pthread_condattr_t 1
0026 #  define __NEED_pthread_mutex_t 1
0027 #  define __NEED_pthread_mutexattr_t 1
0028 #  define __NEED_pthread_key_t 1
0029 #  define __NEED_pthread_t 1
0030 #  define __NEED_pthread_attr_t 1
0031 #  include <bits/alltypes.h>
0032 #else
0033 typedef struct { void *__x; } pthread_cond_t;
0034 typedef struct { unsigned __attr; } pthread_condattr_t;
0035 typedef struct { void *__x; } pthread_mutex_t;
0036 typedef struct { unsigned __attr; } pthread_mutexattr_t;
0037 typedef unsigned pthread_key_t;
0038 typedef unsigned pthread_t;
0039 typedef struct { unsigned __attr; } pthread_attr_t;
0040 #endif
0041 
0042 // mutex
0043 PyAPI_FUNC(int) pthread_mutex_init(pthread_mutex_t *restrict mutex,
0044                                    const pthread_mutexattr_t *restrict attr);
0045 PyAPI_FUNC(int) pthread_mutex_destroy(pthread_mutex_t *mutex);
0046 PyAPI_FUNC(int) pthread_mutex_trylock(pthread_mutex_t *mutex);
0047 PyAPI_FUNC(int) pthread_mutex_lock(pthread_mutex_t *mutex);
0048 PyAPI_FUNC(int) pthread_mutex_unlock(pthread_mutex_t *mutex);
0049 
0050 // condition
0051 PyAPI_FUNC(int) pthread_cond_init(pthread_cond_t *restrict cond,
0052                                   const pthread_condattr_t *restrict attr);
0053 PyAPI_FUNC(int) pthread_cond_destroy(pthread_cond_t *cond);
0054 PyAPI_FUNC(int) pthread_cond_wait(pthread_cond_t *restrict cond,
0055                                   pthread_mutex_t *restrict mutex);
0056 PyAPI_FUNC(int) pthread_cond_timedwait(pthread_cond_t *restrict cond,
0057                                        pthread_mutex_t *restrict mutex,
0058                                        const struct timespec *restrict abstime);
0059 PyAPI_FUNC(int) pthread_cond_signal(pthread_cond_t *cond);
0060 PyAPI_FUNC(int) pthread_condattr_init(pthread_condattr_t *attr);
0061 PyAPI_FUNC(int) pthread_condattr_setclock(
0062     pthread_condattr_t *attr, clockid_t clock_id);
0063 
0064 // pthread
0065 PyAPI_FUNC(int) pthread_create(pthread_t *restrict thread,
0066                                const pthread_attr_t *restrict attr,
0067                                void *(*start_routine)(void *),
0068                                void *restrict arg);
0069 PyAPI_FUNC(int) pthread_detach(pthread_t thread);
0070 PyAPI_FUNC(pthread_t) pthread_self(void);
0071 PyAPI_FUNC(int) pthread_exit(void *retval) __attribute__ ((__noreturn__));
0072 PyAPI_FUNC(int) pthread_attr_init(pthread_attr_t *attr);
0073 PyAPI_FUNC(int) pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
0074 PyAPI_FUNC(int) pthread_attr_destroy(pthread_attr_t *attr);
0075 
0076 
0077 // pthread_key
0078 #ifndef PTHREAD_KEYS_MAX
0079 #  define PTHREAD_KEYS_MAX 128
0080 #endif
0081 
0082 PyAPI_FUNC(int) pthread_key_create(pthread_key_t *key,
0083                                    void (*destr_function)(void *));
0084 PyAPI_FUNC(int) pthread_key_delete(pthread_key_t key);
0085 PyAPI_FUNC(void *) pthread_getspecific(pthread_key_t key);
0086 PyAPI_FUNC(int) pthread_setspecific(pthread_key_t key, const void *value);
0087 
0088 #endif // Py_CPYTHON_PTRHEAD_STUBS_H