"Fossies" - the Fresh Open Source Software Archive

Member "pidentd-3.0.19/src/avail.c" (20 Jan 1999, 1099 Bytes) of package /linux/misc/old/pidentd-3.0.19.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "avail.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2 ** avail.c - Data availability control functions.
    3 **
    4 ** Copyright (c) 1997-1998 Peter Eriksson <pen@lysator.liu.se>
    5 **
    6 ** This program is free software; you can redistribute it and/or
    7 ** modify it as you wish - as long as you don't claim that you wrote
    8 ** it.
    9 **
   10 ** This program is distributed in the hope that it will be useful,
   11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
   12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   13 */
   14 
   15 #include "config.h"
   16 
   17 #include <stdio.h>
   18 
   19 #include "pidentd.h"
   20 
   21 
   22 int
   23 avail_init(avail_t *ap)
   24 {
   25     pthread_mutex_init(&ap->mtx, NULL);
   26     pthread_cond_init(&ap->cv, NULL);
   27     ap->avail = 0;
   28     return 0;
   29 }
   30 
   31 int
   32 avail_signal(avail_t *ap)
   33 {
   34     pthread_mutex_lock(&ap->mtx);
   35     if (ap->avail)
   36     pthread_mutex_unlock(&ap->mtx);
   37     else
   38     {
   39     ap->avail = 1;
   40     pthread_mutex_unlock(&ap->mtx);
   41     pthread_cond_broadcast(&ap->cv);
   42     }
   43 
   44     return 0;
   45 }
   46      
   47 int
   48 avail_wait(avail_t *ap)
   49 {
   50     pthread_mutex_lock(&ap->mtx);
   51     while (ap->avail == 0)
   52     pthread_cond_wait(&ap->cv, &ap->mtx);
   53     pthread_mutex_unlock(&ap->mtx);
   54     
   55     return 0;
   56 }