/* depend: */
/* cflags: */
/* linker: main.o mtime.o stat.o -lm -lpthread -lrt */
+/* winlnk: main.o mtime.o stat.o -lm -lpthread */
#include <pthread.h>
#include <stdio.h>
/* depend: */
/* cflags: */
/* linker: mtime.o -lpthread */
+/* winlnk: mtime.o -lpthread */
#define _GNU_SOURCE
#include <assert.h>
void generate_matrix (matrix_t *matrix)
{
- double base = 10 * drand48 () - 5;
+ double base = 10 * rand () / (double)RAND_MAX - 5;
for (int i = 0; i < matrix->n; i++) {
for (int j = 0; j < matrix->n; j++) {
double val = base * (rand () - RAND_MAX / 2) / (double)RAND_MAX;
/* real-time process */
struct sched_param param = {0};
- if (sched_getparam (0, ¶m) != 0) {
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
+ if (sched_getparam (0, ¶m) != 0) {
fprintf (stderr, "error: sched_getparam\n");
return 1;
}
+#endif
param.sched_priority = sched_rt_prio;
int rc = sched_setscheduler (0, SCHED_FIFO, ¶m); /* non-preemptive */
// int rc = sched_setscheduler (0, SCHED_RR, ¶m); /* preemptive */
/* main process */
- if (do_clock) {
+ if (do_clock) {
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
cpu_set_t cpu_mask;
CPU_ZERO (&cpu_mask);
CPU_SET (0, &cpu_mask);
fprintf (stderr, "error: sched_setaffinity\n");
return 1;
}
+#endif
while (do_clock--) {
printf ("\r");
printf ("Tics clock: %.0fMHz", estimate_tics_clock () / 1e6);
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
#include <sys/wait.h>
+#endif
#include <unistd.h>
#include "stat.h"
void *launch (void *arg)
{
launch_param_t *param = (launch_param_t *)arg;
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
cpu_set_t cpu_mask;
if (sched_getaffinity (0, sizeof (cpu_set_t), &cpu_mask) != 0) {
fprintf (stderr, "error: sched_getaffinity\n");
RETURN (mode, 1);
}
}
+#endif
if (param->synchro) {
switch (param->target) {
case 0:
/* real-time process */
+#ifdef _WIN32 /* Windows */
+ fprintf (stderr, "No RT scheduling on Windows\n");
+#else /* Linux */
struct sched_param param = {0};
if (sched_getparam (0, ¶m) != 0) {
fprintf (stderr, "error: sched_getparam\n");
fprintf (stderr, "error: sched_setscheduler\n");
return 1;
}
+#endif
/* main process */
}
break;
case 1:
+#ifdef _WIN32 /* Windows */
+ fprintf (stderr, "process mode not supported on Windows\n");
+ return 1;
+#else /* Linux */
printf ("process mode\n");
sem_sig = sem_open (SEMSIG, O_CREAT, S_IRUSR|S_IWUSR, 0);
sem_act = sem_open (SEMACT, O_CREAT, S_IRUSR|S_IWUSR, 0);
}
}
}
+#endif
break;
case 2:
printf ("ping mode\n");
#include "mtime.h"
static int rc = 0;
-#define RETURN(m, v) do { rc = (v); if ((m) == 0) pthread_exit (NULL); else return NULL; } while (0)
+#define RETURN(m, v) rc = (v); if ((m) == 0) pthread_exit (NULL); return NULL;
int init (dts_t *buffer, int nb, int mode);
/* depend: */
/* cflags: */
/* linker: main.o mtime.o stat.o -lm -lpthread -lrt */
+/* winlnk: main.o mtime.o stat.o -lm -lpthread */
#include <pthread.h>
#include <semaphore.h>
/* depend: */
/* cflags: */
/* linker: main.o mtime.o stat.o -lm -lpthread -lrt */
+/* winlnk: main.o mtime.o stat.o -lm -lpthread */
#include <errno.h>
#include <fcntl.h>
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
#include <mqueue.h>
+#endif
#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
/* communication through mq */
if (current_mode == 1) {
+#ifdef _WIN32 /* Windows */
+ fprintf (stderr, "process mode not supported on Windows\n");
+ return 1;
+#else /* Linux */
struct mq_attr mq_attr = { 0 };
mq_attr.mq_flags = 0;
mq_attr.mq_maxmsg = 1;
return 1;
}
mq_close (mq);
+#endif
}
return 0;
{
/* open mq for communication betwen process */
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
mqd_t mq = (current_mode == 1) ? mq_open (MQCOM, O_RDONLY) : -2;
if (mq == -1) {
fprintf (stderr, "ping error: mq_open\n");
RETURN (current_mode, 1);
}
+#endif
/* main loop */
/* done by thread pong */
break;
case 1:
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
if (mq_receive (mq, (char *)&ts2, sizeof (ts2), NULL) == -1) {
fprintf (stderr, "pong error: mq_receive (%d)\n", i);
RETURN (current_mode, 1);
}
if (i != -1) deltas[i] = diff_timestamp (&ts2, &ts1);
+#endif
break;
case 2:
/* to do */
/* close communication between process */
if (current_mode == 1) {
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
mq_close (mq);
+#endif
}
RETURN (current_mode, 0);
{
/* open mq for communication betwen process */
-
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
mqd_t mq = (current_mode == 1) ? mq_open (MQCOM, O_WRONLY) : -2;
if (mq == -1) {
fprintf (stderr, "pong error: mq_open\n");
RETURN (current_mode, 1);
}
+#endif
/* main loop */
if (i != -1) deltas[i] = diff_timestamp (&ts2, &ts1);
break;
case 1:
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
if (mq_send (mq, (char *)&ts2, sizeof (ts2), 0) == -1) {
fprintf (stderr, "ping error: mq_send (%d)\n", i);
RETURN (current_mode, 1);
}
+#endif
break;
case 2:
/* can't append */
/* close communication between process */
if (current_mode == 1) {
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
mq_close (mq);
+#endif
}
RETURN (current_mode, 0);
/* close queue */
if (current_mode == 1) {
+#ifdef _WIN32 /* Windows */
+#else /* Linux */
if ((mq_unlink (MQCOM) != 0) && errno != ENOENT) {
fprintf (stderr, "error: mq_unlink\n");
}
+#endif
}
return rc;
/* depend: */
/* cflags: */
/* linker: main.o mtime.o stat.o -lm -lpthread -lrt */
+/* winlnk: main.o mtime.o stat.o -lm -lpthread */
#include <pthread.h>
#include <semaphore.h>
/* depend: */
/* cflags: */
/* linker: main.o mtime.o stat.o -lm -lpthread -lrt */
+/* winlnk: main.o mtime.o stat.o -lm -lpthread */
#include <pthread.h>
#include <semaphore.h>