File: upwaker.h

package info (click to toggle)
jack-capture 0.9.67-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 344 kB
  • sloc: ansic: 2,176; cpp: 1,583; makefile: 179; sh: 114
file content (30 lines) | stat: -rw-r--r-- 980 bytes parent folder | download | duplicates (3)
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

/* 
   An upwaker is something inbetween semaphores and conditionals.

   Similarly to semaphores, it guarantees upwaker_sleep() to wake up, even
   if the upwaker isn't currently sleeping (the next call to upwaker_sleep() will
   not actually go to sleep).

   And similarly to conditionals, it will wake the sleeper up _only_ one time
   when upwaker_wake_up() is called several times in a row, where
   upwaker_sleep() hasn't got a chance to wake up inbetween those calls.

   This implementation only supports one thread calling upwaker_sleep() and
   one thread calling upwaker_wake_up(). Using several sleepers and upwakers on
   the same upwaker_t variable has not been tested or given any thought about
   whether it would work.
*/


#include <pthread.h>

typedef struct {
  int please_wakeup;
  pthread_mutex_t mutex;
  pthread_cond_t cond;
} upwaker_t;

upwaker_t *create_upwaker(void);
void upwaker_sleep(upwaker_t *upwaker);
void upwaker_wake_up(upwaker_t *upwaker);