void Gravity::update_grav_async() { int done = 0; int thread_done = 0; memset(th_ogravmap, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); memset(th_gravmap, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); memset(th_gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); memset(th_gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); memset(th_gravp, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); //memset(th_gravy, 0, XRES*YRES*sizeof(float)); //memset(th_gravx, 0, XRES*YRES*sizeof(float)); //memset(th_gravp, 0, XRES*YRES*sizeof(float)); #ifdef GRAVFFT if (!grav_fft_status) grav_fft_init(); #endif std::unique_lock<std::mutex> l(gravmutex); while (!thread_done) { if (!done) { // run gravity update update_grav(); done = 1; grav_ready = 1; thread_done = gravthread_done; } else { // wait for main thread gravcv.wait(l); done = grav_ready; thread_done = gravthread_done; } } }
void* update_grav_async(void* unused) { int done = 0; int thread_done = 0; memset(th_ogravmap, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); memset(th_gravmap, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); memset(th_gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); memset(th_gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); memset(th_gravp, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); //memset(th_gravy, 0, XRES*YRES*sizeof(float)); //memset(th_gravx, 0, XRES*YRES*sizeof(float)); //memset(th_gravp, 0, XRES*YRES*sizeof(float)); #ifdef GRAVFFT grav_fft_init(); #endif while(!thread_done){ if(!done){ update_grav(); done = 1; pthread_mutex_lock(&gravmutex); grav_ready = done; thread_done = gravthread_done; pthread_mutex_unlock(&gravmutex); } else { pthread_mutex_lock(&gravmutex); pthread_cond_wait(&gravcv, &gravmutex); done = grav_ready; thread_done = gravthread_done; pthread_mutex_unlock(&gravmutex); } } pthread_exit(NULL); }