Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
pthread_stubs.h106 linesDownload Raw Back to cpython
1#ifndef Py_CPYTHON_PTRHEAD_STUBS_H2#define Py_CPYTHON_PTRHEAD_STUBS_H3 4#if !defined(HAVE_PTHREAD_STUBS)5#  error "this header file requires stubbed pthreads."6#endif7 8#ifndef _POSIX_THREADS9#  define _POSIX_THREADS 110#endif11 12/* Minimal pthread stubs for CPython.13 *14 * The stubs implement the minimum pthread API for CPython.15 * - pthread_create() fails.16 * - pthread_exit() calls exit(0).17 * - pthread_key_*() functions implement minimal TSS without destructor.18 * - all other functions do nothing and return 0.19 */20 21#ifdef __wasi__22// WASI's bits/alltypes.h provides type definitions when __NEED_ is set.23// The header file can be included multiple times.24//25// <sys/types.h> may also define these macros.26#  ifndef __NEED_pthread_cond_t27#    define __NEED_pthread_cond_t 128#  endif29#  ifndef __NEED_pthread_condattr_t30#    define __NEED_pthread_condattr_t 131#  endif32#  ifndef __NEED_pthread_mutex_t33#    define __NEED_pthread_mutex_t 134#  endif35#  ifndef __NEED_pthread_mutexattr_t36#    define __NEED_pthread_mutexattr_t 137#  endif38#  ifndef __NEED_pthread_key_t39#    define __NEED_pthread_key_t 140#  endif41#  ifndef __NEED_pthread_t42#    define __NEED_pthread_t 143#  endif44#  ifndef __NEED_pthread_attr_t45#    define __NEED_pthread_attr_t 146#  endif47#  include <bits/alltypes.h>48#else49typedef struct { void *__x; } pthread_cond_t;50typedef struct { unsigned __attr; } pthread_condattr_t;51typedef struct { void *__x; } pthread_mutex_t;52typedef struct { unsigned __attr; } pthread_mutexattr_t;53typedef unsigned pthread_key_t;54typedef unsigned pthread_t;55typedef struct { unsigned __attr; } pthread_attr_t;56#endif57 58// mutex59PyAPI_FUNC(int) pthread_mutex_init(pthread_mutex_t *restrict mutex,60                                   const pthread_mutexattr_t *restrict attr);61PyAPI_FUNC(int) pthread_mutex_destroy(pthread_mutex_t *mutex);62PyAPI_FUNC(int) pthread_mutex_trylock(pthread_mutex_t *mutex);63PyAPI_FUNC(int) pthread_mutex_lock(pthread_mutex_t *mutex);64PyAPI_FUNC(int) pthread_mutex_unlock(pthread_mutex_t *mutex);65 66// condition67PyAPI_FUNC(int) pthread_cond_init(pthread_cond_t *restrict cond,68                                  const pthread_condattr_t *restrict attr);69PyAPI_FUNC(int) pthread_cond_destroy(pthread_cond_t *cond);70PyAPI_FUNC(int) pthread_cond_wait(pthread_cond_t *restrict cond,71                                  pthread_mutex_t *restrict mutex);72PyAPI_FUNC(int) pthread_cond_timedwait(pthread_cond_t *restrict cond,73                                       pthread_mutex_t *restrict mutex,74                                       const struct timespec *restrict abstime);75PyAPI_FUNC(int) pthread_cond_signal(pthread_cond_t *cond);76PyAPI_FUNC(int) pthread_condattr_init(pthread_condattr_t *attr);77PyAPI_FUNC(int) pthread_condattr_setclock(78    pthread_condattr_t *attr, clockid_t clock_id);79 80// pthread81PyAPI_FUNC(int) pthread_create(pthread_t *restrict thread,82                               const pthread_attr_t *restrict attr,83                               void *(*start_routine)(void *),84                               void *restrict arg);85PyAPI_FUNC(int) pthread_detach(pthread_t thread);86PyAPI_FUNC(int) pthread_join(pthread_t thread, void** value_ptr);87PyAPI_FUNC(pthread_t) pthread_self(void);88PyAPI_FUNC(int) pthread_exit(void *retval) __attribute__ ((__noreturn__));89PyAPI_FUNC(int) pthread_attr_init(pthread_attr_t *attr);90PyAPI_FUNC(int) pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);91PyAPI_FUNC(int) pthread_attr_destroy(pthread_attr_t *attr);92 93 94// pthread_key95#ifndef PTHREAD_KEYS_MAX96#  define PTHREAD_KEYS_MAX 12897#endif98 99PyAPI_FUNC(int) pthread_key_create(pthread_key_t *key,100                                   void (*destr_function)(void *));101PyAPI_FUNC(int) pthread_key_delete(pthread_key_t key);102PyAPI_FUNC(void *) pthread_getspecific(pthread_key_t key);103PyAPI_FUNC(int) pthread_setspecific(pthread_key_t key, const void *value);104 105#endif // Py_CPYTHON_PTRHEAD_STUBS_H106 
codekingpro/portable-devtools · Team Ai