📄 pthread.h
字号:
int pthread_attr_setstacksize (pthread_attr_t *attr, size_t stacksize);// Get current minimal stack size.int pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize);//=============================================================================// Dynamic package initialization// Initializer for pthread_once_t instances#define PTHREAD_ONCE_INIT 0// Call init_routine just the once per control variable.int pthread_once (pthread_once_t *once_control, void (*init_routine) (void));//=============================================================================//Thread specific data// Create a key to identify a location in the thread specific data area.// Each thread has its own distinct thread-specific data area but all are// addressed by the same keys. The destructor function is called whenever a// thread exits and the value associated with the key is non-NULL.int pthread_key_create (pthread_key_t *key, void (*destructor) (void *));// Delete key.int pthread_key_delete (pthread_key_t key);// Store the pointer value in the thread-specific data slot addressed// by the key.int pthread_setspecific (pthread_key_t key, const void *pointer);// Retrieve the pointer value in the thread-specific data slot addressed// by the key.void *pthread_getspecific (pthread_key_t key);//=============================================================================// Thread Cancellation//-----------------------------------------------------------------------------// Data structure used to manage cleanup functionsstruct pthread_cleanup_buffer{ struct pthread_cleanup_buffer *prev; // Chain cleanup buffers void (*routine) (void *); // Function to call void *arg; // Arg to pass};//-----------------------------------------------------------------------------// Thread cancelled return value.// This is a value returned as the retval in pthread_join() of a// thread that has been cancelled. By making it the address of a// location we define we can ensure that it differs from NULL and any// other valid pointer (as required by the standard).extern int pthread_canceled_dummy_var;#define PTHREAD_CANCELED ((void *)(&pthread_canceled_dummy_var))//-----------------------------------------------------------------------------// Cancelability enable and type#define PTHREAD_CANCEL_ENABLE 1#define PTHREAD_CANCEL_DISABLE 2#define PTHREAD_CANCEL_ASYNCHRONOUS 1#define PTHREAD_CANCEL_DEFERRED 2//-----------------------------------------------------------------------------// Functions// Set cancel state of current thread to ENABLE or DISABLE.// Returns old state in *oldstate.int pthread_setcancelstate (int state, int *oldstate);// Set cancel type of current thread to ASYNCHRONOUS or DEFERRED.// Returns old type in *oldtype.int pthread_setcanceltype (int type, int *oldtype);// Cancel the thread.int pthread_cancel (pthread_t thread);// Test for a pending cancellation for the current thread and terminate// the thread if there is one.void pthread_testcancel (void);// Install a cleanup routine.// Note that pthread_cleanup_push() and pthread_cleanup_pop() are macros that// must be used in matching pairs and at the same brace nesting level.#define pthread_cleanup_push(routine,arg) \ { \ struct pthread_cleanup_buffer _buffer_; \ pthread_cleanup_push_inner (&_buffer_, (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) \ pthread_cleanup_pop_inner (&_buffer_, (execute)); \ }// These two functions actually implement the cleanup push and pop functionality.void pthread_cleanup_push_inner (struct pthread_cleanup_buffer *buffer, void (*routine) (void *), void *arg);void pthread_cleanup_pop_inner (struct pthread_cleanup_buffer *buffer, int execute);//-----------------------------------------------------------------------------// Mutex objecttypedef struct{ void* os_mutex;} pthread_mutex_t;// We do not implement PTHREAD_MUTEX_INITIALIZER#undef PTHREAD_MUTEX_INITIALIZER//-----------------------------------------------------------------------------// Mutex attributes structuretypedef struct{ unsigned char prio;} pthread_mutexattr_t;//=============================================================================// Mutexes//-----------------------------------------------------------------------------// Mutex attributes manipulation functions// Initialize attribute objectint pthread_mutexattr_init ( pthread_mutexattr_t *attr);// Destroy attribute objectint pthread_mutexattr_destroy ( pthread_mutexattr_t *attr);// Set priorityint pthread_mutexattr_setpriority ( pthread_mutexattr_t *attr, int priority);// Get priorityint pthread_mutexattr_getpriority ( pthread_mutexattr_t *attr, int* priority);//-----------------------------------------------------------------------------// Mutex functions// Initialize mutex. If mutex_attr is NULL, use default attributes.int pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *mutex_attr);// Destroy mutex.int pthread_mutex_destroy (pthread_mutex_t *mutex);// Lock mutex, waiting for it if necessary.int pthread_mutex_lock (pthread_mutex_t *mutex);// Try to lock mutex.int pthread_mutex_trylock (pthread_mutex_t *mutex);// Unlock mutex.int pthread_mutex_unlock (pthread_mutex_t *mutex);#if 0 /* We do not implement pthread condition variable *///-----------------------------------------------------------------------------// Condition Variable structure.// Like mutexes, this must match the underlying eCos implementation class.typedef struct{ int dummy;} pthread_cond_t;#define PTHREAD_COND_INITIALIZER { 0, 0 }//-----------------------------------------------------------------------------// Condition variable attributes structuretypedef struct{ int dummy;} pthread_condattr_t;//=============================================================================// Condition Variables//-----------------------------------------------------------------------------// Attribute manipulation functions// We do not actually support any attributes at present, so these do nothing.// Initialize condition variable attributesint pthread_condattr_init (pthread_condattr_t *attr);// Destroy condition variable attributesint pthread_condattr_destroy (pthread_condattr_t *attr);//-----------------------------------------------------------------------------// Condition variable functions// Initialize condition variable.int pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t *attr);// Destroy condition variable.int pthread_cond_destroy (pthread_cond_t *cond);// Wake up one thread waiting for condition variableint pthread_cond_signal (pthread_cond_t *cond);// Wake up all threads waiting for condition variableint pthread_cond_broadcast (pthread_cond_t *cond);// Block on condition variable until signalled. The mutex is// assumed to be locked before this call, will be unlocked// during the wait, and will be re-locked on wakeup.int pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex);// Block on condition variable until signalled, or the timeout expires.int pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime);#endif /* We do not implement pthread condition variable*/#endif /* __UCOSII__ */#endif /* UCOSII_PTHREAD_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -