File: fiber.h

package info (click to toggle)
massivethreads 1.02-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,924 kB
  • sloc: ansic: 27,814; sh: 4,559; cpp: 3,334; javascript: 1,799; makefile: 1,745; python: 523; asm: 373; perl: 118; lisp: 9
file content (32 lines) | stat: -rw-r--r-- 633 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef _FIBER_H_
#define _FIBER_H_

#include <stdio.h>
#include <stdint.h>
#include <unistd.h>

#define MAX_FIBERS 1024
#define STACK_SIZE 1024*1024

static inline uint64_t get_rdtsc(void)
{
#if defined __i386__ || defined __x86_64__
  uint32_t hi, lo;
  asm volatile("lfence\nrdtsc\n" : "=a"(lo),"=d"(hi));
  return ((uint64_t)hi)<<32 | lo;
#elif __sparc__
  uint64_t tick;
  asm volatile("rd %%tick, %0" : "=r" (tick));
  return tick;
#else
#error "get_rdtsc() not implemented"
  return 0;
#endif
}

void fiber_init(void);
int fiber_spawn(void (*func)(void));
void fiber_yield(void);
int fiber_wait(void);

#endif /* _FIBER_H_ */