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

Side by Side Diff: samples/todomvc/todomvc_shared.cc

Issue 2035023003: Remove service-compiler related code. (Closed) Base URL: git@github.com:dartino/sdk.git@master
Patch Set: Created 4 years, 6 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/todomvc/todomvc_shared.h ('k') | samples/todomvc/unix_ia32_hack.c » ('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 Dartino 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 "todomvc_shared.h" // NOLINT(build/include)
6
7 #include <pthread.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 #include "include/dartino_api.h"
12 #include "include/service_api.h"
13
14 static const int kDone = 1;
15
16 static pthread_mutex_t mutex;
17 static pthread_cond_t cond;
18 static int status = 0;
19
20 static void ChangeStatusAndNotify(int new_status) {
21 pthread_mutex_lock(&mutex);
22 status = new_status;
23 pthread_cond_signal(&cond);
24 pthread_mutex_unlock(&mutex);
25 }
26
27 static void WaitForStatus(int expected) {
28 pthread_mutex_lock(&mutex);
29 while (expected != status) pthread_cond_wait(&cond, &mutex);
30 pthread_mutex_unlock(&mutex);
31 }
32
33 static void* DartThreadEntry(void* arg) {
34 const char* path = static_cast<char*>(arg);
35 DartinoSetup();
36 DartinoProgram program = DartinoLoadSnapshotFromFile(path);
37 if (DartinoRunMain(program, 0, NULL) != 0) {
38 printf("Failed to run snapshot: %s\n", path);
39 exit(1);
40 }
41 DartinoDeleteProgram(program);
42 DartinoTearDown();
43 ChangeStatusAndNotify(kDone);
44 return NULL;
45 }
46
47 static void RunSnapshotInNewThread(char* path) {
48 pthread_t thread;
49 int result = pthread_create(&thread, NULL, DartThreadEntry, path);
50 if (result != 0) {
51 perror("Failed to start thread");
52 exit(1);
53 }
54 }
55
56 void SetupTodoMVC(int argc, char** argv) {
57 pthread_mutex_init(&mutex, NULL);
58 pthread_cond_init(&cond, NULL);
59 ServiceApiSetup();
60 RunSnapshotInNewThread(argv[1]);
61 }
62
63 void TearDownTodoMVC() {
64 WaitForStatus(kDone);
65 ServiceApiTearDown();
66 }
OLDNEW
« no previous file with comments | « samples/todomvc/todomvc_shared.h ('k') | samples/todomvc/unix_ia32_hack.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698