summaryrefslogtreecommitdiff
path: root/ecos/packages/kernel/current/include/thread.inl
blob: 8c00070cdfeacf07554bcc837e91ce5f1ed39244 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
#ifndef CYGONCE_KERNEL_THREAD_INL
#define CYGONCE_KERNEL_THREAD_INL

//==========================================================================
//
//      thread.inl
//
//      Thread class inlines
//
//==========================================================================
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
// -------------------------------------------                              
// This file is part of eCos, the Embedded Configurable Operating System.   
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2008 Free Software Foundation, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under    
// the terms of the GNU General Public License as published by the Free     
// Software Foundation; either version 2 or (at your option) any later      
// version.                                                                 
//
// eCos is distributed in the hope that it will be useful, but WITHOUT      
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
// for more details.                                                        
//
// You should have received a copy of the GNU General Public License        
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
//
// As a special exception, if other files instantiate templates or use      
// macros or inline functions from this file, or you compile this file      
// and link it with other works to produce a work based on this file,       
// this file does not by itself cause the resulting work to be covered by   
// the GNU General Public License. However the source code for this file    
// must still be made available in accordance with section (3) of the GNU   
// General Public License v2.                                               
//
// This exception does not invalidate any other reasons why a work based    
// on this file might be covered by the GNU General Public License.         
// -------------------------------------------                              
// ####ECOSGPLCOPYRIGHTEND####                                              
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):   nickg
// Contributors:        nickg
// Date:        1997-09-09
// Purpose:     Define inlines for thread classes
// Description: Inline implementations of various member functions defined
//              in various Thread classes. 
// Usage:
//              #include <cyg/kernel/thread.hxx>
//              ...
//              #include <cyg/kernel/thread.inl>
//              ...

//
//####DESCRIPTIONEND####
//
//==========================================================================

#include <cyg/kernel/thread.hxx>
#include <cyg/hal/hal_arch.h>

#include <cyg/kernel/clock.inl>
#include <cyg/infra/diag.h>

#ifndef CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE
#define CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE (0)
#endif

//==========================================================================
// Inlines for Cyg_HardwareThread

// -------------------------------------------------------------------------
// get the size/base of this thread's stack

inline CYG_ADDRESS
Cyg_HardwareThread::get_stack_base()
{
    return stack_base - CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE;
}

inline cyg_uint32
Cyg_HardwareThread::get_stack_size()
{
    return stack_size + 2 * CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE;
}

// -------------------------------------------------------------------------
// Check the stack bounds of this thread:
#ifdef CYGFUN_KERNEL_THREADS_STACK_CHECKING
inline void Cyg_HardwareThread::check_stack(void)
{
    cyg_uint32 sig = (cyg_uint32)this;
    cyg_uint32 *base = (cyg_uint32 *)get_stack_base();
    cyg_uint32 *top =  (cyg_uint32 *)(stack_base + stack_size);
    cyg_ucount32 i;

    CYG_INSTRUMENT_THREAD(CHECK_STACK, base, top );
    
    CYG_ASSERT( 0 == ((sizeof(CYG_WORD)-1) & (cyg_uint32)base), "stack base not word aligned" );
    CYG_ASSERT( 0 == ((sizeof(CYG_WORD)-1) & (cyg_uint32)top),  "stack  top not word aligned" );

    CYG_ASSERT( (cyg_uint32)stack_ptr > (cyg_uint32)stack_base,
                "Stack_ptr below base" );
    CYG_ASSERT( (cyg_uint32)stack_ptr <= ((cyg_uint32)stack_base + stack_size),
                "Stack_ptr above top" );

    for ( i = 0;
          i < CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE/sizeof(cyg_uint32);
          i++ ) {
        if ((sig ^ (i * 0x01010101)) != base[i]) {
            const char *reason = "Stack base corrupt";
            diag_printf("%s - i: %d\n", reason, i);
            diag_dump_buf(base, CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE);
            CYG_FAIL(reason);
        }
        if ((sig ^ (i * 0x10101010)) != top[i]) {
            const char *reason = "Stack top corrupt";
            diag_printf("%s - i: %d\n", reason, i);
            diag_dump_buf(top, CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE);
            CYG_FAIL(reason);
        }
    }            

#ifdef CYGFUN_KERNEL_THREADS_STACK_LIMIT
    // we won't have added check data above the stack limit if it hasn't
    // been incremented
    if (stack_limit != stack_base) {
        CYG_ADDRESS limit = stack_limit;
        // the limit will be off by the check data size, so lets correct it
        limit -= CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE;
        
        // determine base of check data by rounding up to nearest word aligned
        // address if not already aligned
        cyg_uint32 *p = (cyg_uint32 *)((limit + 3) & ~3);
        // i.e. + sizeof(cyg_uint32)-1) & ~(sizeof(cyg_uint32)-1);
        
        for ( i = 0;
              i < CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE/sizeof(cyg_uint32);
              i++ ) {
            if ((sig ^ (i * 0x01010101)) != p[i]) {
                const char *reason = "Gap between stack limit and base corrupt";
                diag_printf("%s - i: %d\n", reason, i);
                diag_dump_buf(p, CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE);
                CYG_FAIL(reason);
            }
        }
    }
#endif
}
#endif

// -------------------------------------------------------------------------
// Measure the stack usage of the thread
#ifdef CYGFUN_KERNEL_THREADS_STACK_MEASUREMENT
inline cyg_uint32 Cyg_HardwareThread::measure_stack_usage(void)
{
#ifdef CYGFUN_KERNEL_THREADS_STACK_LIMIT
    CYG_WORD *base = (CYG_WORD *)stack_limit;
    cyg_uint32 size = (stack_size - (stack_limit-stack_base))/sizeof(CYG_WORD);
#else
    CYG_WORD *base = (CYG_WORD *)stack_base;
    cyg_uint32 size = stack_size/sizeof(CYG_WORD);
#endif
    cyg_ucount32 i;

    // Work up the stack comparing with the preset value
    // We assume the stack grows downwards, hmm...
    for (i=0; i<size; i++) {
	if (base[i] != 0xDEADBEEF)
	  break;
    }
    return (size - i)*sizeof(CYG_WORD);
}
#endif

// -------------------------------------------------------------------------
// Attach a stack to this thread. If there is a HAL defined macro to
// do this, then we use that, otherwise assume a falling stack.
inline void Cyg_HardwareThread::attach_stack(CYG_ADDRESS s_base, cyg_uint32 s_size)
{
#ifdef CYGNUM_HAL_STACK_SIZE_MINIMUM
    CYG_ASSERT( s_size >= CYGNUM_HAL_STACK_SIZE_MINIMUM,
                "Stack size too small");
#endif

#ifdef CYGFUN_KERNEL_THREADS_STACK_CHECKING
    {
        cyg_uint32 sig = (cyg_uint32)this;
        cyg_uint32 *base = (cyg_uint32 *)s_base;
        cyg_uint32 *top =  (cyg_uint32 *)(s_base + s_size -
            CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE);

        unsigned int i;

        CYG_INSTRUMENT_THREAD(ATTACH_STACK, base, top );
        
        CYG_ASSERT( NULL != base, "stack base non-NULL" );
        CYG_ASSERT( 0 == ((sizeof(CYG_WORD)-1) & (cyg_uint32)base), "stack base alignment" );
        CYG_ASSERT( 0 == ((sizeof(CYG_WORD)-1) & (cyg_uint32)top),  "stack  top alignment" );

        for ( i = 0;
              i < CYGNUM_KERNEL_THREADS_STACK_CHECK_DATA_SIZE/sizeof(cyg_uint32);
              i++ ) {
            base[i] = (sig ^ (i * 0x01010101));
             top[i] = (sig ^ (i * 0x10101010));
        }            
        // This check for overlap of the two signature areas also detects
        // wrap round zero of the size in the unsigned subtraction below.
        CYG_ASSERT( &base[i] < &top[0], "Stack is so small size wrapped" );
        // Use this 'i' expression to round correctly to whole words.
        s_base += i * sizeof(cyg_uint32);
        s_size -= i * sizeof(cyg_uint32) * 2;
        // This is a complete guess, the 256; the point is to assert early that
        // this might go badly wrong.  It would not detect wrap of unsigned size.
        CYG_ASSERT( s_size >= 256,
                    "Stack size too small after allocating checking buffer");
    }
#endif
#ifdef CYGFUN_KERNEL_THREADS_STACK_MEASUREMENT
    {
	CYG_WORD *base = (CYG_WORD *)s_base;
	cyg_uint32 size = s_size/sizeof(CYG_WORD);
	cyg_ucount32 i;

	// initialize all of stack with known value - don't choose 0
	// could do with pseudo value as above, but this way, checking
	// is faster
	for (i=0; i<size; i++) {
		base[i] = 0xDEADBEEF;
	}
	// Don't bother about the case when the stack isn't a multiple of
	// CYG_WORD in size. Since it's at the top of the stack, it will
	// almost certainly be overwritten the instant the thread starts
	// anyway.
    }
#endif
    stack_base = s_base;
    stack_size = s_size;
#ifdef CYGFUN_KERNEL_THREADS_STACK_LIMIT
    stack_limit = s_base;
#endif
    
#ifdef HAL_THREAD_ATTACH_STACK

    HAL_THREAD_ATTACH_STACK(stack_ptr, stack_base, stack_size);
    
#else

    stack_ptr = stack_base + stack_size;

#endif

#ifdef CYGFUN_KERNEL_THREADS_STACK_CHECKING
    check_stack();
#endif
}

// -------------------------------------------------------------------------

inline Cyg_HardwareThread::Cyg_HardwareThread(
    cyg_thread_entry        *e_point,   // entry point function
    CYG_ADDRWORD            e_data,     // entry data
    cyg_ucount32            s_size,     // stack size, 0 = use default
    CYG_ADDRESS             s_base      // stack base, NULL = allocate
)
{
    entry_point = e_point;
    entry_data  = e_data;
#ifdef CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT
    saved_context = 0;
#endif
    
    attach_stack( s_base, s_size );
};

// -------------------------------------------------------------------------

#ifdef CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT

// Return the current saved state for this thread.
inline HAL_SavedRegisters *Cyg_HardwareThread::get_saved_context()
{
    HAL_SavedRegisters *regs;
    if( saved_context != 0 ) regs = saved_context;
    else HAL_THREAD_GET_SAVED_REGISTERS( stack_ptr, regs );
    return regs;
}

inline void Cyg_HardwareThread::set_saved_context(HAL_SavedRegisters *ctx)
{
    saved_context = ctx;
}

#endif

// -------------------------------------------------------------------------
// (declare this inline before its first use)

inline cyg_uint16 Cyg_Thread::get_unique_id()
{
    return unique_id;
}

// -------------------------------------------------------------------------
// Initialize the context of this thread.

inline void Cyg_HardwareThread::init_context(Cyg_Thread *thread)
{
#ifdef CYGPKG_INFRA_DEBUG
    cyg_uint32 threadid = thread->get_unique_id()*0x01010000;
#else
    cyg_uint32 threadid = 0x11110000;
#endif
    HAL_THREAD_INIT_CONTEXT( stack_ptr, thread, thread_entry, threadid );
}



// -------------------------------------------------------------------------
// Save current thread's context and load that of the given next thread.
// This function is only really here for completeness, the
// kernel generally calls the HAL macros directly.

inline void Cyg_HardwareThread::switch_context(Cyg_HardwareThread *next)
{
    HAL_THREAD_SWITCH_CONTEXT( &stack_ptr, &next->stack_ptr );
}

// -------------------------------------------------------------------------
// Get and set entry_data.

inline void Cyg_HardwareThread::set_entry_data( CYG_ADDRWORD data )
{
    entry_data = data;
}

inline CYG_ADDRWORD Cyg_HardwareThread::get_entry_data()
{
    return entry_data;
}

// -------------------------------------------------------------------------
// Allocate some memory at the lower end of the stack
// by moving the stack limit pointer.

#ifdef CYGFUN_KERNEL_THREADS_STACK_LIMIT

#ifndef CYGFUN_KERNEL_THREADS_STACK_CHECKING
// if stack checking, implementation is in thread.cxx
inline void *Cyg_HardwareThread::increment_stack_limit( cyg_ucount32 size )
{
    void *ret = (void *)stack_limit;
    stack_limit += size;
    return ret;
}
#endif
    
inline CYG_ADDRESS
Cyg_HardwareThread::get_stack_limit()
{
    return stack_limit;
}

#endif    

//==========================================================================
// Inlines for Cyg_Thread class

inline Cyg_Thread *Cyg_Thread::self()
{
    return Cyg_Scheduler::get_current_thread();
}

// -------------------------------------------------------------------------

inline void Cyg_Thread::yield()
{
    self()->Cyg_SchedThread::yield();
}

// -------------------------------------------------------------------------

inline void
Cyg_Thread::rotate_queue( cyg_priority pri )
{
    self()->Cyg_SchedThread::rotate_queue( pri );
}

// -------------------------------------------------------------------------

inline void
Cyg_Thread::to_queue_head( void )
{
    this->Cyg_SchedThread::to_queue_head();
}

// -------------------------------------------------------------------------

#ifdef CYGIMP_THREAD_PRIORITY

inline cyg_priority Cyg_Thread::get_priority()
{
#ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_SIMPLE

    // If we have an inherited priority, return our original
    // priority rather than the current one.
    
    if( priority_inherited ) return original_priority;

#endif

    return priority;
}

// Return the actual dispatching priority of the thread
// regardless of inheritance or scheduling concerns.
inline cyg_priority Cyg_Thread::get_current_priority()
{
    return priority;
}

#endif

// -------------------------------------------------------------------------

inline void Cyg_Thread::set_sleep_reason( cyg_reason reason)
{
    self()->sleep_reason = reason;
    self()->wake_reason = NONE;
}

// -------------------------------------------------------------------------

inline Cyg_Thread::cyg_reason Cyg_Thread::get_sleep_reason()
{
    return sleep_reason;
}

// -------------------------------------------------------------------------

inline void Cyg_Thread::set_wake_reason( cyg_reason reason )
{
    sleep_reason = NONE;
    wake_reason = reason;
}

// -------------------------------------------------------------------------

inline Cyg_Thread::cyg_reason Cyg_Thread::get_wake_reason()
{
    return wake_reason;
}

// -------------------------------------------------------------------------

inline void Cyg_Thread::set_timer(
    cyg_tick_count      trigger,
    cyg_reason          reason
)
{
#ifdef CYGFUN_KERNEL_THREADS_TIMER
    self()->sleep_reason = reason;
    self()->wake_reason = NONE;
    self()->timer.initialize( trigger);
#endif
}

// -------------------------------------------------------------------------

inline void Cyg_Thread::clear_timer()
{
#ifdef CYGFUN_KERNEL_THREADS_TIMER
    self()->timer.disable();
#endif
}

// -------------------------------------------------------------------------

#ifdef CYGVAR_KERNEL_THREADS_DATA

inline CYG_ADDRWORD Cyg_Thread::get_data( Cyg_Thread::cyg_data_index index )
{
    CYG_ASSERT( index < CYGNUM_KERNEL_THREADS_DATA_MAX,
                "Per thread data index out of bounds");
    CYG_ASSERT( (thread_data_map & (1<<index)) == 0,
                "Unallocated index used");
    
    return self()->thread_data[index];
}

inline CYG_ADDRWORD *Cyg_Thread::get_data_ptr( Cyg_Thread::cyg_data_index index )
{
    CYG_ASSERT( index < CYGNUM_KERNEL_THREADS_DATA_MAX,
                "Per thread data index out of bounds");
    CYG_ASSERT( (thread_data_map & (1<<index)) == 0,
                "Unallocated index used");
    
    return &(self()->thread_data[index]);
}

inline void Cyg_Thread::set_data( Cyg_Thread::cyg_data_index index,
                                  CYG_ADDRWORD data )
{
    CYG_ASSERT( index < CYGNUM_KERNEL_THREADS_DATA_MAX,
                "Per thread data index out of bounds");
    CYG_ASSERT( (thread_data_map & (1<<index)) == 0,
                "Unallocated index used");

    thread_data[index] = data;
}

#endif

// -------------------------------------------------------------------------

#ifdef CYGVAR_KERNEL_THREADS_NAME

inline char *Cyg_Thread::get_name()
{
    return name;
}

#endif

// -------------------------------------------------------------------------

#ifdef CYGVAR_KERNEL_THREADS_LIST

inline Cyg_Thread *Cyg_Thread::get_list_head()
{
    return thread_list?thread_list->list_next:0;
}
    
inline Cyg_Thread *Cyg_Thread::get_list_next()
{
    return (this==thread_list)?0:list_next;
}

#endif


// -------------------------------------------------------------------------

#ifdef CYGPKG_KERNEL_EXCEPTIONS

inline void Cyg_Thread::register_exception(
    cyg_code                exception_number,       // exception number
    cyg_exception_handler   handler,                // handler function
    CYG_ADDRWORD            data,                   // data argument
    cyg_exception_handler   **old_handler,          // handler function
    CYG_ADDRWORD            *old_data               // data argument
    )
{
    self()->exception_control.register_exception(
        exception_number,
        handler,
        data,
        old_handler,
        old_data
        );
}

inline void Cyg_Thread::deregister_exception(
    cyg_code                exception_number        // exception number
    )
{
    self()->exception_control.deregister_exception(
        exception_number
        );
}

#endif

//==========================================================================
// Inlines for Cyg_ThreadTimer class

// -------------------------------------------------------------------------
#if defined(CYGFUN_KERNEL_THREADS_TIMER) && defined(CYGVAR_KERNEL_COUNTERS_CLOCK)

inline Cyg_ThreadTimer::Cyg_ThreadTimer(
    Cyg_Thread  *th
    )
    : Cyg_Alarm(Cyg_Clock::real_time_clock,
                &alarm,
                CYG_ADDRWORD(this)
                )
{
    thread = th;
}

#endif

//==========================================================================
// Inlines for Cyg_ThreadQueue class


inline void Cyg_ThreadQueue::enqueue(Cyg_Thread *thread)
{
    Cyg_ThreadQueue_Implementation::enqueue(thread);
}

// -------------------------------------------------------------------------

inline Cyg_Thread *Cyg_ThreadQueue::highpri()
{
    return Cyg_ThreadQueue_Implementation::highpri();
}

// -------------------------------------------------------------------------

inline Cyg_Thread *Cyg_ThreadQueue::dequeue()
{
    return Cyg_ThreadQueue_Implementation::dequeue();
}

// -------------------------------------------------------------------------

inline void Cyg_ThreadQueue::remove(Cyg_Thread *thread)
{
    Cyg_ThreadQueue_Implementation::remove(thread);
}

// -------------------------------------------------------------------------

inline cyg_bool Cyg_ThreadQueue::empty()
{
    return Cyg_ThreadQueue_Implementation::empty();
}

// -------------------------------------------------------------------------

#ifdef CYGPKG_KERNEL_THREADS_DESTRUCTORS

#ifndef CYGSEM_KERNEL_THREADS_DESTRUCTORS_PER_THREAD
# include <cyg/kernel/sched.inl>
#endif

// Add and remove destructors. Returns true on success, false on failure.
inline cyg_bool
Cyg_Thread::add_destructor( destructor_fn fn, CYG_ADDRWORD data )
{
    cyg_ucount16 i;
#ifndef CYGSEM_KERNEL_THREADS_DESTRUCTORS_PER_THREAD
    Cyg_Scheduler::lock();
#endif
    for (i=0; i<CYGNUM_KERNEL_THREADS_DESTRUCTORS; i++) {
        if (NULL == destructors[i].fn) {
            destructors[i].data = data;
            destructors[i].fn = fn;
#ifndef CYGSEM_KERNEL_THREADS_DESTRUCTORS_PER_THREAD
            Cyg_Scheduler::unlock();
#endif
            return true;
        }
    }
#ifndef CYGSEM_KERNEL_THREADS_DESTRUCTORS_PER_THREAD
    Cyg_Scheduler::unlock();
#endif
    return false;
}

inline cyg_bool
Cyg_Thread::rem_destructor( destructor_fn fn, CYG_ADDRWORD data )
{
    cyg_ucount16 i;
#ifndef CYGSEM_KERNEL_THREADS_DESTRUCTORS_PER_THREAD
    Cyg_Scheduler::lock();
#endif
    for (i=0; i<CYGNUM_KERNEL_THREADS_DESTRUCTORS; i++) {
        if (destructors[i].fn == fn && destructors[i].data == data) {
            destructors[i].fn = NULL;
#ifndef CYGSEM_KERNEL_THREADS_DESTRUCTORS_PER_THREAD
            Cyg_Scheduler::unlock();
#endif
            return true;
        }
    }
#ifndef CYGSEM_KERNEL_THREADS_DESTRUCTORS_PER_THREAD
    Cyg_Scheduler::unlock();
#endif
    return false;
}
#endif

// -------------------------------------------------------------------------

#endif // ifndef CYGONCE_KERNEL_THREAD_INL
// EOF thread.inl