mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-11-03 13:11:20 -05:00 
			
		
		
		
	FT8 demod: FFT: removed main Unix dependencies
This commit is contained in:
		
							parent
							
								
									7ec86b09de
								
							
						
					
					
						commit
						6adac5f45b
					
				
							
								
								
									
										50
									
								
								ft8/fft.cpp
									
									
									
									
									
								
							
							
						
						
									
										50
									
								
								ft8/fft.cpp
									
									
									
									
									
								
							@ -21,11 +21,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "fft.h"
 | 
					#include "fft.h"
 | 
				
			||||||
#include <mutex>
 | 
					#include <mutex>
 | 
				
			||||||
#include <unistd.h>
 | 
					// #include <unistd.h>
 | 
				
			||||||
#include <assert.h>
 | 
					#include <assert.h>
 | 
				
			||||||
#include <sys/file.h>
 | 
					// #include <sys/file.h>
 | 
				
			||||||
#include <sys/types.h>
 | 
					// #include <sys/types.h>
 | 
				
			||||||
#include <sys/stat.h>
 | 
					// #include <sys/stat.h>
 | 
				
			||||||
#include "util.h"
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define TIMING 0
 | 
					#define TIMING 0
 | 
				
			||||||
@ -36,9 +36,10 @@ namespace FT8 {
 | 
				
			|||||||
int fftw_type = FFTW_ESTIMATE;
 | 
					int fftw_type = FFTW_ESTIMATE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static std::mutex plansmu;
 | 
					static std::mutex plansmu;
 | 
				
			||||||
 | 
					static std::mutex plansmu2;
 | 
				
			||||||
static Plan *plans[1000];
 | 
					static Plan *plans[1000];
 | 
				
			||||||
static int nplans;
 | 
					static int nplans;
 | 
				
			||||||
static int plan_master_pid = 0;
 | 
					// static int plan_master_pid = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Plan *get_plan(int n, const char *why)
 | 
					Plan *get_plan(int n, const char *why)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -47,10 +48,10 @@ Plan *get_plan(int n, const char *why)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    plansmu.lock();
 | 
					    plansmu.lock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (plan_master_pid == 0)
 | 
					    // if (plan_master_pid == 0)
 | 
				
			||||||
    {
 | 
					    // {
 | 
				
			||||||
        plan_master_pid = getpid();
 | 
					    //     plan_master_pid = getpid();
 | 
				
			||||||
    }
 | 
					    // }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (int i = 0; i < nplans; i++)
 | 
					    for (int i = 0; i < nplans; i++)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -67,7 +68,9 @@ Plan *get_plan(int n, const char *why)
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if TIMING
 | 
				
			||||||
    double t0 = now();
 | 
					    double t0 = now();
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // fftw_make_planner_thread_safe();
 | 
					    // fftw_make_planner_thread_safe();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -75,12 +78,12 @@ Plan *get_plan(int n, const char *why)
 | 
				
			|||||||
    // can't rely on plansmu because both ft8.so
 | 
					    // can't rely on plansmu because both ft8.so
 | 
				
			||||||
    // and snd.so may be using separate copies of fft.cc.
 | 
					    // and snd.so may be using separate copies of fft.cc.
 | 
				
			||||||
    // the lock file really should be per process.
 | 
					    // the lock file really should be per process.
 | 
				
			||||||
    // FIXME: Qt-fy this
 | 
					    // int lockfd = creat("/tmp/fft-plan-lock", 0666);
 | 
				
			||||||
    int lockfd = creat("/tmp/fft-plan-lock", 0666);
 | 
					    // assert(lockfd >= 0);
 | 
				
			||||||
    assert(lockfd >= 0);
 | 
					    // fchmod(lockfd, 0666);
 | 
				
			||||||
    fchmod(lockfd, 0666);
 | 
					    // int lockret = flock(lockfd, LOCK_EX);
 | 
				
			||||||
    int lockret = flock(lockfd, LOCK_EX);
 | 
					    // assert(lockret == 0);
 | 
				
			||||||
    assert(lockret == 0);
 | 
					    plansmu2.lock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fftwf_set_timelimit(5);
 | 
					    fftwf_set_timelimit(5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -106,10 +109,10 @@ Plan *get_plan(int n, const char *why)
 | 
				
			|||||||
    // FFTW_PATIENT
 | 
					    // FFTW_PATIENT
 | 
				
			||||||
    // FFTW_EXHAUSTIVE
 | 
					    // FFTW_EXHAUSTIVE
 | 
				
			||||||
    int type = fftw_type;
 | 
					    int type = fftw_type;
 | 
				
			||||||
    if (getpid() != plan_master_pid)
 | 
					    // if (getpid() != plan_master_pid)
 | 
				
			||||||
    {
 | 
					    // {
 | 
				
			||||||
        type = FFTW_ESTIMATE;
 | 
					    //     type = FFTW_ESTIMATE;
 | 
				
			||||||
    }
 | 
					    // }
 | 
				
			||||||
    p->type_ = type;
 | 
					    p->type_ = type;
 | 
				
			||||||
    p->fwd_ = fftwf_plan_dft_r2c_1d(n, p->r_, p->c_, type);
 | 
					    p->fwd_ = fftwf_plan_dft_r2c_1d(n, p->r_, p->c_, type);
 | 
				
			||||||
    assert(p->fwd_);
 | 
					    assert(p->fwd_);
 | 
				
			||||||
@ -128,21 +131,24 @@ Plan *get_plan(int n, const char *why)
 | 
				
			|||||||
    p->crev_ = fftwf_plan_dft_1d(n, p->cc2_, p->cc1_, FFTW_BACKWARD, type);
 | 
					    p->crev_ = fftwf_plan_dft_1d(n, p->cc2_, p->cc1_, FFTW_BACKWARD, type);
 | 
				
			||||||
    assert(p->crev_);
 | 
					    assert(p->crev_);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    flock(lockfd, LOCK_UN);
 | 
					    // flock(lockfd, LOCK_UN);
 | 
				
			||||||
    close(lockfd);
 | 
					    // close(lockfd);
 | 
				
			||||||
 | 
					    plansmu2.unlock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assert(nplans + 1 < 1000);
 | 
					    assert(nplans + 1 < 1000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    plans[nplans] = p;
 | 
					    plans[nplans] = p;
 | 
				
			||||||
    __sync_synchronize();
 | 
					    // __sync_synchronize();
 | 
				
			||||||
    nplans += 1;
 | 
					    nplans += 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if TIMING
 | 
				
			||||||
    if (0 && getpid() == plan_master_pid)
 | 
					    if (0 && getpid() == plan_master_pid)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        double t1 = now();
 | 
					        double t1 = now();
 | 
				
			||||||
        fprintf(stderr, "miss pid=%d master=%d n=%d t=%.3f total=%d type=%d, %s\n",
 | 
					        fprintf(stderr, "miss pid=%d master=%d n=%d t=%.3f total=%d type=%d, %s\n",
 | 
				
			||||||
                getpid(), plan_master_pid, n, t1 - t0, nplans, type, why);
 | 
					                getpid(), plan_master_pid, n, t1 - t0, nplans, type, why);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    plansmu.unlock();
 | 
					    plansmu.unlock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user