libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

threads.c (1555B)


      1 //
      2 
      3 #include "../release/libsheepyObject.h"
      4 
      5 #define internal static
      6 
      7 int argc; char **argv;
      8 
      9  // make a ring with a buffer of int elements
     10 #define chanMax   1000
     11 ringMake(chanT, int, chanMax);
     12 
     13 void emptyTask() {
     14 
     15   puts("the empty task");
     16 }
     17 
     18 void asWalkdir(void *AG) {
     19 
     20   cast(tpoolArgs *, args, AG)
     21 
     22   //puts(args->s);
     23   args->list = walkDirAll(args->s);
     24   //args->status = 1
     25   if (args->cb) {
     26     args->cb(args->cbArgs);
     27   }
     28 }
     29 
     30 void wDCallback(void *AG) {
     31 
     32   cast(tpoolArgs *, args, AG)
     33   cast(chanT *, c, args->channel)
     34 
     35   puts("asWalkdir finished");
     36   printf("Dir: %s", args->s);
     37   printf("\n");
     38   tpoolLock(0);
     39   ringSend(c, 1);
     40   ringSend(c, 2);
     41   tpoolUlock(0);
     42 }
     43 
     44 int main(int ARGC, char** ARGV) {
     45   tpoolArgs args;
     46   tpoolArgs cbArgs;
     47   chanT c;
     48 
     49   argc = ARGC; argv = ARGV;
     50 
     51   initLibsheepy(argv[0]);
     52 
     53   ringStaticInit(c);
     54 
     55   args.s         = "../release/json/";
     56   args.list      = NULL;
     57   args.cb        = wDCallback;
     58   args.cbArgs    = &cbArgs;
     59   cbArgs.s       = args.s;
     60   cbArgs.channel = &c;
     61 
     62   tpoolAdd(emptyTask, NULL);
     63   tpoolAdd(asWalkdir, &args);
     64   puts("threads are running");
     65 
     66   tpoolWait;
     67 
     68   if (args.list) {
     69     puts("asWalkdir success");
     70     pError0(listPrintS(args.list));
     71     printf("The ring has %d messages", (int)ringCount(&c));
     72     printf("\n");
     73     printf("last %d", (int)c.last);
     74     printf("\n");
     75     printf("head %d", (int)c.head);
     76     printf("\n");
     77     if (ringIsEmpty(&c) == 0) {
     78       int r = 0;;
     79       ringRecv((&c), r);
     80       printf("ring status %d", r);
     81       printf("\n");
     82     }
     83   }
     84 
     85 
     86   finalizeLibsheepy();
     87 
     88 }