Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: samples/myapi/myapi_client.cc

Issue 1209033003: Work in progres, please take a look and give early feedback if this is the way we want to structure… (Closed) Base URL: git@github.com:dart-lang/fletch.git@master
Patch Set: address comments Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « samples/myapi/myapi.gyp ('k') | samples/myapi/myapi_impl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE.md file.
4
5 #include "generated/myapi.h"
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10
11 static void Setup(char* path);
12 static void TearDown();
13
14 int main(int argc, char** argv) {
15 Setup(argv[1]);
16
17 MyApi api = MyApi::create();
18 MyObject m0 = api.foo();
19 MyObject m1 = api.foo();
20 m0.funk(m1);
21 m1.funk(m0);
22 api.destroy();
23
24 TearDown();
25 }
26
27
28 // -----------------------------------------------------------------------
29
30 #include <pthread.h>
31
32 #include "include/fletch_api.h"
33 #include "include/service_api.h"
34
35 static const int kDone = 1;
36
37 static pthread_mutex_t mutex;
38 static pthread_cond_t cond;
39 static int status = 0;
40
41 static void ChangeStatusAndNotify(int new_status) {
42 pthread_mutex_lock(&mutex);
43 status = new_status;
44 pthread_cond_signal(&cond);
45 pthread_mutex_unlock(&mutex);
46 }
47
48 static void WaitForStatus(int expected) {
49 pthread_mutex_lock(&mutex);
50 while (expected != status) pthread_cond_wait(&cond, &mutex);
51 pthread_mutex_unlock(&mutex);
52 }
53
54 static void* FletchThreadEntry(void* arg) {
55 const char* path = static_cast<char*>(arg);
56 FletchSetup();
57 FletchRunSnapshotFromFile(path);
58 FletchTearDown();
59 ChangeStatusAndNotify(kDone);
60 return NULL;
61 }
62
63 static void RunSnapshotInNewThread(char* path) {
64 pthread_t thread;
65 int result = pthread_create(&thread, NULL, FletchThreadEntry, path);
66 if (result != 0) {
67 perror("Failed to start thread");
68 exit(1);
69 }
70 }
71
72 void Setup(char* path) {
73 pthread_mutex_init(&mutex, NULL);
74 pthread_cond_init(&cond, NULL);
75 ServiceApiSetup();
76 RunSnapshotInNewThread(path);
77 }
78
79 void TearDown() {
80 WaitForStatus(kDone);
81 ServiceApiTearDown();
82 }
83
OLDNEW
« no previous file with comments | « samples/myapi/myapi.gyp ('k') | samples/myapi/myapi_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698