/** * Returns a process-specific fmutex used to guard OS/2 TCP/IP DLL calls. * This mutex must be used to provide thread safety where it (or reentrancy) * is guaranteed by the respective API. Note that we assume that TCP/IP DLL * calls are process safe and process-reentrant and thus only guarantee thread * safety within a single process. */ _fmutex *global_tcpip_sem() { _fmutex *fsem = NULL; global_lock(); ProcDesc *proc = find_proc_desc(getpid()); ASSERT(proc); if (proc->tcpip_fsem.hev == NULLHANDLE) { /* * Lazily create the mutex. Note that we never destroy it as * process-specific ones will be freed automatically on process termination */ int rc = _fmutex_create(&proc->tcpip_fsem, 0); ASSERT(!rc); } fsem = &proc->tcpip_fsem; global_unlock(); return fsem; }
void RW_IN_Init (in_state_t *in_state_p) { USHORT m_mask = MOUSE_MOTION_WITH_BN1_DOWN | MOUSE_BN1_DOWN | MOUSE_MOTION_WITH_BN2_DOWN | MOUSE_BN2_DOWN | MOUSE_MOTION_WITH_BN3_DOWN | MOUSE_BN3_DOWN | MOUSE_MOTION; USHORT m_flags = MOUSE_DISABLED | MOUSE_MICKEYS; if (mouse_works) return; in_state = in_state_p; // mouse variables freelook = ri.Cvar_Get( "freelook", "0", 0 ); lookstrafe = ri.Cvar_Get ("lookstrafe", "0", 0); sensitivity = ri.Cvar_Get ("sensitivity", "3", 0); m_pitch = ri.Cvar_Get ("m_pitch", "0.022", 0); m_yaw = ri.Cvar_Get ("m_yaw", "0.022", 0); m_forward = ri.Cvar_Get ("m_forward", "1", 0); m_side = ri.Cvar_Get ("m_side", "0.8", 0); ri.Cmd_AddCommand ("+mlook", RW_IN_MLookDown); ri.Cmd_AddCommand ("-mlook", RW_IN_MLookUp); ri.Cmd_AddCommand ("force_centerview", Force_CenterView_f); if (MouOpen(NULL, &mh)) return; ev = _THUNK_PTR_STRUCT_OK(ev_a) ? ev_a : ev_a + 1; //scale = _THUNK_PTR_STRUCT_OK(scale_a) ? scale_a : scale_a + 1; mouse_works = 1; //scale->rowScale = 1; //scale->colScale = 1; //if (MouSetScaleFact(scale, mh)) Sys_Error("MouSetScaleFact"); if (MouSetDevStatus(&m_flags, mh)) Sys_Error("MouSetDevStatus"); MouSetEventMask(&m_mask, mh); { //THRESHOLD t; USHORT status = -1; MouGetNumButtons(&status, mh); //Con_Printf("os/2 mouse: %d buttons\n", (int)status); /* t.Length = sizeof t; MouGetThreshold(&t, mh); Con_Printf("t: %d %d %d %d %d\n", t.Length, t.Level1, t.Lev1Mult, t.Level2, t.lev2Mult); */ } _fmutex_create(&sem, 0); xpos = ypos = 0; if (_beginthread(mouse_thread, NULL, 65536, NULL) == -1) { MouClose(mh); mouse_works = 0; } }
/* Creates the the worker threads. */ static void incdep_init (struct floc *f) { unsigned i; #if defined (HAVE_PTHREAD) && !defined (CONFIG_WITHOUT_THREADS) int rc; pthread_attr_t attr; #elif defined (WINDOWS32) unsigned tid; uintptr_t hThread; #elif defined (__OS2__) int rc; int tid; #endif (void)f; /* heap hacks */ #ifdef __APPLE__ incdep_zone = malloc_create_zone (0, 0); if (!incdep_zone) incdep_zone = malloc_default_zone (); #endif /* create the mutex and two condition variables / event objects. */ #if defined (HAVE_PTHREAD) && !defined (CONFIG_WITHOUT_THREADS) rc = pthread_mutex_init (&incdep_mtx, NULL); if (rc) fatal (f, _("pthread_mutex_init failed: err=%d"), rc); rc = pthread_cond_init (&incdep_cond_todo, NULL); if (rc) fatal (f, _("pthread_cond_init failed: err=%d"), rc); rc = pthread_cond_init (&incdep_cond_done, NULL); if (rc) fatal (f, _("pthread_cond_init failed: err=%d"), rc); #elif defined (WINDOWS32) InitializeCriticalSection (&incdep_mtx); incdep_hev_todo = CreateEvent (NULL, TRUE /*bManualReset*/, FALSE /*bInitialState*/, NULL); if (!incdep_hev_todo) fatal (f, _("CreateEvent failed: err=%d"), GetLastError()); incdep_hev_done = CreateEvent (NULL, TRUE /*bManualReset*/, FALSE /*bInitialState*/, NULL); if (!incdep_hev_done) fatal (f, _("CreateEvent failed: err=%d"), GetLastError()); incdep_hev_todo_waiters = 0; incdep_hev_done_waiters = 0; #elif defined (__OS2__) _fmutex_create (&incdep_mtx, 0); rc = DosCreateEventSem (NULL, &incdep_hev_todo, 0, FALSE); if (rc) fatal (f, _("DosCreateEventSem failed: rc=%d"), rc); rc = DosCreateEventSem (NULL, &incdep_hev_done, 0, FALSE); if (rc) fatal (f, _("DosCreateEventSem failed: rc=%d"), rc); incdep_hev_todo_waiters = 0; incdep_hev_done_waiters = 0; #endif /* create the worker threads and associated per thread data. */ incdep_terminate = 0; if (incdep_are_threads_enabled()) { incdep_num_threads = sizeof (incdep_threads) / sizeof (incdep_threads[0]); if (incdep_num_threads + 1 > job_slots) incdep_num_threads = job_slots <= 1 ? 1 : job_slots - 1; for (i = 0; i < incdep_num_threads; i++) { /* init caches */ unsigned rec_size = sizeof (struct incdep_variable_in_set); if (rec_size < sizeof (struct incdep_variable_def)) rec_size = sizeof (struct incdep_variable_def); if (rec_size < sizeof (struct incdep_recorded_file)) rec_size = sizeof (struct incdep_recorded_file); alloccache_init (&incdep_rec_caches[i], rec_size, "incdep rec", incdep_cache_allocator, (void *)(size_t)i); alloccache_init (&incdep_dep_caches[i], sizeof(struct dep), "incdep dep", incdep_cache_allocator, (void *)(size_t)i); strcache2_init (&incdep_dep_strcaches[i], "incdep dep", /* name */ 65536, /* hash size */ 0, /* default segment size*/ #ifdef HAVE_CASE_INSENSITIVE_FS 1, /* case insensitive */ #else 0, /* case insensitive */ #endif 0); /* thread safe */ strcache2_init (&incdep_var_strcaches[i], "incdep var", /* name */ 32768, /* hash size */ 0, /* default segment size*/ 0, /* case insensitive */ 0); /* thread safe */ /* create the thread. */ #if defined (HAVE_PTHREAD) && !defined (CONFIG_WITHOUT_THREADS) rc = pthread_attr_init (&attr); if (rc) fatal (f, _("pthread_attr_init failed: err=%d"), rc); /*rc = pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_JOINABLE); */ rc = pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); if (rc) fatal (f, _("pthread_attr_setdetachstate failed: err=%d"), rc); rc = pthread_create(&incdep_threads[i], &attr, incdep_worker_pthread, (void *)(size_t)i); if (rc) fatal (f, _("pthread_mutex_init failed: err=%d"), rc); pthread_attr_destroy (&attr); #elif defined (WINDOWS32) tid = 0; hThread = _beginthreadex (NULL, 128*1024, incdep_worker_windows, (void *)i, 0, &tid); if (hThread == 0 || hThread == ~(uintptr_t)0) fatal (f, _("_beginthreadex failed: err=%d"), errno); incdep_threads[i] = (HANDLE)hThread; #elif defined (__OS2__) tid = _beginthread (incdep_worker_os2, NULL, 128*1024, (void *)i); if (tid <= 0) fatal (f, _("_beginthread failed: err=%d"), errno); incdep_threads[i] = tid; #endif } } else incdep_num_threads = 0; incdep_initialized = 1; }
static int kai_stream_init(cubeb * context, cubeb_stream ** stream, char const * stream_name, cubeb_devid input_device, cubeb_stream_params * input_stream_params, cubeb_devid output_device, cubeb_stream_params * output_stream_params, unsigned int latency, cubeb_data_callback data_callback, cubeb_state_callback state_callback, void * user_ptr) { cubeb_stream * stm; KAISPEC wanted_spec; XASSERT(!input_stream_params && "not supported."); if (input_device || output_device) { /* Device selection not yet implemented. */ return CUBEB_ERROR_DEVICE_UNAVAILABLE; } if (!output_stream_params) return CUBEB_ERROR_INVALID_PARAMETER; if (output_stream_params->channels < 1 || output_stream_params->channels > MAX_CHANNELS) return CUBEB_ERROR_INVALID_FORMAT; XASSERT(context); XASSERT(stream); *stream = NULL; stm = calloc(1, sizeof(*stm)); XASSERT(stm); stm->context = context; stm->params = *output_stream_params; stm->data_callback = data_callback; stm->state_callback = state_callback; stm->user_ptr = user_ptr; stm->soft_volume = -1.0f; if (_fmutex_create(&stm->mutex, 0)) { free(stm); return CUBEB_ERROR; } wanted_spec.usDeviceIndex = 0; wanted_spec.ulType = KAIT_PLAY; wanted_spec.ulBitsPerSample = BPS_16; wanted_spec.ulSamplingRate = stm->params.rate; wanted_spec.ulDataFormat = MCI_WAVE_FORMAT_PCM; wanted_spec.ulChannels = stm->params.channels; wanted_spec.ulNumBuffers = NBUFS; wanted_spec.ulBufferSize = frames_to_bytes(FRAME_SIZE, stm->params); wanted_spec.fShareable = TRUE; wanted_spec.pfnCallBack = kai_callback; wanted_spec.pCallBackData = stm; if (kaiOpen(&wanted_spec, &stm->spec, &stm->hkai)) { _fmutex_close(&stm->mutex); free(stm); return CUBEB_ERROR; } *stream = stm; return CUBEB_OK; }