⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pthread.h

📁 linux 下的线程库源码
💻 H
📖 第 1 页 / 共 2 页
字号:
/* Linuxthreads - a simple clone()-based implementation of Posix        *//* threads for Linux.                                                   *//* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr)              *//*                                                                      *//* This program is free software; you can redistribute it and/or        *//* modify it under the terms of the GNU Library General Public License  *//* as published by the Free Software Foundation; either version 2       *//* of the License, or (at your option) any later version.               *//*                                                                      *//* This program is distributed in the hope that it will be useful,      *//* but WITHOUT ANY WARRANTY; without even the implied warranty of       *//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *//* GNU Library General Public License for more details.                 */#ifndef _PTHREAD_H#define _PTHREAD_H      1#include <features.h>#define __need_sigset_t#include <signal.h>#define __need_timespec#include <time.h>#ifdef __BUILDING_LINUXTHREADS#include <linux/sched.h>#else#include <sched.h>#endif#ifndef _REENTRANT#define _REENTRANT#endif#include <errno.h>/*** Feature test macros */#ifndef _POSIX_THREADS#define _POSIX_THREADS#endif#ifndef _POSIX_THREAD_PRIORITY_SCHEDULING#define _POSIX_THREAD_PRIORITY_SCHEDULING#endif/*** Limits (should be in limits.h) *//* Max number of simultaneously running threads. */#define _POSIX_THREAD_THREADS_MAX 64/* This is the value this implementation supports. */#define PTHREAD_THREADS_MAX     1024/* Max number of keys for thread-specific data */#define _POSIX_THREAD_KEYS_MAX  128/* This is the value this implementation supports.  */#define PTHREAD_KEYS_MAX        1024/* Max number of iterations of destructors for thread-specific data.  */#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4/* Number of iterations this implementation does.  */#define PTHREAD_DESTRUCTOR_ITERATIONS       4/*** Types ***//* Thread identifiers */typedef unsigned long pthread_t;/* Thread descriptors */typedef struct _pthread_descr_struct * _pthread_descr;/* Waiting queues (not abstract because mutexes and conditions aren't).  */struct _pthread_queue {  _pthread_descr head;          /* First element, or NULL if queue empty.  */  _pthread_descr tail;          /* Last element, or NULL if queue empty.  */};/* Mutexes (not abstract because of PTHREAD_MUTEX_INITIALIZER).  */typedef struct {  int m_spinlock;               /* Spin lock to guarantee mutual exclusion.  */  int m_count;                  /* 0 if free, > 0 if taken.  */  _pthread_descr m_owner;       /* Owner of mutex (for recursive mutexes) */  int m_kind;                   /* Kind of mutex */  struct _pthread_queue m_waiting; /* Threads waiting on this mutex.  */} pthread_mutex_t;#define PTHREAD_MUTEX_INITIALIZER {0, 0, 0, PTHREAD_MUTEX_FAST_NP, {0, 0}}#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP {0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP, {0, 0}}#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP {0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP, {0, 0}}/* Conditions (not abstract because of PTHREAD_COND_INITIALIZER */typedef struct {  int c_spinlock;                  /* Spin lock to protect the queue.  */  struct _pthread_queue c_waiting;  /* Threads waiting on this condition.  */} pthread_cond_t;#define PTHREAD_COND_INITIALIZER {0, {0, 0}}/* Attributes */enum {  PTHREAD_CREATE_JOINABLE,  PTHREAD_CREATE_DETACHED};enum {  PTHREAD_INHERIT_SCHED,  PTHREAD_EXPLICIT_SCHED};enum {  PTHREAD_SCOPE_SYSTEM,  PTHREAD_SCOPE_PROCESS};typedef struct {  int detachstate;  int schedpolicy;  struct sched_param schedparam;  int inheritsched;  int scope;} pthread_attr_t;enum {  PTHREAD_MUTEX_FAST_NP,  PTHREAD_MUTEX_RECURSIVE_NP,  PTHREAD_MUTEX_ERRORCHECK_NP};typedef struct {  int mutexkind;} pthread_mutexattr_t;typedef struct {  int dummy;} pthread_condattr_t;/* Keys for thread-specific data */typedef unsigned int pthread_key_t;/* Once-only execution */typedef int pthread_once_t;#define PTHREAD_ONCE_INIT 0/* Cleanup buffers */struct _pthread_cleanup_buffer {  void (*routine) __P ((void *));       /* Function to call.  */  void *arg;                            /* Its argument.  */  int canceltype;                       /* Saved cancellation type. */  struct _pthread_cleanup_buffer *prev; /* Chaining of cleanup functions.  */};/* Cancellation */enum { PTHREAD_CANCEL_ENABLE, PTHREAD_CANCEL_DISABLE };enum { PTHREAD_CANCEL_DEFERRED, PTHREAD_CANCEL_ASYNCHRONOUS };#define PTHREAD_CANCELED ((void *) -1)/*** Function for handling threads. ***/#if defined(__cplusplus)extern "C" {#endif/* Create a thread with given attributes ATTR (or default attributes   if ATTR is NULL), and call function START_ROUTINE with given   arguments ARG.  */extern int pthread_create __P ((pthread_t *__thread,                                __const pthread_attr_t *__attr,                                void *(*__start_routine) (void *),                                void *__arg));/* Obtain the identifier of the current thread.  */extern pthread_t pthread_self __P ((void));/* Compare two thread identifiers.  */extern int pthread_equal __P ((pthread_t __thread1, pthread_t __thread2));/* Terminate calling thread.  */extern void pthread_exit __P ((void *__retval)) __attribute__ ((noreturn));/* Make calling thread wait for termination of the thread TH.  The   exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN   is not NULL.  */extern int pthread_join __P ((pthread_t __th, void **__thread_return));/* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.   The resources of TH will therefore be freed immediately when it   terminates, instead of waiting for another thread to perform PTHREAD_JOIN   on it. */extern int pthread_detach __P ((pthread_t __th));/* Functions for handling attributes.  *//* Initialize thread attribute *ATTR with default attributes   (detachstate is PTHREAD_JOINABLE, scheduling policy is SCHED_OTHER). */extern int pthread_attr_init __P ((pthread_attr_t *__attr));/* Destroy thread attribute *ATTR.  */extern int pthread_attr_destroy __P ((pthread_attr_t *__attr));/* Set the `detachstate' attribute in *ATTR according to DETACHSTATE.  */extern int pthread_attr_setdetachstate __P ((pthread_attr_t *__attr,                                             int __detachstate));/* Return in *DETACHSTATE the `detachstate' attribute in *ATTR.  */extern int pthread_attr_getdetachstate __P ((__const pthread_attr_t *__attr,                                             int *__detachstate));/* Set scheduling parameters (priority, etc) in *ATTR according to PARAM.  */extern int pthread_attr_setschedparam __P ((pthread_attr_t *__attr,                                         __const struct sched_param *__param));/* Return in *PARAM the scheduling parameters of *ATTR.  */extern int pthread_attr_getschedparam __P ((__const pthread_attr_t *__attr,                                            struct sched_param *__param));/* Set scheduling policy in *ATTR according to POLICY.  */extern int pthread_attr_setschedpolicy __P ((pthread_attr_t *__attr,                                             int __policy));/* Return in *POLICY the scheduling policy of *ATTR.  */extern int pthread_attr_getschedpolicy __P ((__const pthread_attr_t *__attr,                                             int *__policy));/* Set scheduling inheritance mode in *ATTR according to INHERIT.  */extern int pthread_attr_setinheritsched __P ((pthread_attr_t *__attr,                                              int __inherit));/* Return in *INHERIT the scheduling inheritance mode of *ATTR.  */extern int pthread_attr_getinheritsched __P ((__const pthread_attr_t *__attr,                                              int *__inherit));/* Set scheduling contention scope in *ATTR according to SCOPE.  */extern int pthread_attr_setscope __P((pthread_attr_t *__attr, int __scope));/* Return in *SCOPE the scheduling contention scope of *ATTR.  */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -