Changeset 9129a84 for src/libcfa
- Timestamp:
- Nov 28, 2016, 4:02:45 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:
- 1f44196
- Parents:
- f773f67
- Location:
- src/libcfa
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/libcfa/assert ¶
rf773f67 r9129a84 22 22 #define __STRINGIFY__(str) #str 23 23 #define __VSTRINGIFY__(str) __STRINGIFY__(str) 24 #define assertf(expr, fmt, ...) ((expr) ? static_cast<void>(0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ ))24 #define assertf(expr, fmt, ...) ((expr) ? ((void)2) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ )) 25 25 26 26 void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) __attribute__((noreturn)); -
TabularUnified src/libcfa/concurrency/threads ¶
rf773f67 r9129a84 17 17 #define __THREADS_H__ 18 18 19 #include <stdbool.h> 19 20 20 21 struct coroutine { 21 int blarg; 22 coroutine* last; 23 const char* name; 24 bool notHalted; 22 25 }; 26 27 void ?{}(coroutine* this); 23 28 24 29 trait coroutine_t(dtype T) { … … 26 31 }; 27 32 28 forall(dtype T | coroutine_t(T)) 29 void suspend(T* cor); 33 void suspend(void); 30 34 31 35 forall(dtype T | coroutine_t(T)) -
TabularUnified src/libcfa/concurrency/threads.c ¶
rf773f67 r9129a84 1 1 #include "threads" 2 #include "assert" 2 3 3 forall(dtype T | coroutine_t(T)) 4 void suspend(T* cor) { 4 #include <stddef.h> 5 5 6 #include <fstream> 7 8 static coroutine main_coroutine; 9 static coroutine* current_coroutine = &main_coroutine; 10 11 void ctxSwitchDirect(void* src, void* dst) { 12 current_coroutine = dst; 13 } 14 15 coroutine* this_coroutine() { 16 return current_coroutine; 17 } 18 19 void ?{}(coroutine* this) 20 { 21 this->last = NULL; 22 this->name = "A Coroutine"; 23 this->notHalted = true; 24 } 25 26 void suspend() { 27 coroutine* src = this_coroutine(); // optimization 28 29 assertf( src->last == (coroutine*)0, 30 "Attempt to suspend coroutine %.256s (%p) that has never been resumed.\n" 31 "Possible cause is a suspend executed in a member called by a coroutine user rather than by the coroutine main.", 32 src->name, src ); 33 assertf( src->last->notHalted, 34 "Attempt by coroutine %.256s (%p) to suspend back to terminated coroutine %.256s (%p).\n" 35 "Possible cause is terminated coroutine's main routine has already returned.", 36 src->name, src, src->last->name, src->last ); 37 38 ctxSwitchDirect( src, src->last ); 6 39 } 7 40 8 41 forall(dtype T | coroutine_t(T)) 9 42 void resume(T* cor) { 43 coroutine* src = this_coroutine(); // optimization 44 coroutine* dst = this_coroutine(cor); 10 45 46 if ( src != dst ) { // not resuming self ? 47 assertf( dst->notHalted , 48 "Attempt by coroutine %.256s (%p) to resume terminated coroutine %.256s (%p).\n" 49 "Possible cause is terminated coroutine's main routine has already returned.", 50 src->name, src, dst->name, dst ); 51 dst->last = src; // set last resumer 52 } // if 53 ctxSwitchDirect( src, dst ); // always done for performance testing 11 54 }
Note: See TracChangeset
for help on using the changeset viewer.