📄 pthread.h
字号:
size_t *__restrict __stacksize) __THROW __nonnull ((1, 2, 3));/* The following two interfaces are intended to replace the last two. They require setting the address as well as the size since only setting the address will make the implementation on some architectures impossible. */extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr, size_t __stacksize) __THROW __nonnull ((1));#endif#ifdef __USE_GNU/* Thread created with attribute ATTR will be limited to run only on the processors represented in CPUSET. */extern int pthread_attr_setaffinity_np (pthread_attr_t *__attr, size_t __cpusetsize, __const cpu_set_t *__cpuset) __THROW __nonnull ((1, 3));/* Get bit set in CPUSET representing the processors threads created with ATTR can run on. */extern int pthread_attr_getaffinity_np (__const pthread_attr_t *__attr, size_t __cpusetsize, cpu_set_t *__cpuset) __THROW __nonnull ((1, 3));/* Initialize thread attribute *ATTR with attributes corresponding to the already running thread TH. It shall be called on uninitialized ATTR and destroyed with pthread_attr_destroy when no longer needed. */extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr) __THROW __nonnull ((2));#endif/* Functions for scheduling control. *//* Set the scheduling parameters for TARGET_THREAD according to POLICY and *PARAM. */extern int pthread_setschedparam (pthread_t __target_thread, int __policy, __const struct sched_param *__param) __THROW __nonnull ((3));/* Return in *POLICY and *PARAM the scheduling parameters for TARGET_THREAD. */extern int pthread_getschedparam (pthread_t __target_thread, int *__restrict __policy, struct sched_param *__restrict __param) __THROW __nonnull ((2, 3));/* Set the scheduling priority for TARGET_THREAD. */extern int pthread_setschedprio (pthread_t __target_thread, int __prio) __THROW;#ifdef __USE_UNIX98/* Determine level of concurrency. */extern int pthread_getconcurrency (void) __THROW;/* Set new concurrency level to LEVEL. */extern int pthread_setconcurrency (int __level) __THROW;#endif#ifdef __USE_GNU/* Yield the processor to another thread or process. This function is similar to the POSIX `sched_yield' function but might be differently implemented in the case of a m-on-n thread implementation. */extern int pthread_yield (void) __THROW;/* Limit specified thread TH to run only on the processors represented in CPUSET. */extern int pthread_setaffinity_np (pthread_t __th, size_t __cpusetsize, __const cpu_set_t *__cpuset) __THROW __nonnull ((3));/* Get bit set in CPUSET representing the processors TH can run on. */extern int pthread_getaffinity_np (pthread_t __th, size_t __cpusetsize, cpu_set_t *__cpuset) __THROW __nonnull ((3));#endif/* Functions for handling initialization. *//* Guarantee that the initialization function INIT_ROUTINE will be called only once, even if pthread_once is executed several times with the same ONCE_CONTROL argument. ONCE_CONTROL must point to a static or extern variable initialized to PTHREAD_ONCE_INIT. The initialization functions might throw exception which is why this function is not marked with __THROW. */extern int pthread_once (pthread_once_t *__once_control, void (*__init_routine) (void)) __nonnull ((1, 2));/* Functions for handling cancellation. Note that these functions are explicitly not marked to not throw an exception in C++ code. If cancellation is implemented by unwinding this is necessary to have the compiler generate the unwind information. *//* Set cancelability state of current thread to STATE, returning old state in *OLDSTATE if OLDSTATE is not NULL. */extern int pthread_setcancelstate (int __state, int *__oldstate);/* Set cancellation state of current thread to TYPE, returning the old type in *OLDTYPE if OLDTYPE is not NULL. */extern int pthread_setcanceltype (int __type, int *__oldtype);/* Cancel THREAD immediately or at the next possibility. */extern int pthread_cancel (pthread_t __th);/* Test for pending cancellation for the current thread and terminate the thread as per pthread_exit(PTHREAD_CANCELED) if it has been cancelled. */extern void pthread_testcancel (void);/* Cancellation handling with integration into exception handling. */typedef struct{ struct { __jmp_buf __cancel_jmp_buf; int __mask_was_saved; } __cancel_jmp_buf[1]; void *__pad[4];} __pthread_unwind_buf_t __attribute__ ((__aligned__));/* No special attributes by default. */#ifndef __cleanup_fct_attribute# define __cleanup_fct_attribute#endif/* Structure to hold the cleanup handler information. */struct __pthread_cleanup_frame{ void (*__cancel_routine) (void *); void *__cancel_arg; int __do_it; int __cancel_type;};#if defined __GNUC__ && defined __EXCEPTIONS# ifdef __cplusplus/* Class to handle cancellation handler invocation. */class __pthread_cleanup_class{ void (*__cancel_routine) (void *); void *__cancel_arg; int __do_it; int __cancel_type; public: __pthread_cleanup_class (void (*__fct) (void *), void *__arg) : __cancel_routine (__fct), __cancel_arg (__arg), __do_it (1) { } ~__pthread_cleanup_class () { if (__do_it) __cancel_routine (__cancel_arg); } void __setdoit (int __newval) { __do_it = __newval; } void __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, &__cancel_type); } void __restore () const { pthread_setcanceltype (__cancel_type, 0); }};/* Install a cleanup handler: ROUTINE will be called with arguments ARG when the thread is canceled or calls pthread_exit. ROUTINE will also be called with arguments ARG when the matching pthread_cleanup_pop is executed with non-zero EXECUTE argument. pthread_cleanup_push and pthread_cleanup_pop are macros and must always be used in matching pairs at the same nesting level of braces. */# define pthread_cleanup_push(routine, arg) \ do { \ __pthread_cleanup_class __clframe (routine, arg)/* Remove a cleanup handler installed by the matching pthread_cleanup_push. If EXECUTE is non-zero, the handler function is called. */# define pthread_cleanup_pop(execute) \ __clframe.__setdoit (execute); \ } while (0)# ifdef __USE_GNU/* Install a cleanup handler as pthread_cleanup_push does, but also saves the current cancellation type and sets it to deferred cancellation. */# define pthread_cleanup_push_defer_np(routine, arg) \ do { \ __pthread_cleanup_class __clframe (routine, arg); \ __clframe.__defer ()/* Remove a cleanup handler as pthread_cleanup_pop does, but also restores the cancellation type that was in effect when the matching pthread_cleanup_push_defer was called. */# define pthread_cleanup_pop_restore_np(execute) \ __clframe.__restore (); \ __clframe.__setdoit (execute); \ } while (0)# endif# else/* Function called to call the cleanup handler. As an extern inline function the compiler is free to decide inlining the change when needed or fall back on the copy which must exist somewhere else. */__extern_inline void__pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame){ if (__frame->__do_it) __frame->__cancel_routine (__frame->__cancel_arg);}/* Install a cleanup handler: ROUTINE will be called with arguments ARG when the thread is canceled or calls pthread_exit. ROUTINE will also be called with arguments ARG when the matching pthread_cleanup_pop is executed with non-zero EXECUTE argument. pthread_cleanup_push and pthread_cleanup_pop are macros and must always be used in matching pairs at the same nesting level of braces. */# define pthread_cleanup_push(routine, arg) \ do { \ struct __pthread_cleanup_frame __clframe \ __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \ = { .__cancel_routine = (routine), .__cancel_arg = (arg), \ .__do_it = 1 };/* Remove a cleanup handler installed by the matching pthread_cleanup_push. If EXECUTE is non-zero, the handler function is called. */# define pthread_cleanup_pop(execute) \ __clframe.__do_it = (execute); \ } while (0)# ifdef __USE_GNU/* Install a cleanup handler as pthread_cleanup_push does, but also saves the current cancellation type and sets it to deferred cancellation. */# define pthread_cleanup_push_defer_np(routine, arg) \ do { \ struct __pthread_cleanup_frame __clframe \ __attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \ = { .__cancel_routine = (routine), .__cancel_arg = (arg), \ .__do_it = 1 }; \ (void) pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, \ &__clframe.__cancel_type)/* Remove a cleanup handler as pthread_cleanup_pop does, but also restores the cancellation type that was in effect when the matching pthread_cleanup_push_defer was called. */# define pthread_cleanup_pop_restore_np(execute) \ (void) pthread_setcanceltype (__clframe.__cancel_type, NULL); \ __clframe.__do_it = (execute); \ } while (0)# endif# endif#else/* Install a cleanup handler: ROUTINE will be called with arguments ARG when the thread is canceled or calls pthread_exit. ROUTINE will also be called with arguments ARG when the matching pthread_cleanup_pop is executed with non-zero EXECUTE argument. pthread_cleanup_push and pthread_cleanup_pop are macros and must always be used in matching pairs at the same nesting level of braces. */# define pthread_cleanup_push(routine, arg) \ do { \ __pthread_unwind_buf_t __cancel_buf; \ void (*__cancel_routine) (void *) = (routine); \ void *__cancel_arg = (arg); \ int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ __cancel_buf.__cancel_jmp_buf, 0); \ if (__builtin_expect (not_first_call, 0)) \ { \ __cancel_routine (__cancel_arg); \ __pthread_unwind_next (&__cancel_buf); \ /* NOTREACHED */ \ } \ \ __pthread_register_cancel (&__cancel_buf); \ do {extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf) __cleanup_fct_attribute;/* Remove a cleanup handler installed by the matching pthread_cleanup_push. If EXECUTE is non-zero, the handler function is called. */# define pthread_cleanup_pop(execute) \ do; while (0); /* Empty to allow label before pthread_cleanup_pop. */ \ } while (0); \ __pthread_unregister_cancel (&__cancel_buf); \ if (execute) \ __cancel_routine (__cancel_arg); \ } while (0)extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf) __cleanup_fct_attribute;# ifdef __USE_GNU/* Install a cleanup handler as pthread_cleanup_push does, but also saves the current cancellation type and sets it to deferred cancellation. */# define pthread_cleanup_push_defer_np(routine, arg) \ do { \ __pthread_unwind_buf_t __cancel_buf; \ void (*__cancel_routine) (void *) = (routine); \ void *__cancel_arg = (arg); \ int not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ __cancel_buf.__cancel_jmp_buf, 0); \ if (__builtin_expect (not_first_call, 0)) \ { \ __cancel_routine (__cancel_arg); \ __pthread_unwind_next (&__cancel_buf); \ /* NOTREACHED */ \ } \ \ __pthread_register_cancel_defer (&__cancel_buf); \ do {extern void __pthread_register_cancel_defer (__pthread_unwind_buf_t *__buf) __cleanup_fct_attribute;/* Remove a cleanup handler as pthread_cleanup_pop does, but also restores the cancellation type that was in effect when the matching pthread_cleanup_push_defer was called. */# define pthread_cleanup_pop_restore_np(execute) \ do; while (0); /* Empty to allow label before pthread_cleanup_pop. */ \ } while (0); \ __pthread_unregister_cancel_restore (&__cancel_buf); \ if (execute) \ __cancel_routine (__cancel_arg); \ } while (0)extern void __pthread_unregister_cancel_restore (__pthread_unwind_buf_t *__buf) __cleanup_fct_attribute;# endif/* Internal interface to initiate cleanup. */extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf) __cleanup_fct_attribute __attribute__ ((__noreturn__))# ifndef SHARED __attribute__ ((__weak__))# endif ;#endif/* Function used in the macros. */struct __jmp_buf_tag;extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROW;/* Mutex handling. *//* Initialize a mutex. */extern int pthread_mutex_init (pthread_mutex_t *__mutex, __const pthread_mutexattr_t *__mutexattr) __THROW __nonnull ((1));/* Destroy a mutex. */extern int pthread_mutex_destroy (pthread_mutex_t *__mutex) __THROW __nonnull ((1));/* Try locking a mutex. */extern int pthread_mutex_trylock (pthread_mutex_t *__mutex) __THROW __nonnull ((1));/* Lock a mutex. */extern int pthread_mutex_lock (pthread_mutex_t *__mutex) __THROW __nonnull ((1));#ifdef __USE_XOPEN2K/* Wait until lock becomes available, or specified time passes. */extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex, __const struct timespec *__restrict __abstime) __THROW __nonnull ((1, 2));#endif/* Unlock a mutex. */extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) __THROW __nonnull ((1));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -