Changeset 23 for trunk/kernel/syscalls/sys_thread_wakeup.c
- Timestamp:
- Jun 18, 2017, 10:06:41 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_thread_wakeup.c
r1 r23 1 1 /* 2 * kern/sys_thread_wakeup.c - wakeup all indicated threads2 * sys_thread_wakeup.c - wakeup all indicated threads 3 3 * 4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless 5 * Copyright (c) 2011,2012 UPMC Sorbonne Universites 4 * Author Alain Greiner (2016,2017) 6 5 * 7 * This file is part of ALMOS-kernel.6 * Copyright (c) UPMC Sorbonne Universites 8 7 * 9 * ALMOS-kernel is free software; you can redistribute it and/or modify it 8 * This file is part of ALMOS-MKH. 9 * 10 * ALMOS-MKH is free software; you can redistribute it and/or modify it 10 11 * under the terms of the GNU General Public License as published by 11 12 * the Free Software Foundation; version 2.0 of the License. 12 13 * 13 * ALMOS- kernelis distributed in the hope that it will be useful, but14 * ALMOS-MKH is distributed in the hope that it will be useful, but 14 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 17 18 * 18 19 * You should have received a copy of the GNU General Public License 19 * along with ALMOS- kernel; if not, write to the Free Software Foundation,20 * along with ALMOS-MKH; if not, write to the Free Software Foundation, 20 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 22 */ 22 23 24 #include <hal_types.h> 25 #include <thread.h> 26 #include <printk.h> 27 #include <process.h> 23 28 #include <errno.h> 24 #include <kmagics.h>25 #include <cpu.h>26 #include <kdmsg.h>27 #include <cluster.h>28 #include <task.h>29 #include <scheduler.h>30 #include <thread.h>31 29 32 /* 33 * FIXME: define spinlock_rdlock() so all locking on task->th_lock 34 * becoms rdlock but on join/detach/destroy 35 */ 36 int sys_thread_wakeup(pthread_t tid, pthread_t *tid_tbl, uint_t count) 30 ////////////////////////////////////// 31 int sys_thread_wakeup( trdid_t trdid ) 37 32 { 38 struct task_s *task; 39 struct thread_s *this; 40 struct thread_s *target; 41 pthread_t tbl[100]; 42 void *listner; 43 uint_t event; 44 sint_t i; 45 error_t err; 33 thread_t * this = CURRENT_THREAD; 34 process_t * process = this->process; 46 35 47 this = current_thread; 48 task = this->task;49 i = -1;36 // get target thread ltid and cxy 37 ltid_t target_ltid = LTID_FROM_TRDID( trdid ); 38 cxy_t target_cxy = CXY_FROM_TRDID( trdid ); 50 39 51 if(tid_tbl != NULL) 40 // check trdid argument 41 if( (target_ltid >= CONFIG_THREAD_MAX_PER_CLUSTER) || cluster_is_undefined( target_cxy ) ) 52 42 { 53 if((NOT_IN_USPACE((uint_t)tid_tbl + (count*sizeof(pthread_t)))) || 54 (count == 0) || (count > 100)) 55 { 56 err = -1; 57 goto fail_tid_tbl; 58 } 59 60 if((err = cpu_copy_from_uspace(&tbl[0], tid_tbl, sizeof(pthread_t*) * count))) 61 goto fail_usapce; 62 63 if(tbl[0] != tid) 64 { 65 err = -2; 66 goto fail_first_tid; 67 } 68 } 69 else 70 { 71 count = 1; 72 tbl[0] = tid; 43 printk("\n[ERROR] in %s : illegal trdid argument\n", __FUNCTION__ ); 44 this->errno = EINVAL; 45 return -1; 73 46 } 74 47 75 for(i = 0; i < count; i++) 76 { 77 tid = tbl[i]; 48 // get extended pointer on target thread 49 xptr_t thread_xp = thread_get_xptr( process->pid , trdid ); 78 50 79 if(tid > task->max_order) 80 { 81 err = -3; 82 goto fail_tid; 83 } 51 if( thread_xp == XPTR_NULL ) 52 { 53 printk("\n[ERROR] in %s : cannot find thread %x in process %x/n", 54 __FUNCTION__ , trdid , CURRENT_THREAD->process->pid ); 55 CURRENT_THREAD->errno = EINVAL; 56 return -1; 57 } 84 58 85 target = task->th_tbl[tid]; 86 87 if((target == NULL) || (target->signature != THREAD_ID)) 88 { 89 err = -4; 90 goto fail_target; 91 } 59 // unblock target thread 60 thread_unblock( thread_xp , THREAD_BLOCKED_GLOBAL ); 92 61 93 listner = sched_get_listner(target, SCHED_OP_UWAKEUP); 94 event = sched_event_make(target,SCHED_OP_UWAKEUP); 95 96 if(this->info.isTraced == true) 97 { 98 printk(INFO,"%s: tid %d --> tid %d [%d][%d]\n", 99 __FUNCTION__, 100 this->info.order, 101 tid, 102 cpu_time_stamp(), 103 i); 104 } 105 106 sched_event_send(listner,event); 107 cpu_wbflush(); 108 } 109 110 return 0; 111 112 fail_target: 113 fail_tid: 114 fail_first_tid: 115 fail_usapce: 116 fail_tid_tbl: 117 118 printk(INFO, "%s: cpu %d, pid %d, tid %x, i %d, count %d, ttid %x, request has failed with err %d [%d]\n", 119 __FUNCTION__, 120 cpu_get_id(), 121 task->pid, 122 this, 123 i, 124 count, 125 tid, 126 err, 127 cpu_time_stamp()); 128 129 this->info.errno = EINVAL; 130 return -1; 131 } 62 return 0; 63 } // end sys_thread_wakeup()
Note: See TracChangeset
for help on using the changeset viewer.