* Added start of an implementation of pthread_cancel().
* Implemented pthread_setcanceltype(), pthread_setcancelstate(), and pthread_testcancel(). * In the previous commit, I also made pthread_private.h self-contained. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24710 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
af134c1d5e
commit
c80e610789
@ -154,16 +154,21 @@ extern int pthread_attr_init(pthread_attr_t *attr);
|
||||
extern int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);
|
||||
extern int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
|
||||
|
||||
/* thread functions */
|
||||
extern int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
void *(*start_routine)(void*), void *arg);
|
||||
extern int pthread_detach(pthread_t thread);
|
||||
extern int pthread_equal(pthread_t t1, pthread_t t2);
|
||||
extern void pthread_exit(void *value_ptr);
|
||||
extern int pthread_join(pthread_t thread, void **value_ptr);
|
||||
extern int pthread_join(pthread_t thread, void **_value);
|
||||
extern pthread_t pthread_self(void);
|
||||
|
||||
extern int pthread_kill(pthread_t thread, int sig);
|
||||
|
||||
extern int pthread_cancel(pthread_t thread);
|
||||
extern int pthread_setcancelstate(int state, int *_oldState);
|
||||
extern int pthread_setcanceltype(int type, int *_oldType);
|
||||
extern void pthread_testcancel(void);
|
||||
|
||||
/* thread specific data functions */
|
||||
extern int pthread_key_create(pthread_key_t *key, void (*destructor)(void*));
|
||||
extern int pthread_key_delete(pthread_key_t key);
|
||||
|
@ -6,6 +6,7 @@ MergeObject posix_pthread.o :
|
||||
pthread.c
|
||||
pthread_atfork.c
|
||||
pthread_attr.c
|
||||
pthread_cancel.cpp
|
||||
pthread_cleanup.cpp
|
||||
pthread_cond.c
|
||||
pthread_condattr.c
|
||||
|
@ -87,6 +87,9 @@ pthread_create(pthread_t *_thread, const pthread_attr_t *_attr,
|
||||
|
||||
thread->entry = startRoutine;
|
||||
thread->entry_argument = arg;
|
||||
thread->cancel_state = PTHREAD_CANCEL_ENABLE;
|
||||
thread->cancel_type = PTHREAD_CANCEL_DEFERRED;
|
||||
thread->cancelled = false;
|
||||
thread->cleanup_handlers = NULL;
|
||||
|
||||
if (sPthreadSlot == -1) {
|
||||
|
67
src/system/libroot/posix/pthread/pthread_cancel.cpp
Normal file
67
src/system/libroot/posix/pthread/pthread_cancel.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "pthread_private.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
int
|
||||
pthread_cancel(pthread_t thread)
|
||||
{
|
||||
// TODO: notify thread of being cancelled.
|
||||
fprintf(stderr, "pthread_cancel() is not yet implemented!\n");
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
pthread_setcancelstate(int state, int *_oldState)
|
||||
{
|
||||
if (state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE)
|
||||
return EINVAL;
|
||||
|
||||
pthread_thread* thread = __get_pthread();
|
||||
if (thread == NULL)
|
||||
return EINVAL;
|
||||
|
||||
if (_oldState != NULL)
|
||||
*_oldState = thread->cancel_state;
|
||||
|
||||
thread->cancel_state = state;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
pthread_setcanceltype(int type, int *_oldType)
|
||||
{
|
||||
if (type != PTHREAD_CANCEL_DEFERRED && type != PTHREAD_CANCEL_ASYNCHRONOUS)
|
||||
return EINVAL;
|
||||
|
||||
pthread_thread* thread = __get_pthread();
|
||||
if (thread == NULL)
|
||||
return EINVAL;
|
||||
|
||||
if (_oldType != NULL)
|
||||
*_oldType = thread->cancel_type;
|
||||
|
||||
thread->cancel_type = type;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
pthread_testcancel(void)
|
||||
{
|
||||
pthread_thread* thread = __get_pthread();
|
||||
if (thread == NULL)
|
||||
return;
|
||||
|
||||
if (thread->cancelled && thread->cancel_state == PTHREAD_CANCEL_ENABLE)
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
@ -51,6 +51,9 @@ typedef struct _pthread_attr {
|
||||
struct pthread_thread {
|
||||
void *(*entry)(void*);
|
||||
void *entry_argument;
|
||||
int cancel_state;
|
||||
int cancel_type;
|
||||
bool cancelled;
|
||||
struct __pthread_cleanup_handler *cleanup_handlers;
|
||||
// TODO: move pthread keys in here, too
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user