@@ -65,7 +65,7 @@ int msg_send(msg_t *m, kernel_pid_t target_pid)
6565 if (irq_is_in ()) {
6666 return msg_send_int (m , target_pid );
6767 }
68- if (sched_active_pid == target_pid ) {
68+ if (thread_getpid () == target_pid ) {
6969 return msg_send_to_self (m );
7070 }
7171 return _msg_send (m , target_pid , true, irq_disable ());
@@ -76,7 +76,7 @@ int msg_try_send(msg_t *m, kernel_pid_t target_pid)
7676 if (irq_is_in ()) {
7777 return msg_send_int (m , target_pid );
7878 }
79- if (sched_active_pid == target_pid ) {
79+ if (thread_getpid () == target_pid ) {
8080 return msg_send_to_self (m );
8181 }
8282 return _msg_send (m , target_pid , false, irq_disable ());
@@ -91,21 +91,21 @@ static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block,
9191 }
9292#endif /* DEVELHELP */
9393
94- thread_t * target = ( thread_t * ) sched_threads [ target_pid ] ;
94+ thread_t * target = thread_get_unchecked ( target_pid ) ;
9595
96- m -> sender_pid = sched_active_pid ;
96+ m -> sender_pid = thread_getpid () ;
9797
9898 if (target == NULL ) {
9999 DEBUG ("msg_send(): target thread %d does not exist\n" , target_pid );
100100 irq_restore (state );
101101 return -1 ;
102102 }
103103
104- thread_t * me = ( thread_t * ) sched_active_thread ;
104+ thread_t * me = thread_get_active () ;
105105
106106 DEBUG ("msg_send() %s:%i: Sending from %" PRIkernel_pid " to %" PRIkernel_pid
107107 ". block=%i src->state=%i target->state=%i\n" , RIOT_FILE_RELATIVE ,
108- __LINE__ , sched_active_pid , target_pid ,
108+ __LINE__ , thread_getpid () , target_pid ,
109109 block , me -> status , target -> status );
110110
111111 if (target -> status != STATUS_RECEIVE_BLOCKED ) {
@@ -125,17 +125,16 @@ static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block,
125125 }
126126
127127 if (!block ) {
128- DEBUG (
129- "msg_send: %" PRIkernel_pid ": Receiver not waiting, block=%u\n" ,
130- me -> pid , block );
128+ DEBUG ("msg_send: %" PRIkernel_pid ": Receiver not waiting, "
129+ "block=%u\n" , me -> pid , block );
131130 irq_restore (state );
132131 return 0 ;
133132 }
134133
135134 DEBUG ("msg_send: %" PRIkernel_pid ": going send blocked.\n" ,
136135 me -> pid );
137136
138- me -> wait_data = ( void * ) m ;
137+ me -> wait_data = m ;
139138
140139 int newstatus ;
141140
@@ -146,7 +145,7 @@ static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block,
146145 newstatus = STATUS_SEND_BLOCKED ;
147146 }
148147
149- sched_set_status (( thread_t * ) me , newstatus );
148+ sched_set_status (me , newstatus );
150149
151150 thread_add_to_list (& (target -> msg_waiters ), me );
152151
@@ -166,7 +165,7 @@ static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block,
166165 PRIkernel_pid " to %" PRIkernel_pid ".\n" ,
167166 me -> pid , thread_getpid (), target_pid );
168167 /* copy msg to target */
169- msg_t * target_message = ( msg_t * ) target -> wait_data ;
168+ msg_t * target_message = target -> wait_data ;
170169 * target_message = * m ;
171170 sched_set_status (target , STATUS_PENDING );
172171
@@ -181,8 +180,8 @@ int msg_send_to_self(msg_t *m)
181180{
182181 unsigned state = irq_disable ();
183182
184- m -> sender_pid = sched_active_pid ;
185- int res = queue_msg (( thread_t * ) sched_active_thread , m );
183+ m -> sender_pid = thread_getpid () ;
184+ int res = queue_msg (thread_get_active () , m );
186185
187186 irq_restore (state );
188187 return res ;
@@ -196,7 +195,7 @@ static int _msg_send_oneway(msg_t *m, kernel_pid_t target_pid)
196195 }
197196#endif /* DEVELHELP */
198197
199- thread_t * target = ( thread_t * ) sched_threads [ target_pid ] ;
198+ thread_t * target = thread_get_unchecked ( target_pid ) ;
200199
201200 if (target == NULL ) {
202201 DEBUG ("%s: target thread %d does not exist\n" , __func__ , target_pid );
@@ -242,7 +241,7 @@ int msg_send_bus(msg_t *m, msg_bus_t *bus)
242241 const uint32_t event_mask = (1UL << (m -> type & 0x1F ));
243242 int count = 0 ;
244243
245- m -> sender_pid = in_irq ? KERNEL_PID_ISR : sched_active_pid ;
244+ m -> sender_pid = in_irq ? KERNEL_PID_ISR : thread_getpid () ;
246245
247246 unsigned state = irq_disable ();
248247
@@ -269,11 +268,11 @@ int msg_send_bus(msg_t *m, msg_bus_t *bus)
269268
270269int msg_send_receive (msg_t * m , msg_t * reply , kernel_pid_t target_pid )
271270{
272- assert (sched_active_pid != target_pid );
271+ assert (thread_getpid () != target_pid );
273272 unsigned state = irq_disable ();
274- thread_t * me = ( thread_t * ) sched_active_thread ;
273+ thread_t * me = thread_get_active () ;
275274 sched_set_status (me , STATUS_REPLY_BLOCKED );
276- me -> wait_data = ( void * ) reply ;
275+ me -> wait_data = reply ;
277276
278277 /* we re-use (abuse) reply for sending, because wait_data might be
279278 * overwritten if the target is not in RECEIVE_BLOCKED */
@@ -286,20 +285,20 @@ int msg_reply(msg_t *m, msg_t *reply)
286285{
287286 unsigned state = irq_disable ();
288287
289- thread_t * target = ( thread_t * ) sched_threads [ m -> sender_pid ] ;
288+ thread_t * target = thread_get_unchecked ( m -> sender_pid ) ;
290289
291290 assert (target != NULL );
292291
293292 if (target -> status != STATUS_REPLY_BLOCKED ) {
294293 DEBUG ("msg_reply(): %" PRIkernel_pid ": Target \"%" PRIkernel_pid
295- "\" not waiting for reply." , sched_active_thread -> pid ,
294+ "\" not waiting for reply." , thread_getpid () ,
296295 target -> pid );
297296 irq_restore (state );
298297 return -1 ;
299298 }
300299
301300 DEBUG ("msg_reply(): %" PRIkernel_pid ": Direct msg copy.\n" ,
302- sched_active_thread -> pid );
301+ thread_getpid () );
303302 /* copy msg to target */
304303 msg_t * target_message = (msg_t * )target -> wait_data ;
305304 * target_message = * reply ;
@@ -313,11 +312,11 @@ int msg_reply(msg_t *m, msg_t *reply)
313312
314313int msg_reply_int (msg_t * m , msg_t * reply )
315314{
316- thread_t * target = ( thread_t * ) sched_threads [ m -> sender_pid ] ;
315+ thread_t * target = thread_get_unchecked ( m -> sender_pid ) ;
317316
318317 if (target -> status != STATUS_REPLY_BLOCKED ) {
319318 DEBUG ("msg_reply_int(): %" PRIkernel_pid ": Target \"%" PRIkernel_pid
320- "\" not waiting for reply." , sched_active_thread -> pid ,
319+ "\" not waiting for reply." , thread_getpid () ,
321320 target -> pid );
322321 return -1 ;
323322 }
@@ -344,9 +343,9 @@ static int _msg_receive(msg_t *m, int block)
344343 unsigned state = irq_disable ();
345344
346345 DEBUG ("_msg_receive: %" PRIkernel_pid ": _msg_receive.\n" ,
347- sched_active_thread -> pid );
346+ thread_getpid () );
348347
349- thread_t * me = ( thread_t * ) sched_active_thread ;
348+ thread_t * me = thread_get_active () ;
350349
351350 int queue_index = -1 ;
352351
@@ -361,9 +360,8 @@ static int _msg_receive(msg_t *m, int block)
361360 }
362361
363362 if (queue_index >= 0 ) {
364- DEBUG (
365- "_msg_receive: %" PRIkernel_pid ": _msg_receive(): We've got a queued message.\n" ,
366- sched_active_thread -> pid );
363+ DEBUG ("_msg_receive: %" PRIkernel_pid ": _msg_receive(): We've got a "
364+ "queued message.\n" , thread_getpid ());
367365 * m = me -> msg_array [queue_index ];
368366 }
369367 else {
@@ -373,21 +371,19 @@ static int _msg_receive(msg_t *m, int block)
373371 list_node_t * next = list_remove_head (& me -> msg_waiters );
374372
375373 if (next == NULL ) {
376- DEBUG (
377- "_msg_receive: %" PRIkernel_pid ": _msg_receive(): No thread in waiting list.\n" ,
378- sched_active_thread -> pid );
374+ DEBUG ("_msg_receive: %" PRIkernel_pid ": _msg_receive(): No thread in "
375+ "waiting list.\n" , thread_getpid ());
379376
380377 if (queue_index < 0 ) {
381- DEBUG (
382- "_msg_receive(): %" PRIkernel_pid ": No msg in queue. Going blocked.\n" ,
383- sched_active_thread -> pid );
378+ DEBUG ("_msg_receive(): %" PRIkernel_pid ": No msg in queue. Going "
379+ "blocked.\n" , thread_getpid ());
384380 sched_set_status (me , STATUS_RECEIVE_BLOCKED );
385381
386382 irq_restore (state );
387383 thread_yield_higher ();
388384
389385 /* sender copied message */
390- assert (sched_active_thread -> status != STATUS_RECEIVE_BLOCKED );
386+ assert (thread_get_active () -> status != STATUS_RECEIVE_BLOCKED );
391387 }
392388 else {
393389 irq_restore (state );
@@ -396,9 +392,8 @@ static int _msg_receive(msg_t *m, int block)
396392 return 1 ;
397393 }
398394 else {
399- DEBUG (
400- "_msg_receive: %" PRIkernel_pid ": _msg_receive(): Waking up waiting thread.\n" ,
401- sched_active_thread -> pid );
395+ DEBUG ("_msg_receive: %" PRIkernel_pid ": _msg_receive(): Waking up "
396+ "waiting thread.\n" , thread_getpid ());
402397
403398 thread_t * sender =
404399 container_of ((clist_node_t * )next , thread_t , rq_entry );
@@ -435,9 +430,9 @@ static int _msg_receive(msg_t *m, int block)
435430int msg_avail (void )
436431{
437432 DEBUG ("msg_available: %" PRIkernel_pid ": msg_available.\n" ,
438- sched_active_thread -> pid );
433+ thread_getpid () );
439434
440- thread_t * me = ( thread_t * ) sched_active_thread ;
435+ thread_t * me = thread_get_active () ;
441436
442437 int queue_index = -1 ;
443438
@@ -450,7 +445,7 @@ int msg_avail(void)
450445
451446void msg_init_queue (msg_t * array , int num )
452447{
453- thread_t * me = ( thread_t * ) sched_active_thread ;
448+ thread_t * me = thread_get_active () ;
454449
455450 me -> msg_array = array ;
456451 cib_init (& (me -> msg_queue ), num );
@@ -460,7 +455,7 @@ void msg_queue_print(void)
460455{
461456 unsigned state = irq_disable ();
462457
463- thread_t * thread = ( thread_t * ) sched_active_thread ;
458+ thread_t * thread = thread_get_active () ;
464459 cib_t * msg_queue = & thread -> msg_queue ;
465460 msg_t * msg_array = thread -> msg_array ;
466461 unsigned int i = msg_queue -> read_count & msg_queue -> mask ;
0 commit comments