Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c20a6bf

Browse filesBrowse files
committed
Fix the linux version.
timer compiles symbol lookup is clunky but works
1 parent cd89192 commit c20a6bf
Copy full SHA for c20a6bf

File tree

1 file changed

+31
-9
lines changed
Filter options

1 file changed

+31
-9
lines changed

‎stl/stl.c

Copy file name to clipboardExpand all lines: stl/stl.c
+31-9Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@
1313
#include <stdint.h>
1414

1515
#include <pthread.h>
16+
#ifdef __linux__
17+
#define __USE_GNU
1618
#include <dlfcn.h>
19+
#endif
1720
#include <semaphore.h>
21+
#ifdef __linux__
22+
#include <fcntl.h>
23+
#include <signal.h>
24+
#endif
1825
#include <time.h>
1926

2027
#include "stl.h"
@@ -66,7 +73,7 @@ typedef struct _timer {
6673
timer_t timer; // the POSIX timer handle
6774
char *name;
6875
int busy;
69-
} mutex;
76+
} timer;
7077
#endif
7178

7279
// local forward defines
@@ -81,7 +88,7 @@ static thread threadlist[NTHREADS];
8188
static mutex mutexlist[NMUTEXS];
8289
static semaphore semlist[NSEMAPHORES];
8390
#ifdef __linux__
84-
static semaphore semlist[NTIMERS];
91+
static timer timerlist[NTIMERS];
8592
#endif
8693
static int stl_debug_flag = 1;
8794
static int stl_cmdline_argc;
@@ -111,7 +118,7 @@ stl_initialize(int argc, char **argv)
111118
threadlist[0].busy = 1;
112119
threadlist[0].name = "user";
113120
threadlist[0].f = NULL; // no pointer to function entry
114-
threadlist[0].pthread = NULL; // it has no thread handle
121+
threadlist[0].pthread = (pthread_t)NULL; // it has no thread handle
115122
}
116123

117124
void
@@ -441,7 +448,7 @@ stl_timer_create(char *name, double interval, int32_t semid)
441448
LIST_LOCK
442449
for (p=timerlist, slot=0; slot<NTIMERS; slot++, p++) {
443450
if (p->busy == 0) {
444-
mp = p;
451+
tp = p;
445452
tp->busy++; // mark it busy
446453
break;
447454
}
@@ -455,8 +462,8 @@ stl_timer_create(char *name, double interval, int32_t semid)
455462
sevp.sigev_notify_attributes = NULL;
456463

457464
// post the semaphore
458-
sevp.sigev_notify_function = stl_sem_post;
459-
sevp.sigev.sigev_value.sival_int = semid;
465+
sevp.sigev_notify_function = (void (*)(union sigval))stl_sem_post;
466+
sevp.sigev_value.sival_int = semid;
460467

461468
status = timer_create(CLOCK_REALTIME, &sevp, &t);
462469
if (status)
@@ -466,14 +473,14 @@ stl_timer_create(char *name, double interval, int32_t semid)
466473
tp->name = stralloc(name);
467474

468475
// set the interval and activate the timer
469-
struct timerspect ts;
476+
struct timespec ts;
470477
ts.tv_sec = (int)interval;
471478
ts.tv_nsec = (interval - ts.tv_sec) * 1e9;
472479

473-
strict itimerspec its;
480+
struct itimerspec its;
474481
its.it_interval = ts; // interval
475482
its.it_value = ts; // initial value
476-
status = timer_settime(t, &ts, NULL);
483+
status = timer_settime(t, 0, &its, NULL);
477484
if (status)
478485
stl_error("timer settime failed %s", strerror(errno));
479486

@@ -540,5 +547,20 @@ stl_log(const char *fmt, ...)
540547
static void *
541548
get_functionptr(char *name)
542549
{
550+
#ifdef __linux__
551+
// this is ugly, but I can't figure how to make dlopen/dlsym work here
552+
FILE *fp;
553+
char cmd[4096];
554+
void *f;
555+
556+
snprintf(cmd, 4096, "nm %s | grep %s", stl_cmdline_argv[0], name);
557+
fp = popen(cmd, "r");
558+
fscanf(fp, "%x", &f);
559+
fclose(fp);
560+
printf("f 0x%x\n", f);
561+
562+
return f;
563+
#else
543564
return (void *)dlsym(RTLD_SELF, name);
565+
#endif
544566
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.