diff options
| author | Kyle Keen <keenerd@gmail.com> | 2013-01-30 17:40:00 -0500 |
|---|---|---|
| committer | Steve Markgraf <steve@steve-m.de> | 2013-01-31 20:42:42 +0100 |
| commit | ea4dbd242d268e50163acb8df1ac662485b43632 (patch) | |
| tree | 97a0e15ffc2d707957423a90068da06d15a1bac2 /src/rtl_adsb.c | |
| parent | 8d358b44d4f0c85ee2c3397df45b844068547588 (diff) | |
rtl_fm: osx does not like semaphores
Signed-off-by: Steve Markgraf <steve@steve-m.de>
Diffstat (limited to 'src/rtl_adsb.c')
| -rw-r--r-- | src/rtl_adsb.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/rtl_adsb.c b/src/rtl_adsb.c index a625d31..44b62e2 100644 --- a/src/rtl_adsb.c +++ b/src/rtl_adsb.c @@ -37,7 +37,6 @@ #include "getopt/getopt.h" #endif -#include <semaphore.h> #include <pthread.h> #include <libusb.h> @@ -59,7 +58,7 @@ #define BADSAMPLE 255 static pthread_t demod_thread; -static sem_t data_ready; +static pthread_mutex_t data_ready; /* locked when no data available */ static volatile int do_exit = 0; static rtlsdr_dev_t *dev = NULL; @@ -334,20 +333,18 @@ void messages(uint16_t *buf, int len) static void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx) { - int dr_val; if (do_exit) { return;} memcpy(buffer, buf, len); - sem_getvalue(&data_ready, &dr_val); - if (dr_val <= 0) { - sem_post(&data_ready);} + pthread_mutex_trylock(&data_ready); + pthread_mutex_unlock(&data_ready); } static void *demod_thread_fn(void *arg) { int len; while (!do_exit) { - sem_wait(&data_ready); + pthread_mutex_lock(&data_ready); len = magnitute(buffer, DEFAULT_BUF_LENGTH); manchester((uint16_t*)buffer, len); messages((uint16_t*)buffer, len); @@ -368,7 +365,7 @@ int main(int argc, char **argv) int device_count; int ppm_error = 0; char vendor[256], product[256], serial[256]; - sem_init(&data_ready, 0, 0); + pthread_mutex_init(&data_ready, NULL); squares_precompute(); while ((opt = getopt(argc, argv, "d:g:p:e:Q:VS")) != -1) @@ -507,6 +504,7 @@ int main(int argc, char **argv) else { fprintf(stderr, "\nLibrary error %d, exiting...\n", r);} rtlsdr_cancel_async(dev); + pthread_mutex_destroy(&data_ready); if (file != stdout) { fclose(file);} |
