bool wxThreadModule::OnInit() { bool hasThreadManager = #ifdef __LP64__ true ; // TODO VERIFY IN NEXT BUILD #else MPLibraryIsLoaded(); #endif if ( !hasThreadManager ) { wxLogError( wxT("MP thread support is not available on this system" ) ) ; return false; } // main thread's This() is NULL verify_noerr( MPAllocateTaskStorageIndex( &gs_tlsForWXThread ) ) ; verify_noerr( MPSetTaskStorageValue( gs_tlsForWXThread, 0 ) ) ; wxThread::ms_idMainThread = wxThread::GetCurrentId(); gs_critsectWaitingForGui = new wxCriticalSection(); gs_critsectGui = new wxCriticalSection(); gs_critsectGui->Enter(); return true; }
int fftw_threads_init(void) { #ifdef FFTW_USING_POSIX_THREADS /* Set the thread creation attributes as necessary. If we don't change anything, just use the default attributes (NULL). */ int err, attr, attr_changed = 0; err = pthread_attr_init(&fftw_pthread_attributes); /* set to defaults */ if (err) return err; /* Make sure that threads are joinable! (they aren't on AIX) */ err = pthread_attr_getdetachstate(&fftw_pthread_attributes, &attr); if (err) return err; if (attr != PTHREAD_CREATE_JOINABLE) { err = pthread_attr_setdetachstate(&fftw_pthread_attributes, PTHREAD_CREATE_JOINABLE); if (err) return err; attr_changed = 1; } /* Make sure threads parallelize (they don't by default on Solaris) */ err = pthread_attr_getscope(&fftw_pthread_attributes, &attr); if (err) return err; if (attr != PTHREAD_SCOPE_SYSTEM) { err = pthread_attr_setscope(&fftw_pthread_attributes, PTHREAD_SCOPE_SYSTEM); if (err) return err; attr_changed = 1; } if (attr_changed) /* we aren't using the defaults */ fftw_pthread_attributes_p = &fftw_pthread_attributes; else { fftw_pthread_attributes_p = NULL; /* use default attributes */ err = pthread_attr_destroy(&fftw_pthread_attributes); if (err) return err; } #endif /* FFTW_USING_POSIX_THREADS */ #ifdef FFTW_USING_MACOS_THREADS /* Must use MPAllocate and MPFree instead of malloc and free: */ if (MPLibraryIsLoaded()) { fftw_malloc_hook = MPAllocate; fftw_free_hook = MPFree; } #endif /* FFTW_USING_MACOS_THREADS */ #if defined(FFTW_USING_OPENMP_THREADS) && ! defined(_OPENMP) #error OpenMP enabled but not using an OpenMP compiler #endif return 0; /* no error */ }
static bool wxMacMPThreadsInitVerify() { static bool hasThreadManager = false ; if ( !hasThreadManager ) hasThreadManager = MPLibraryIsLoaded(); if ( !hasThreadManager ) { wxMessageBox( wxT("Error") , wxT("MP Thread Support is not available on this System" ), wxOK ) ; return FALSE ; } return TRUE ; }
cFUThread::cFUThread(THREAD_ROUTINE_POINTER startAddress, void* parameter, bool suspended, const char* szName) : isSuspended(suspended) , isSuspendedCS() , semaphore() , threadStartedSemaphore() , terminate(false) , exitCode(0) #ifdef FP_APPLE , queue(cFUThread_INVALID) #endif , name() , thread(cFUThread_INVALID) { if (szName != nullptr) { name = szName; } //Create the structure from the function parameters. cFUThreadInternalParam* params = new cFUThreadInternalParam; params->object = this; params->parameter = parameter; params->func = startAddress; #if defined(WIN32) unsigned int ThreadId; thread = (HANDLE)_beginthreadex(nullptr, 0, InternalFunc, params, 0, &ThreadId); threadStartedSemaphore.Down(); #elif defined (FP_APPLE) if (MPLibraryIsLoaded()) { OSStatus status = MPCreateQueue(&queue); if (status == noErr) status = MPCreateTask(&InternalFunc, params, 0, queue, &exitCode, nullptr, 0, &thread); } #elif defined(LINUX) || defined(IOS) || defined(ANDROID) int status = pthread_create(&thread, nullptr, InternalFunc, params); if (status == 0) // Success threadStartedSemaphore.Down(); #endif }
void SetupReverb() { /* REVERB SETUP */ /* something to fiddle with. */ int delay[REVERB_NUMTAPS] = { 131, 149, 173, 211, 281, 401, 457}; /* prime numbers make it sound good! */ int volume[REVERB_NUMTAPS] = { 120, 100, 95, 90, 80, 60, 50}; int pan[REVERB_NUMTAPS] = { 100, 128, 128, 152, 128, 100, 152}; int count; for (count=0; count< REVERB_NUMTAPS; count++) { DSP_ReverbTap[count].delayms = delay[count]; DSP_ReverbTap[count].volume = volume[count]; DSP_ReverbTap[count].pan = pan[count]; DSP_ReverbTap[count].historyoffset = 0; DSP_ReverbTap[count].historylen = (DSP_ReverbTap[count].delayms * 44100 / 1000); if (DSP_ReverbTap[count].historylen < FSOUND_DSP_GetBufferLength()) DSP_ReverbTap[count].historylen = FSOUND_DSP_GetBufferLength(); /* just in case our calc is not the same. */ #ifdef __MACH__ DSP_ReverbTap[count].historybuff = (char *)calloc(DSP_ReverbTap[count].historylen, 4); #else if (MPLibraryIsLoaded()) { DSP_ReverbTap[count].historybuff = (char *)MPAllocateAligned(DSP_ReverbTap[count].historylen * 4, kMPAllocateDefaultAligned, kMPAllocateClearMask); /* * 4 is for 16bit stereo (mmx only) */ } if (!DSP_ReverbTap[count].historybuff) { printf("Memory not allocated!"); exit (EXIT_FAILURE); } #endif DSP_ReverbTap[count].workarea = NULL; DSP_ReverbTap[count].Unit = FSOUND_DSP_Create(&DSP_ReverbCallback, FSOUND_DSP_DEFAULTPRIORITY_USER+20+(count*2), (void *)&DSP_ReverbTap[count]); FSOUND_DSP_SetActive(DSP_ReverbTap[count].Unit, TRUE); } }
static OSErr InitializeApplication( void ) { OSErr err; static const EventTypeSpec sApplicationEvents[] = { { kEventClassCommand, kEventCommandProcess } }; BlockZero( &g, sizeof(g) ); g.mainBundle = CFBundleGetMainBundle(); if ( g.mainBundle == NULL ) { err = -1; goto Bail; } if ( MPLibraryIsLoaded() == false ) { err = -1; goto Bail; } err = CreateNibReferenceWithCFBundle( g.mainBundle, CFSTR("main"), &g.mainNib ); if ( err != noErr ) goto Bail; if ( g.mainNib == NULL ) { err = -1; goto Bail; } err = SetMenuBarFromNib( g.mainNib, CFSTR("MenuBar") ); if ( err != noErr ) goto Bail; InstallApplicationEventHandler( NewEventHandlerUPP(AppEventEventHandlerProc), GetEventTypeCount(sApplicationEvents), sApplicationEvents, 0, NULL ); Bail: return( err ); }
/** * \brief Parses the GNU AutoOpts options for tcpreplay * * If you're using AutoOpts with tcpreplay_api, then just call this after * optionProcess() and it will parse all the options for you. As always, * returns 0 on success, and -1 on error & -2 on warning. */ int tcpreplay_post_args(tcpreplay_t *ctx, int argc) { char *temp, *intname; char ebuf[SENDPACKET_ERRBUF_SIZE]; int int1dlt, int2dlt; tcpreplay_opt_t *options; int warn = 0; #ifdef USE_AUTOOPTS options = ctx->options; #ifdef DEBUG if (HAVE_OPT(DBUG)) debug = OPT_VALUE_DBUG; #else if (HAVE_OPT(DBUG)) { warn ++; tcpreplay_setwarn(ctx, "%s", "not configured with --enable-debug. Debugging disabled."); } #endif options->loop = OPT_VALUE_LOOP; options->sleep_accel = OPT_VALUE_SLEEP_ACCEL; if (HAVE_OPT(LIMIT)) options->limit_send = OPT_VALUE_LIMIT; if (HAVE_OPT(TOPSPEED)) { options->speed.mode = speed_topspeed; options->speed.speed = 0.0; } else if (HAVE_OPT(PPS)) { options->speed.mode = speed_packetrate; options->speed.speed = (float)OPT_VALUE_PPS; options->speed.pps_multi = OPT_VALUE_PPS_MULTI; } else if (HAVE_OPT(ONEATATIME)) { options->speed.mode = speed_oneatatime; options->speed.speed = 0.0; } else if (HAVE_OPT(MBPS)) { options->speed.mode = speed_mbpsrate; options->speed.speed = atof(OPT_ARG(MBPS)); } else if (HAVE_OPT(MULTIPLIER)) { options->speed.mode = speed_multiplier; options->speed.speed = atof(OPT_ARG(MULTIPLIER)); } #ifdef ENABLE_VERBOSE if (HAVE_OPT(VERBOSE)) options->verbose = 1; if (HAVE_OPT(DECODE)) options->tcpdump->args = safe_strdup(OPT_ARG(DECODE)); #endif if (HAVE_OPT(STATS)) options->stats = OPT_VALUE_STATS; /* * Check if the file cache should be enabled - if we're looping more than * once and the command line option has been spec'd */ if (HAVE_OPT(ENABLE_FILE_CACHE) && (options->loop != 1)) { options->enable_file_cache = true; } /* * If we're preloading the pcap before the first run, then * we're forcing the file cache to be true */ if (HAVE_OPT(PRELOAD_PCAP)) { options->preload_pcap = true; options->enable_file_cache = true; } /* Dual file mode */ if (HAVE_OPT(DUALFILE)) { options->dualfile = true; if (argc < 2) { tcpreplay_seterr(ctx, "%s", "--dualfile mode requires at least two pcap files"); return -1; } if (argc % 2 != 0) { tcpreplay_seterr(ctx, "%s", "--dualfile mode requires an even number of pcap files"); return -1; } } if (HAVE_OPT(TIMER)) { if (strcmp(OPT_ARG(TIMER), "select") == 0) { #ifdef HAVE_SELECT options->accurate = accurate_select; #else tcpreplay_seterr(ctx, "%s", "tcpreplay_api not compiled with select support"); return -1; #endif } else if (strcmp(OPT_ARG(TIMER), "rdtsc") == 0) { #ifdef HAVE_RDTSC options->accurate = accurate_rdtsc; #else tcpreplay_seterr(ctx, "%s", "tcpreplay_api not compiled with rdtsc support"); return -1; #endif } else if (strcmp(OPT_ARG(TIMER), "ioport") == 0) { #if defined HAVE_IOPERM && defined(__i386__) options->accurate = accurate_ioport; ioport_sleep_init(); #else tcpreplay_seterr(ctx, "%s", "tcpreplay_api not compiled with IO Port 0x80 support"); return -1; #endif } else if (strcmp(OPT_ARG(TIMER), "gtod") == 0) { options->accurate = accurate_gtod; } else if (strcmp(OPT_ARG(TIMER), "nano") == 0) { options->accurate = accurate_nanosleep; } else if (strcmp(OPT_ARG(TIMER), "abstime") == 0) { #ifdef HAVE_ABSOLUTE_TIME options->accurate = accurate_abs_time; if (!MPLibraryIsLoaded()) { tcpreplay_seterr(ctx, "%s", "The MP library did not load.\n"); return -1; } #else tcpreplay_seterr(ctx, "%s", "tcpreplay_api only supports absolute time on Apple OS X"); return -1; #endif } else { tcpreplay_seterr(ctx, "Unsupported timer mode: %s", OPT_ARG(TIMER)); return -1; } } #ifdef HAVE_RDTSC if (HAVE_OPT(RDTSC_CLICKS)) { rdtsc_calibrate(OPT_VALUE_RDTSC_CLICKS); } #endif if (HAVE_OPT(PKTLEN)) { options->use_pkthdr_len = true; warn ++; tcpreplay_setwarn(ctx, "%s", "--pktlen may cause problems. Use with caution."); } if ((intname = get_interface(ctx->intlist, OPT_ARG(INTF1))) == NULL) { tcpreplay_seterr(ctx, "Invalid interface name/alias: %s", OPT_ARG(INTF1)); return -1; } options->intf1_name = safe_strdup(intname); /* open interfaces for writing */ if ((ctx->intf1 = sendpacket_open(options->intf1_name, ebuf, TCPR_DIR_C2S)) == NULL) { tcpreplay_seterr(ctx, "Can't open %s: %s", options->intf1_name, ebuf); return -1; } int1dlt = sendpacket_get_dlt(ctx->intf1); if (HAVE_OPT(INTF2)) { if ((intname = get_interface(ctx->intlist, OPT_ARG(INTF2))) == NULL) { tcpreplay_seterr(ctx, "Invalid interface name/alias: %s", OPT_ARG(INTF2)); return -1; } options->intf2_name = safe_strdup(intname); /* open interface for writing */ if ((ctx->intf2 = sendpacket_open(options->intf2_name, ebuf, TCPR_DIR_S2C)) == NULL) { tcpreplay_seterr(ctx, "Can't open %s: %s", options->intf2_name, ebuf); } int2dlt = sendpacket_get_dlt(ctx->intf2); if (int2dlt != int1dlt) { tcpreplay_seterr(ctx, "DLT type missmatch for %s (%s) and %s (%s)", options->intf1_name, pcap_datalink_val_to_name(int1dlt), options->intf2_name, pcap_datalink_val_to_name(int2dlt)); return -1; } } if (HAVE_OPT(CACHEFILE)) { temp = safe_strdup(OPT_ARG(CACHEFILE)); options->cache_packets = read_cache(&options->cachedata, temp, &options->comment); safe_free(temp); } /* return -2 on warnings */ if (warn > 0) return -2; return 0; #else tcpreplay_seterr(ctx, "autopts support not compiled in. tcpreplay_post_args() not supported"); return -1; #endif /* USE_AUTOOPTS */ }
int X(ithreads_init)(void) { #ifdef USING_POSIX_THREADS /* Set the thread creation attributes as necessary. If we don't change anything, just use the default attributes (NULL). */ int err, attr, attr_changed = 0; err = pthread_attr_init(&fftw_pthread_attributes); /* set to defaults */ if (err) return err; /* Make sure that threads are joinable! (they aren't on AIX) */ err = pthread_attr_getdetachstate(&fftw_pthread_attributes, &attr); if (err) return err; if (attr != PTHREAD_CREATE_JOINABLE) { err = pthread_attr_setdetachstate(&fftw_pthread_attributes, PTHREAD_CREATE_JOINABLE); if (err) return err; attr_changed = 1; } /* Make sure threads parallelize (they don't by default on Solaris). Note, however that the POSIX standard does not *require* implementations to support PTHREAD_SCOPE_SYSTEM. They may only support PTHREAD_SCOPE_PROCESS (e.g. IRIX, Cygwin). In this case, how the threads interact with other resources on the system is undefined by the standard, and we have to hope for the best. */ err = pthread_attr_getscope(&fftw_pthread_attributes, &attr); if (err) return err; if (attr != PTHREAD_SCOPE_SYSTEM) { err = pthread_attr_setscope(&fftw_pthread_attributes, PTHREAD_SCOPE_SYSTEM); if (err == 0) attr_changed = 1; /* ignore errors */ } if (attr_changed) /* we aren't using the defaults */ fftw_pthread_attributes_p = &fftw_pthread_attributes; else { fftw_pthread_attributes_p = NULL; /* use default attributes */ err = pthread_attr_destroy(&fftw_pthread_attributes); if (err) return err; } #endif /* USING_POSIX_THREADS */ #ifdef USING_MACOS_THREADS /* FIXME: don't have malloc hooks (yet) in fftw3 */ /* Must use MPAllocate and MPFree instead of malloc and free: */ if (MPLibraryIsLoaded()) { MALLOC_hook = MPAllocate; fftw_free_hook = MPFree; } #endif /* USING_MACOS_THREADS */ #if defined(USING_OPENMP_THREADS) && ! defined(_OPENMP) #error OpenMP enabled but not using an OpenMP compiler #endif #ifdef HAVE_THREADS X(mksolver_ct_hook) = X(mksolver_ct_threads); X(mksolver_hc2hc_hook) = X(mksolver_hc2hc_threads); return 0; /* no error */ #else return 0; /* no threads, no error */ #endif }