Changes in src/libcfa/concurrency/invoke.c [1c273d0:cb0e6de]
- File:
-
- 1 edited
-
src/libcfa/concurrency/invoke.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/invoke.c
r1c273d0 rcb0e6de 29 29 30 30 extern void __suspend_internal(void); 31 extern void __leave_thread_monitor( struct thread_desc * this ); 32 extern void disable_interrupts(); 33 extern void enable_interrupts( const char * ); 31 extern void __leave_monitor_desc( struct monitor_desc * this ); 34 32 35 33 void CtxInvokeCoroutine( 36 void (*main)(void *), 37 struct coroutine_desc *(*get_coroutine)(void *), 34 void (*main)(void *), 35 struct coroutine_desc *(*get_coroutine)(void *), 38 36 void *this 39 37 ) { … … 58 56 59 57 void CtxInvokeThread( 60 void (*dtor)(void *), 61 void (*main)(void *), 62 struct thread_desc *(*get_thread)(void *), 58 void (*dtor)(void *), 59 void (*main)(void *), 60 struct thread_desc *(*get_thread)(void *), 63 61 void *this 64 62 ) { 65 // First suspend, once the thread arrives here,66 // the function pointer to main can be invalidated without risk67 63 __suspend_internal(); 68 64 69 // Fetch the thread handle from the user defined thread structure70 65 struct thread_desc* thrd = get_thread( this ); 66 struct coroutine_desc* cor = &thrd->cor; 67 struct monitor_desc* mon = &thrd->mon; 68 cor->state = Active; 71 69 72 // Officially start the thread by enabling preemption 73 enable_interrupts( __PRETTY_FUNCTION__ ); 74 75 // Call the main of the thread 70 // LIB_DEBUG_PRINTF("Invoke Thread : invoking main %p (args %p)\n", main, this); 76 71 main( this ); 77 72 78 // To exit a thread we must : 79 // 1 - Mark it as halted 80 // 2 - Leave its monitor 81 // 3 - Disable the interupts 82 // The order of these 3 operations is very important 83 __leave_thread_monitor( thrd ); 73 __leave_monitor_desc( mon ); 84 74 85 75 //Final suspend, should never return … … 90 80 91 81 void CtxStart( 92 void (*main)(void *), 93 struct coroutine_desc *(*get_coroutine)(void *), 94 void *this, 82 void (*main)(void *), 83 struct coroutine_desc *(*get_coroutine)(void *), 84 void *this, 95 85 void (*invoke)(void *) 96 86 ) { … … 118 108 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke; 119 109 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520 120 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7 110 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7 121 111 122 112 #elif defined( __x86_64__ ) … … 138 128 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[1] = invoke; 139 129 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520 140 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7 130 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7 141 131 #else 142 132 #error Only __i386__ and __x86_64__ is supported for threads in cfa
Note:
See TracChangeset
for help on using the changeset viewer.