, K - , k.h :
typedef struct k0{..}*K;
, , , , . , kdb + . .
read(d, &data, PIPE_CAPACITY);
65536 , 8- . , segfault, , , 8 .
, , , eventfd, -. pipe().
:
#include <k.h>
#include <pthread.h>
#include <time.h>
#include <unistd.h>
static int fd[2];
static pthread_t thread;
static pthread_mutex_t lock;
K callback(int d)
{
K data = ktj(-KN, 0);
pthread_mutex_lock(&lock);
read(d, (void *)&data->j, sizeof(data->j));
pthread_mutex_unlock(&lock);
k(0, (char *)"callback", data, (K)0);
return (K)0;
}
void* loop()
{
while (1) {
struct timespec ts;
struct tm *time;
clock_gettime(CLOCK_REALTIME, &ts);
time = gmtime(&ts.tv_sec);
time->tm_sec = 0;
time->tm_min = 0;
time->tm_hour = 0;
ts.tv_sec -= mktime(time);
J data = (J)ts.tv_sec * 1000000000 + ts.tv_nsec;
pthread_mutex_lock(&lock);
write(fd[1], &data, sizeof(data));
pthread_mutex_unlock(&lock);
}
}
K1(init)
{
pthread_mutex_init(&lock, NULL);
pipe(fd);
sd1(fd[0], callback);
pthread_create(&thread, NULL, loop, NULL);
R ktj(0, 0);
}
, x.c,
$ gcc -Wall -shared -fPIC -I $(pwd) -DKXVER=3 x.c -o x.so
q:
callback:0N!
init:`:./x 2:(`init;1)
init[]