#include <pthread.h>
#include <signal.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <cthread.h>
#include "main.h"
#include "phil.h"
static struct app_info app_info = {0};
struct app_info *app = &app_info;
enum {
MAX_SCRN_ROWS = 43,
MAX_SCRN_COLS = 132,
COLUMN_WIDTH_0 = 18,
COLUMN_WIDTH_1 = 22
};
struct sched_args {
int row;
int col;
int sched_id;
};
static pthread_once_t once = PTHREAD_ONCE_INIT;
static int
_cthread_stats(
struct cthread *c,
void *arg,
int cthread_id)
{
struct sched_args *a = arg;
phil_info_t *phil;
int row, col, sched_id;
if (!phil)
return 0;
sched_id = a->sched_id;
row = a->row++;
col = a->col + ((sched_id - 1) * COLUMN_WIDTH_1);
if (phil->saved_doing != phil->doing) {
phil->solution == CLAIM_BASED ? " Claim-Based" : " Ticket-Based");
cne_printf_pos(4, col,
" [lightskyblue]----- [deeppink]%d [lightskyblue]-----[]",
sched_id);
switch(phil->doing) {
case PHIL_THINKING:
cne_printf_pos(row, col,
"[palegoldenrod]%s[]", doing_str[phil->doing]);
break;
case PHIL_WANTS_TO_EAT:
cne_printf_pos(row, col,
"[yellow]%s[]", doing_str[phil->doing]);
break;
case PHIL_WAIT_FORK:
cne_printf_pos(row, col,
"[teal]%s[]", doing_str[phil->doing]);
break;
case PHIL_EATING:
cne_printf_pos(row, col,
"[green]%s[]", doing_str[phil->doing]);
break;
case PHIL_ASK_RIGHT_FORK:
cne_printf_pos(row, col,
"[yellow]%s[]", doing_str[phil->doing]);
break;
case PHIL_WAIT_RIGHT_FORK:
cne_printf_pos(row, col,
"[red]%s[]", doing_str[phil->doing]);
break;
case PHIL_ASK_LEFT_FORK:
cne_printf_pos(row, col,
"[yellow]%s[]", doing_str[phil->doing]);
break;
case PHIL_WAIT_LEFT_FORK:
cne_printf_pos(row, col,
"[red]%s[]", doing_str[phil->doing]);
break;
case PHIL_GIVE_FORK:
cne_printf_pos(row, col,
"[blue]%s[]", doing_str[phil->doing]);
break;
case PHIL_UNKNOWN_STATE:
cne_printf_pos(row, col,
"%s", doing_str[phil->doing]);
break;
}
phil->saved_doing = phil->doing;
}
return 0;
}
static int
{
struct sched_args *a = arg;
a->row = 3;
a->col = COLUMN_WIDTH_0;
a->sched_id = sched_id;
}
static void
page_stats(void)
{
struct sched_args args = {0};
}
void
thread_func(void *arg)
{
pthread_setaffinity_np(pthread_self(),
sizeof(cpu_set_t), &thd->
group->
lcore_bitmap);
pthread_once(&once, phil_create_barriers);
CNE_RET(
"Unable to create cthread\n");
}
static int
{
return 0;
}
static void
my_exit(void)
{
fflush(stdout);
usleep(5000);
jcfg_thread_foreach(app->jinfo, _thread_quit, app);
app->quit = 1;
fflush(stdout);
usleep(5000);
}
static void
signal_handler(int sig)
{
if (sig == SIGUSR1)
return;
my_exit();
exit(0);
}
int
main(int argc, char **argv)
{
int lcore_id;
atexit(my_exit);
signal(SIGINT, signal_handler);
signal(SIGUSR1, signal_handler);
if (lcore_id < 0 || lcore_id > INT_MAX)
srand(0x19560630);
else
srand(0x19560630 + lcore_id * 333);
if (parse_args(argc, argv))
vt_cls();
cne_printf_pos(2, 1,
"*** [yellow]Dining Philosphers[], [magenta]PID: [lightskyblue]%d[]\n",
getpid());
sleep(1);
app->quit = 0;
while (!app->quit) {
page_stats();
sleep(1);
}
return 0;
}
CNDP_API int cne_init(void)
CNDP_API int cne_printf_pos(int16_t r, int16_t c, const char *fmt,...)
CNDP_API int cne_printf(const char *fmt,...)
CNDP_API int cne_lcore_id(void)
CNDP_API struct cthread * cthread_find(struct cthread_sched *s, int threadid)
CNDP_API struct cthread_sched * cthread_sched_find(int schedid)
CNDP_API int cthread_sched_foreach(sched_cb_t func, void *arg)
CNDP_API int cthread_foreach(struct cthread_sched *s, cthread_cb_t func, void *arg)
CNDP_API const char * cthread_get_name(struct cthread *ct)
CNDP_API void cthread_run(void)
CNDP_API struct cthread * cthread_create(const char *name, cthread_func_t func, void *arg)
void(* cthread_func_t)(void *)
CNDP_API int cthread_sched_create(size_t stack_size)
CNDP_API void * cthread_thread_private(struct cthread *c)