Changeset d9c44c3
- Timestamp:
- Dec 6, 2016, 4:16:47 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- fa66f4e
- Parents:
- e4745d7a
- Location:
- src
- Files:
-
- 1 added
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/assert
re4745d7a rd9c44c3 17 17 #define __ASSERT_H__ 18 18 19 #ifdef __CFORALL__ 19 20 extern "C" { 21 #endif //__CFORALL__ 22 20 23 #include <assert.h> 21 24 … … 29 32 void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) __attribute__((noreturn)); 30 33 #endif 31 } 34 35 #ifdef __CFORALL__ 36 } // extern "C" 37 #endif //__CFORALL__ 32 38 33 39 #endif // __ASSERT_H__ -
src/libcfa/concurrency/invoke.c
re4745d7a rd9c44c3 4 4 #include <stdio.h> 5 5 6 #include "libhdr.h" 6 7 #include "invoke.h" 7 8 … … 18 19 void __invokeCoroutine__F_P9scoVtablePv__1(struct coVtable *vtable, void* vthis) 19 20 { 20 printf("Invoke : Received %p (v %p)\n", vthis, vtable);21 LIB_DEBUG_PRINTF("Invoke : Received %p (v %p)\n", vthis, vtable); 21 22 22 23 struct coroutine* cor = vtable->this_coroutine(vthis); … … 34 35 void (*invoke)(struct coVtable *, void *) 35 36 ) { 36 37 #if ! defined( __x86_64__ ) && ! defined( __i386__ ) 38 #error Only __x86_64__ and __i386__ is supported for threads in cfa 39 #endif 40 41 #if defined( __U_SWAPCONTEXT__ ) 42 #error __U_SWAPCONTEXT__ should not be defined for __x86_64__ 43 #endif 37 LIB_DEBUG_PRINTF("StartCoroutine : Passing in %p (v %p) to %p\n", vthis, vtable, invoke); 44 38 45 39 struct coVtable * vtable = get_vtable( vthis ); … … 47 41 struct coStack_t* stack = &this->stack; 48 42 43 #if defined( __i386__ ) 44 45 struct FakeStack { 46 void *fixedRegisters[3]; // fixed registers ebx, edi, esi (popped on 1st uSwitch, values unimportant) 47 void *rturn; // where to go on return from uSwitch 48 void *dummyReturn; // fake return compiler would have pushed on call to uInvoke 49 void *argument[2]; // for 16-byte ABI, 16-byte alignment starts here 50 void *padding[2]; // padding to force 16-byte alignment, as "base" is 16-byte aligned 51 }; 52 53 ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack ); 54 ((struct machine_context_t *)stack->context)->FP = NULL; // terminate stack with NULL fp 55 56 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL; 57 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[0] = vtable; // argument to invoke 58 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->argument[1] = vthis; // argument to invoke 59 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->rturn = invoke; 60 61 #elif defined( __x86_64__ ) 62 49 63 struct FakeStack { 50 64 void *fixedRegisters[5]; // fixed registers rbx, r12, r13, r14, r15 51 65 void *rturn; // where to go on return from uSwitch 52 66 void *dummyReturn; // NULL return address to provide proper alignment 53 }; // FakeStack67 }; 54 68 55 69 ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack ); 56 70 ((struct machine_context_t *)stack->context)->FP = NULL; // terminate stack with NULL fp 57 58 fprintf(stderr, "StartCoroutine : Passing in %p (v %p) to %p\n", vthis, vtable, invoke);59 71 60 72 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->dummyReturn = NULL; … … 63 75 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[1] = vthis; 64 76 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fixedRegisters[2] = invoke; 77 #else 78 #error Only __i386__ and __x86_64__ is supported for threads in cfa 79 #endif 65 80 } -
src/libcfa/concurrency/threads.c
re4745d7a rd9c44c3 166 166 coroutine* dst = this_coroutine(cor); 167 167 168 fprintf(stderr, "Resuming %p from %p\n", dst, src);169 168 if ( src != dst ) { // not resuming self ? 170 169 assertf( dst->notHalted , … … 172 171 "Possible cause is terminated coroutine's main routine has already returned.", 173 172 src->name, src, dst->name, dst ); 174 fprintf(stderr, "Assigning last pointer\n");175 173 dst->last = src; // set last resumer 176 174 } // if -
src/libcfa/libhdr/libdebug.h
re4745d7a rd9c44c3 25 25 #endif 26 26 27 #ifdef __CFA_DEBUG_PRINT__ 28 #define LIB_DEBUG_PRINTF(...) printf (__VA_ARGS__) 29 #define LIB_DEBUG_FPRINTF(...) fprintf (stderr, __VA_ARGS__) 30 #else 31 #define LIB_DEBUG_PRINTF(...) ((void)0) 32 #define LIB_DEBUG_FPRINTF(...) ((void)0) 33 #endif 34 27 35 #endif //__LIB_DEBUG_H__ 28 36 -
src/libcfa/stdhdr/assert.h
re4745d7a rd9c44c3 14 14 // 15 15 16 #ifdef __CFORALL__ 16 17 extern "C" { 17 #include_next <assert.h> // has internal check for multiple expansion 18 #endif //__CFORALL__ 19 20 // has internal check for multiple expansion 21 #include_next <assert.h> 22 23 #ifdef __CFORALL__ 18 24 } // extern "C" 25 #endif //__CFORALL__ 19 26 20 27 // Local Variables: // -
src/tests/coroutine.c
re4745d7a rd9c44c3 28 28 29 29 void co_main(Fibonacci* this) { 30 #ifdef MORE_DEBUG 30 31 sout | "Starting main of coroutine " | this | endl; 31 32 sout | "Started from " | this_coroutine(this)->last | endl; 33 #endif 32 34 int fn1, fn2; // retained between resumes 33 35 this->fn = 0; … … 62 64 63 65 int main() { 64 Fibonacci f1; 65 sout | "User coroutine : " | &f1 | endl; 66 Fibonacci f1, f2; 67 #ifdef MORE_DEBUG 68 sout | "User coroutines : " | &f1 | ' ' | &f1 | endl; 69 #endif 66 70 for ( int i = 1; i <= 10; i += 1 ) { 67 sout | next(&f1) | endl;71 sout | next(&f1) | ' ' | next(&f2) | endl; 68 72 } 69 73
Note: See TracChangeset
for help on using the changeset viewer.