17 #ifndef LEANSDR_FRAMEWORK_H    18 #define LEANSDR_FRAMEWORK_H    30 #define VERSION "undefined"    36 void fatal(
const char *s);
    37 void fail(
const char *s);
    49 static const int MAX_PIPES = 64;
    50 static const int MAX_RUNNABLES = 64;
    51 static const int MAX_READERS = 8;
    65     virtual void dump(std::size_t *total_bufs)
   103         fprintf(stderr, 
"Deallocating %s !\n", name);
   134         if (npipes == MAX_PIPES)
   141         if (nrunnables == MAX_RUNNABLES)
   142             fail(
"MAX_RUNNABLES");
   143         runnables[nrunnables++] = r;
   148         for (
int i = 0; 
i < nrunnables; ++
i)
   154         unsigned long long prev_hash = 0;
   159             unsigned long long h = 
hash();
   168         for (
int i = 0; 
i < nrunnables; ++
i)
   169             runnables[
i]->shutdown();
   174         unsigned long long h = 0;
   175         for (
int i = 0; 
i < npipes; ++
i)
   176             h += (1 + 
i) * pipes[
i]->
hash();
   182         fprintf(stderr, 
"\n");
   183         std::size_t total_bufs = 0;
   184         for (
int i = 0; 
i < npipes; ++
i)
   185             pipes[
i]->
dump(&total_bufs);
   186         fprintf(stderr, 
"Total buffer memory: %ld KiB\n",
   187                 (
unsigned long)total_bufs / 1024);
   195         sch->add_runnable(
this);
   202 template <
typename T>
   229         if (nrd == MAX_READERS)
   230             fail(
"too many readers");
   238         for (
int i = 0; 
i < nrd; ++
i)
   241         memmove(buf, rd, (wr - rd) * 
sizeof(T));
   243         for (
int i = 0; 
i < nrd; ++
i)
   249         return total_written + total_read;
   252     void dump(std::size_t *total_bufs)
   254         if (total_written < 10000)
   255             fprintf(stderr, 
".%-16s : %4ld/%4ld", 
name, total_read,
   257         else if (total_written < 1000000)
   258             fprintf(stderr, 
".%-16s : %3ldk/%3ldk", 
name, total_read / 1000,
   259                     total_written / 1000);
   261             fprintf(stderr, 
".%-16s : %3ldM/%3ldM", 
name, total_read / 1000000,
   262                     total_written / 1000000);
   263         *total_bufs += (end - buf) * 
sizeof(T);
   264         unsigned long nw = end - wr;
   265         fprintf(stderr, 
" %6ld writable %c,", nw, (nw < min_write) ? 
'!' : 
' ');
   267         for (
int j = 0; j < nrd; ++j)
   270         fprintf(stderr, 
" %6d unread (", (
int)(wr - rd));
   271         for (
int j = 0; j < nrd; ++j)
   272             fprintf(stderr, 
" %d", (
int)(wr - rds[j]));
   273         fprintf(stderr, 
" )\n");
   280         fprintf(stderr, 
"Deallocating %s !\n", 
name);
   285 template <
typename T>
   300         return buf.
end - buf.
wr;
   310         if (buf.
wr + n > buf.
end)
   312             fprintf(stderr, 
"Bug: overflow to %s\n", buf.
name);
   328 template <
typename T>
   334 template <
typename T>
   337     return (p == NULL) || p->
writable() >= n;
   340 template <
typename T>
   347 template <
typename T>
   359         return buf.
wr - buf.
rds[id];
   369         if (buf.
rds[
id] + n > buf.
wr)
   371             fprintf(stderr, 
"Bug: underflow from %s\n", buf.
name);
   381 template <
typename T>
   398 template <
typename T>
   415 template <
typename T>
   422 inline long double gen_hypot(
long double x, 
long double y)
   427 template <
typename T>
   434 inline long double gen_atan2(
long double y, 
long double x)
   439 template <
typename T>
   440 T 
min(
const T &x, 
const T &y)
   442     return (x < y) ? x : y;
   445 template <
typename T>
   446 T 
max(
const T &x, 
const T &y)
   448     return (x < y) ? y : x;
   453 typedef unsigned char u8;
   454 typedef unsigned short u16;
   455 typedef unsigned long u32;
   456 typedef signed char s8;
   462 #endif // LEANSDR_FRAMEWORK_H 
pipereader(pipebuf< T > &_buf)
virtual ~runnable_common()
void add_pipe(pipebuf_common *p)
Fixed< IntType, IntBits > abs(Fixed< IntType, IntBits > const &x)
runnable(scheduler *_sch, const char *name)
virtual ~pipebuf_common()
runnable_common(const char *_name)
pipewriter(pipebuf< T > &_buf, unsigned long min_write=1)
virtual void dump(std::size_t *total_bufs)
pipebuf(scheduler *sch, const char *name, unsigned long size)
void opt_write(pipewriter< T > *p, T val)
bool opt_writable(pipewriter< T > *p, int n=1)
unsigned long long hash()
void written(unsigned long n)
pipewriter< T > * opt_writer(pipebuf< T > *buf, unsigned long min_write=1)
void fatal(const char *s)
pipebuf_common(const char *_name)
unsigned long total_written
void add_runnable(runnable_common *r)
void dump(std::size_t *total_bufs)
void read(unsigned long n)
T max(const T &x, const T &y)
window_placement * windows
T min(const T &x, const T &y)