|
|
@@ -1,12 +1,55 @@
|
|
|
#include <stdio.h>
|
|
|
+#include <stdbool.h>
|
|
|
+#include <stdint.h>
|
|
|
|
|
|
#define IMP
|
|
|
#include "./future.h"
|
|
|
|
|
|
+struct counter {
|
|
|
+ uint32_t count;
|
|
|
+ uint32_t end;
|
|
|
+};
|
|
|
+
|
|
|
+void *counter_future(void *env, void *data);
|
|
|
+
|
|
|
int
|
|
|
main(int argc, char *argv[])
|
|
|
{
|
|
|
- printf("Hello World!\n");
|
|
|
+ struct future counter_f1 = {0};
|
|
|
+ struct future counter_f2 = {0};
|
|
|
+ struct counter c1 = {0, 5};
|
|
|
+ struct counter c2 = {5, 10};
|
|
|
+
|
|
|
+ counter_f1.f = &counter_future;
|
|
|
+ counter_f1.env = &c1;
|
|
|
+ counter_f2.f = &counter_future;
|
|
|
+ counter_f2.env = &c2;
|
|
|
+
|
|
|
+ while ( true ) {
|
|
|
+ void *r1 = NULL;
|
|
|
+ void *r2 = NULL;
|
|
|
+ r1 = future_poll(counter_f1, NULL);
|
|
|
+ r2 = future_poll(counter_f2, NULL);
|
|
|
+ if ( r1 != NULL && r2 != NULL ) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
(void) argc; (void) argv;
|
|
|
return 0;
|
|
|
}
|
|
|
+
|
|
|
+void *
|
|
|
+counter_future(void *env, void *data)
|
|
|
+{
|
|
|
+ struct counter *this = (struct counter *) env;
|
|
|
+ if ( this->count >= this->end ) {
|
|
|
+ return &this->count;
|
|
|
+ }
|
|
|
+
|
|
|
+ printf("Counted: %d\n", this->count);
|
|
|
+ ++this->count;
|
|
|
+
|
|
|
+ (void) data;
|
|
|
+ return NULL;
|
|
|
+}
|