diff options
| author | Daniel Eischen <deischen@FreeBSD.org> | 2007-04-23 03:36:14 +0000 |
|---|---|---|
| committer | Daniel Eischen <deischen@FreeBSD.org> | 2007-04-23 03:36:14 +0000 |
| commit | 96c57267f5d878daa928bd8ee527f728d30a1a39 (patch) | |
| tree | 8aabeae41b9b83219067a3a40d2419371782e011 /lib | |
| parent | 6f91e7a3af334c4502f1ffc571922c2c490ce8d0 (diff) | |
Notes
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/libkse/thread/thr_info.c | 29 | ||||
| -rw-r--r-- | lib/libpthread/thread/thr_info.c | 29 |
2 files changed, 48 insertions, 10 deletions
diff --git a/lib/libkse/thread/thr_info.c b/lib/libkse/thread/thr_info.c index 1028ca7ca1c3..e8dc506371f4 100644 --- a/lib/libkse/thread/thr_info.c +++ b/lib/libkse/thread/thr_info.c @@ -214,12 +214,31 @@ dump_thread(int fd, pthread_t pthread, int long_version) void _pthread_set_name_np(pthread_t thread, char *name) { - /* Check if the caller has specified a valid thread: */ - if (thread != NULL && thread->magic == THR_MAGIC) { - if (thread->name != NULL) { + struct pthread *curthread = _get_curthread(); + char *new_name; + char *prev_name; + int ret; + + new_name = strdup(name); + /* Add a reference to the target thread. */ + if (_thr_ref_add(curthread, thread, 0) != 0) { + free(new_name); + ret = ESRCH; + } + else { + THR_THREAD_LOCK(curthread, thread); + prev_name = thread->name; + thread->name = new_name; + THR_THREAD_UNLOCK(curthread, thread); + _thr_ref_delete(curthread, thread); + if (prev_name != NULL) { /* Free space for previous name. */ - free(thread->name); + free(prev_name); } - thread->name = strdup(name); + ret = 0; } +#if 0 + /* XXX - Should return error code. */ + return (ret); +#endif } diff --git a/lib/libpthread/thread/thr_info.c b/lib/libpthread/thread/thr_info.c index 1028ca7ca1c3..e8dc506371f4 100644 --- a/lib/libpthread/thread/thr_info.c +++ b/lib/libpthread/thread/thr_info.c @@ -214,12 +214,31 @@ dump_thread(int fd, pthread_t pthread, int long_version) void _pthread_set_name_np(pthread_t thread, char *name) { - /* Check if the caller has specified a valid thread: */ - if (thread != NULL && thread->magic == THR_MAGIC) { - if (thread->name != NULL) { + struct pthread *curthread = _get_curthread(); + char *new_name; + char *prev_name; + int ret; + + new_name = strdup(name); + /* Add a reference to the target thread. */ + if (_thr_ref_add(curthread, thread, 0) != 0) { + free(new_name); + ret = ESRCH; + } + else { + THR_THREAD_LOCK(curthread, thread); + prev_name = thread->name; + thread->name = new_name; + THR_THREAD_UNLOCK(curthread, thread); + _thr_ref_delete(curthread, thread); + if (prev_name != NULL) { /* Free space for previous name. */ - free(thread->name); + free(prev_name); } - thread->name = strdup(name); + ret = 0; } +#if 0 + /* XXX - Should return error code. */ + return (ret); +#endif } |
