3 static void player_cleanup(void *arg)
7 frsh_thread_get_vres_id(fosa_thread_self(), &vres);
8 frsh_contract_cancel(vres);
11 void *player(void *thread_args)
13 struct player_args *args = (struct player_args*) thread_args;
15 frsh_rel_time_t player_budget, player_period;
16 frsh_contract_t player_contract;
17 frsh_vres_id_t player_vres;
22 fprintf(stdout, "== Waiting for being bound...\n");
25 "== Starting playing %s, with %d/%d CPU bandwidth\n",
26 args->file, args->budget, args->period);
28 player_budget = fosa_usec_to_rel_time(args->budget);
29 player_period = fosa_usec_to_rel_time(args->period);
30 PXW(frsh_contract_init(&player_contract));
31 PXW(frsh_contract_set_basic_params(&player_contract,
34 FRSH_WT_INDETERMINATE,
36 PXW(frsh_contract_set_resource_and_label(&player_contract,
40 fprintf(stdout, "== Player contract initialized\n");
42 PXW(frsh_contract_negotiate(&player_contract, &player_vres));
43 fprintf(stdout, "== Player contract negotiated\n");
45 pthread_cleanup_push(player_cleanup, NULL);
47 PXW(frsh_thread_bind(player_vres, fosa_thread_self()));
48 fprintf(stdout, "== Player thread bound to its contract\n");
50 snprintf(cmd, 255, PLAYER_BINARY PLAYER_ARGS " %s", args->file);
52 fprintf(stdout, "== Issuing command:\n %s\n", cmd);
56 if (WIFEXITED(status))
57 fprintf(stdout, "== Playback finished normally\n");
58 else if (WIFSIGNALED(status))
59 fprintf(stdout, "== Playback aborted\n");
61 pthread_cleanup_pop(1);
63 pthread_exit(EXIT_SUCCESS);
66 int main(int argc, char *argv[])
68 pthread_t player_thread;
69 pthread_attr_t player_attr;
70 struct player_args args;
75 fprintf(stderr, "USAGE:\n"
76 "%s -b budget_usec -p period_usec -f file\n\n",
78 error(EXIT_FAILURE, EINVAL, "Wrong argument count");
81 while ((opt = getopt(argc, argv, "b:p:f:")) != -1) {
84 args.budget = atoi(optarg);
87 args.period = atoi(optarg);
90 strncpy(args.file, optarg, sizeof(args.file));
98 fprintf(stdout, "FRSH initialized\n");
100 terror = pthread_attr_init(&player_attr);
101 if (terror) assert_perror(errno);
103 terror = pthread_create(&player_thread, &player_attr, player, (void*) &args);
104 if (terror) assert_perror(errno);
105 fprintf(stdout, "FRSH thread created, waiting for its termination...\n");
107 terror = pthread_join(player_thread, NULL);
108 if (terror) assert_perror(errno);
109 fprintf(stdout, "FRSH thread ended. Exiting\n\n");