void *FXTerminal::worker_thread(void *arg) #endif { signal(SIGINT, sigint_handler); #ifdef SIGBREAK signal(SIGBREAK, sigbreak_handler); #endif term = (FXTerminal *)arg; // set proper initial state for all the locks. LockMutex(term->mutex1); LockMutex(term->mutex2); term->sync_even = 1; // run the application code. returncode = (*fwin_main1)(term->argc, term->argv); wake_up_terminal(WORKER_EXITING); #ifdef WIN32 ExitThread(returncode); return returncode; #else pthread_exit(&returncode); // between these two lines I think return &returncode; // I must certainly exit! #endif }
void PlanetOrbitMenu (void) { MENU_STATE MenuState; InputFrameCallback *oldCallback; memset (&MenuState, 0, sizeof MenuState); DrawMenuStateStrings (PM_SCAN, SCAN); LockMutex (GraphicsLock); SetFlashRect (SFR_MENU_3DO); UnlockMutex (GraphicsLock); MenuState.CurState = SCAN; SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); oldCallback = SetInputCallback (on_input_frame); MenuState.InputFunc = DoPlanetOrbit; DoInput (&MenuState, TRUE); SetInputCallback (oldCallback); LockMutex (GraphicsLock); SetFlashRect (NULL); UnlockMutex (GraphicsLock); DrawMenuStateStrings (PM_STARMAP, -NAVIGATION); }
void TFB_DrawImage_SetMipmap (TFB_Image *img, TFB_Image *mmimg, int hotx, int hoty) { bool imgpal; bool mmpal; if (!img || !mmimg) return; LockMutex (img->mutex); LockMutex (mmimg->mutex); // Either both images must be using the same colormap, or mipmap image // must not be paletted. This restriction is due to the current // implementation of fill-stamp, which replaces the palette with // fill color. imgpal = TFB_DrawCanvas_IsPaletted (img->NormalImg); mmpal = TFB_DrawCanvas_IsPaletted (mmimg->NormalImg); if (!mmpal || (mmpal && imgpal && img->colormap_index == mmimg->colormap_index)) { img->MipmapImg = mmimg->NormalImg; img->MipmapHs.x = hotx; img->MipmapHs.y = hoty; } else { img->MipmapImg = NULL; } UnlockMutex (mmimg->mutex); UnlockMutex (img->mutex); }
static void Imo2sproxy_Loop(IMO2SPROXY *hInst) { struct sockaddr_in sock; int socklen; SOCKET new_fd; TYP_LIST *hConns = List_Init(32); CONNINST *pInst; IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)hInst; fd_set fdListen; if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog) fprintf (hProxy->pCfg->fpLog, "Socksproxy:Loop(Start)\n"); hProxy->iRunning = 1; LockMutex(hProxy->loopmutex); while (hProxy->iRunning) { FD_ZERO(&fdListen); FD_SET(hProxy->listen_fd, &fdListen); socklen = sizeof(sock); if (select (0, &fdListen, NULL, NULL, NULL) != SOCKET_ERROR && FD_ISSET(hProxy->listen_fd, &fdListen)) { new_fd = accept(hProxy->listen_fd, (struct sockaddr *) &sock, &socklen); if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog) { fprintf (hProxy->pCfg->fpLog, "Connection from %s:%d -> Connection: %d\n", inet_ntoa(sock.sin_addr), ntohs(sock.sin_port), new_fd); fflush (hProxy->pCfg->fpLog); } if (new_fd != INVALID_SOCKET && (pInst = calloc (1, sizeof(CONNINST)))) { CleanConnections (hConns); List_Push(hConns, pInst); pInst->hSock = new_fd; pInst->hProxy = hProxy; InitMutex(pInst->connected); LockMutex(pInst->connected); InitMutex(pInst->sendmutex); Dispatcher_Start(pInst); } } } if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog) fprintf (hProxy->pCfg->fpLog, "Socksproxy:Loop(End)\n"); CleanConnections (hConns); while (pInst=List_Pop(hConns)) { Dispatcher_Stop(pInst); FreeConnection(pInst); free (pInst); } List_Exit(hConns); UnlockMutex(hProxy->loopmutex); }
void TFB_DrawImage_CopyRect (TFB_Image *source, const RECT *srcRect, TFB_Image *target, POINT dstPt) { LockMutex (source->mutex); LockMutex (target->mutex); TFB_DrawCanvas_CopyRect (source->NormalImg, srcRect, target->NormalImg, dstPt); target->dirty = TRUE; UnlockMutex (target->mutex); UnlockMutex (source->mutex); }
BOOLEAN DoSaveTeam (MELEE_STATE *pMS) { STAMP MsgStamp; char file[NAME_MAX]; uio_Stream *stream; CONTEXT OldContext; bool saveOk = false; snprintf (file, sizeof file, "%s.mle", MeleeSetup_getTeamName (pMS->meleeSetup, pMS->side)); LockMutex (GraphicsLock); OldContext = SetContext (ScreenContext); ConfirmSaveLoad (&MsgStamp); // Show the "Saving . . ." message. UnlockMutex (GraphicsLock); stream = uio_fopen (meleeDir, file, "wb"); if (stream != NULL) { saveOk = (MeleeTeam_serialize (&pMS->meleeSetup->teams[pMS->side], stream) == 0); uio_fclose (stream); if (!saveOk) uio_unlink (meleeDir, file); } pMS->load.top = 0; pMS->load.cur = 0; // Undo the screen damage done by the "Saving . . ." message. LockMutex (GraphicsLock); DrawStamp (&MsgStamp); DestroyDrawable (ReleaseDrawable (MsgStamp.frame)); SetContext (OldContext); UnlockMutex (GraphicsLock); if (!saveOk) SaveProblem (); // Update the team list; a previously existing team may have been // deleted when save failed. LoadTeamList (pMS); SelectTeamByFileName (pMS, file); return (stream != 0); }
void arith_frame_blit (FRAME srcFrame, const RECT *rsrc, FRAME dstFrame, const RECT *rdst, int num, int denom) { TFB_Image *srcImg, *dstImg; SDL_Surface *src, *dst; SDL_Rect srcRect, dstRect, *srp = NULL, *drp = NULL; srcImg = srcFrame->image; dstImg = dstFrame->image; LockMutex (srcImg->mutex); LockMutex (dstImg->mutex); src = (SDL_Surface *)srcImg->NormalImg; dst = (SDL_Surface *)dstImg->NormalImg; if (rdst) { dstRect.x = rdst->corner.x; dstRect.y = rdst->corner.y; dstRect.w = rdst->extent.width; dstRect.h = rdst->extent.height; drp = &dstRect; } if (rsrc) { srcRect.x = rsrc->corner.x; srcRect.y = rsrc->corner.y; srcRect.w = rsrc->extent.width; srcRect.h = rsrc->extent.height; srp = &srcRect; } else if (srcFrame->HotSpot.x || srcFrame->HotSpot.y) { if (rdst) { dstRect.x -= srcFrame->HotSpot.x; dstRect.y -= srcFrame->HotSpot.y; } else { dstRect.x = -srcFrame->HotSpot.x; dstRect.y = -srcFrame->HotSpot.y; dstRect.w = GetFrameWidth (srcFrame); dstRect.h = GetFrameHeight (srcFrame); drp = &dstRect; } } TFB_BlitSurface (src, srp, dst, drp, num, denom); UnlockMutex (srcImg->mutex); UnlockMutex (dstImg->mutex); }
BOOLEAN TFB_DrawImage_Intersect (TFB_Image *img1, POINT img1org, TFB_Image *img2, POINT img2org, const RECT *interRect) { BOOLEAN ret; LockMutex (img1->mutex); LockMutex (img2->mutex); ret = TFB_DrawCanvas_Intersect (img1->NormalImg, img1org, img2->NormalImg, img2org, interRect); UnlockMutex (img2->mutex); UnlockMutex (img1->mutex); return ret; }
static void FlushFadeXForms (void) { LockMutex (fadeLock); finishPendingFade (); UnlockMutex (fadeLock); }
BOOLEAN _ReleaseMusicData (void *data) { TFB_SoundSample **pmus = data; TFB_SoundSample *sample; if (pmus == NULL) return (FALSE); sample = *pmus; assert (sample != 0); if (sample->decoder) { TFB_SoundDecoder *decoder = sample->decoder; LockMutex (soundSource[MUSIC_SOURCE].stream_mutex); if (soundSource[MUSIC_SOURCE].sample == sample) { // Currently playing this sample! Not good. StopStream (MUSIC_SOURCE); } UnlockMutex (soundSource[MUSIC_SOURCE].stream_mutex); sample->decoder = NULL; SoundDecoder_Free (decoder); } TFB_DestroySoundSample (sample); FreeMusicData (data); return (TRUE); }
static void RosterCleanup (MENU_STATE *pMS) { if (pMS->flash_task) { UnlockMutex (GraphicsLock); ConcludeTask (pMS->flash_task); LockMutex (GraphicsLock); pMS->flash_task = 0; } if (pMS->CurFrame) { STAMP s; SHIP_FRAGMENT *StarShipPtr; SetContext (StatusContext); s.origin = pMS->first_item; StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), (HSHIPFRAG)pMS->CurFrame); s.frame = StarShipPtr->icons; UnlockShipFrag (&GLOBAL (built_ship_q), (HSHIPFRAG)pMS->CurFrame); if (!(pMS->CurState & SHIP_TOGGLE)) DrawStamp (&s); else { SetContextForeGroundColor (WHITE_COLOR); DrawFilledStamp (&s); } } }
static COUNT DeltaCredit (SIZE delta_credit) { COUNT Credit; Credit = MAKE_WORD ( GET_GAME_STATE (MELNORME_CREDIT0), GET_GAME_STATE (MELNORME_CREDIT1) ); if ((int)delta_credit >= 0 || ((int)(-delta_credit) <= (int)(Credit))) { Credit += delta_credit; SET_GAME_STATE (MELNORME_CREDIT0, LOBYTE (Credit)); SET_GAME_STATE (MELNORME_CREDIT1, HIBYTE (Credit)); LockMutex (GraphicsLock); DrawStatusMessage ((UNICODE *)~0); UnlockMutex (GraphicsLock); } else { NPCPhrase (NEED_MORE_CREDIT0); NPCPhrase (delta_credit + (int)Credit); NPCPhrase (NEED_MORE_CREDIT1); } return (Credit); }
/* Add Decoded CRL, 0 on success */ static int AddCRL(WOLFSSL_CRL* crl, DecodedCRL* dcrl) { CRL_Entry* crle; WOLFSSL_ENTER("AddCRL"); crle = (CRL_Entry*)XMALLOC(sizeof(CRL_Entry), crl->heap, DYNAMIC_TYPE_CRL_ENTRY); if (crle == NULL) { WOLFSSL_MSG("alloc CRL Entry failed"); return -1; } if (InitCRL_Entry(crle, dcrl) < 0) { WOLFSSL_MSG("Init CRL Entry failed"); XFREE(crle, crl->heap, DYNAMIC_TYPE_CRL_ENTRY); return -1; } if (LockMutex(&crl->crlLock) != 0) { WOLFSSL_MSG("LockMutex failed"); FreeCRL_Entry(crle, crl->heap); XFREE(crle, crl->heap, DYNAMIC_TYPE_CRL_ENTRY); return BAD_MUTEX_E; } crle->next = crl->crlList; crl->crlList = crle; UnLockMutex(&crl->crlLock); return 0; }
static void Imo2sproxy_Exit(IMO2SPROXY *hInst) { IMO2SPROXY_INST *hProxy = (IMO2SPROXY_INST*)hInst; CONNINST *pInst; if (hProxy->pCfg->bVerbose && hProxy->pCfg->fpLog) fprintf (hProxy->pCfg->fpLog, "W32SkypeEmu:Exit()\n"); if (hProxy->hWndDispatch) DestroyWindow (hProxy->hWndDispatch); if (hProxy->dwThreadID) PostThreadMessage (hProxy->dwThreadID, WM_QUIT, 0, 0); LockMutex(hProxy->loopmutex); // Kill 'em all! if (hProxy->hClients) { while (pInst=List_Pop(hProxy->hClients)) { FreeConnection(pInst); free (pInst); } List_Exit (hProxy->hClients); } UnregisterClass ("Imo2SProxyDispatchWindow", GetModuleHandle(NULL)); UnlockMutex(hProxy->loopmutex); ExitMutex(hProxy->loopmutex); free (hProxy); }
static void DrawRestartMenu (BYTE OldState, BYTE NewState, FRAME f) { RECT r; TEXT t; UNICODE buf[64]; LockMutex (GraphicsLock); SetContext (ScreenContext); r.corner.x = r.corner.y = r.extent.width = r.extent.height = 0; SetContextClipRect (&r); r.corner.x = 0; r.corner.y = 0; r.extent.width = SCREEN_WIDTH; r.extent.height = SCREEN_HEIGHT; SetFlashRect (&r, SetAbsFrameIndex (f, NewState + 1)); // Put version number in the corner SetContextFont (TinyFont); t.pStr = buf; t.baseline.x = SCREEN_WIDTH - 3; t.baseline.y = SCREEN_HEIGHT - 2; t.align = ALIGN_RIGHT; t.CharCount = (COUNT)~0; sprintf (buf, "v%d.%d.%d%s", UQM_MAJOR_VERSION, UQM_MINOR_VERSION, UQM_PATCH_VERSION, UQM_EXTRA_VERSION); SetContextForeGroundColor (WHITE_COLOR); font_DrawText (&t); UnlockMutex (GraphicsLock); (void) OldState; /* Satisfying compiler (unused parameter) */ }
void AlienTalkSegue (COUNT wait_track) { // this skips any talk segues that follow an aborted one if ((GLOBAL (CurrentActivity) & CHECK_ABORT) || TalkingFinished) return; if (!pCurInputState->Initialized) { InitSpeechGraphics (); LockMutex (GraphicsLock); SetColorMap (GetColorMapAddress (CommData.AlienColorMap)); SetContext (AnimContext); DrawAlienFrame (NULL, 0, TRUE); UpdateSpeechGraphics (); CommIntroTransition (); UnlockMutex (GraphicsLock); pCurInputState->Initialized = TRUE; PlayMusic (CommData.AlienSong, TRUE, 1); SetMusicVolume (BACKGROUND_VOL); InitCommAnimations (); LastActivity &= ~CHECK_LOAD; } TalkingFinished = TalkSegue (wait_track); if (TalkingFinished) FadeMusic (FOREGROUND_VOL, ONE_SECOND); }
static int GetOcspEntry(WOLFSSL_OCSP* ocsp, OcspRequest* request, OcspEntry** entry) { WOLFSSL_ENTER("GetOcspEntry"); *entry = NULL; if (LockMutex(&ocsp->ocspLock) != 0) { WOLFSSL_LEAVE("CheckCertOCSP", BAD_MUTEX_E); return BAD_MUTEX_E; } for (*entry = ocsp->ocspList; *entry; *entry = (*entry)->next) if (XMEMCMP((*entry)->issuerHash, request->issuerHash, OCSP_DIGEST_SIZE) == 0 && XMEMCMP((*entry)->issuerKeyHash, request->issuerKeyHash, OCSP_DIGEST_SIZE) == 0) break; if (*entry == NULL) { *entry = (OcspEntry*)XMALLOC(sizeof(OcspEntry), NULL, DYNAMIC_TYPE_OCSP_ENTRY); if (*entry) { InitOcspEntry(*entry, request); (*entry)->next = ocsp->ocspList; ocsp->ocspList = *entry; } } UnLockMutex(&ocsp->ocspLock); return *entry ? 0 : MEMORY_ERROR; }
static void DrawDevices (DEVICES_STATE *devState, COUNT OldDevice, COUNT NewDevice) { LockMutex (GraphicsLock); BatchGraphics (); SetContext (StatusContext); if (OldDevice > NUM_DEVICES) { // Asked for the initial display or refresh DrawDevicesDisplay (devState); // do not draw unselected again this time OldDevice = NewDevice; } if (OldDevice != NewDevice) { // unselect the previous element DrawDevice (devState->list[OldDevice], OldDevice - devState->topIndex, false); } if (NewDevice < NUM_DEVICES) { // select the new element DrawDevice (devState->list[NewDevice], NewDevice - devState->topIndex, true); } UnbatchGraphics (); UnlockMutex (GraphicsLock); }
static void post_melnorme_enc (void) { LockMutex (GraphicsLock); DrawStatusMessage (0); UnlockMutex (GraphicsLock); }
void StopTrack (void) { LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); StopStream (SPEECH_SOURCE); track_count = 0; tracks_length = 0; cur_chunk = NULL; cur_sub_chunk = NULL; UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); if (chunks_head) { chunks_tail = NULL; destroy_SoundChunk_list (chunks_head); chunks_head = NULL; last_sub = NULL; } if (sound_sample) { // We delete the decoders ourselves sound_sample->decoder = NULL; TFB_DestroySoundSample (sound_sample); sound_sample = NULL; } }
void TFB_ReturnColorMap (TFB_ColorMap *map) { LockMutex (maplock); release_colormap (map); UnlockMutex (maplock); }
// ----------------------------------------------------------------------------- static void EventHandler(char *pszMsg, void *pUser) { CONNINST *pInst = (CONNINST*)pUser; unsigned int uiLen = strlen (pszMsg); static BOOL bFirstLogin = TRUE; if (pInst->hProxy->pCfg->bVerbose && pInst->hProxy->pCfg->fpLog) { fprintf (pInst->hProxy->pCfg->fpLog, "%03d> %s\n", pInst->hSock, pszMsg); fflush (pInst->hProxy->pCfg->fpLog); } if (bFirstLogin && strncmp (pszMsg, "CONNSTATUS", 10) == 0 && strcmp(pszMsg+11, "CONNECTING")) { pInst->iConnectionStat = (strcmp(pszMsg+11, "ONLINE")==0); UnlockMutex (pInst->connected); bFirstLogin = FALSE; } LockMutex(pInst->sendmutex); if (!(SendPacket (pInst, &uiLen, sizeof(uiLen)) && SendPacket (pInst, pszMsg, uiLen))) { //Dispatcher_Stop(pInst); //FreeConnection (pInst); } UnlockMutex(pInst->sendmutex); }
int GetFadeAmount (void) { int newAmount; LockMutex (XFormControl.Lock); if (fadeInterval) { // have a pending fade TimeCount Now = GetTimeCounter (); sint32 elapsed; elapsed = Now - fadeStartTime; if (elapsed > fadeInterval) elapsed = fadeInterval; newAmount = fadeAmount + (long)fadeDelta * elapsed / fadeInterval; if (elapsed >= fadeInterval) { // fade is over fadeAmount = newAmount; fadeInterval = 0; } } else { // no fade pending, return the current newAmount = fadeAmount; } UnlockMutex (XFormControl.Lock); return newAmount; }
static void FlushFadeXForms (void) { LockMutex (XFormControl.Lock); finishPendingFade (); UnlockMutex (XFormControl.Lock); }
void TFB_DrawImage_Delete (TFB_Image *image) { if (image == 0) { log_add (log_Warning, "INTERNAL ERROR: Tried to delete a null image!"); /* Should we die here? */ return; } LockMutex (image->mutex); TFB_DrawCanvas_Delete (image->NormalImg); if (image->ScaledImg) { TFB_DrawCanvas_Delete (image->ScaledImg); image->ScaledImg = 0; } if (image->FilledImg) { TFB_DrawCanvas_Delete (image->FilledImg); image->FilledImg = 0; } UnlockMutex (image->mutex); DestroyMutex (image->mutex); HFree (image); }
static void GiveRadios (RESPONSE_REF R) { if (PLAYER_SAID (R, we_will_transfer_now)) { SET_GAME_STATE (RADIOACTIVES_PROVIDED, 1); NPCPhrase (FUEL_UP0); NPCPhrase (FUEL_UP1); AlienTalkSegue (1); LockMutex (GraphicsLock); //CommData.AlienAmbientArray[2].AnimFlags |= ANIM_DISABLED; // JMS UnlockMutex (GraphicsLock); XFormColorMap (GetColorMapAddress ( SetAbsColorMapIndex (CommData.AlienColorMap, 0) ), ONE_SECOND / 2); AlienTalkSegue ((COUNT)~0); RevealSelf (0); } else { if (PLAYER_SAID (R, what_will_you_give_us)) NPCPhrase (MESSAGE_GARBLED_1); else if (PLAYER_SAID (R, before_radios_we_need_info)) NPCPhrase (MESSAGE_GARBLED_2); Response (we_will_transfer_now, GiveRadios); Response (what_will_you_give_us, GiveRadios); Response (before_radios_we_need_info, GiveRadios); } }
/*********** Invoke Forground Command *********************/ static void command_invoke(void *args) { void (*func)(void * ) ; int i,iteration ; func = (void(*)(void *))((func_args *)args)->argv[0] ; #ifdef HAVE_KEIL_RTX LockMutex((CyaSSL_Mutex *)&command_mutex) ; #endif iteration = for_iteration ; for(i=0; i< iteration; i++) { if(iteration > 1) printf("--- Start for %d ---->\n", i) ; #if defined(HAVE_KEIL_RTX) stack_fill(command_stack, COMMAND_STACK_SIZE) ; #endif func(args) ; /* invoke command */ #if defined(HAVE_KEIL_RTX) stack_check(command_stack, COMMAND_STACK_SIZE) ; #endif } if(iteration > 1) for_iteration = 1 ; #ifdef HAVE_KEIL_RTX UnLockMutex((CyaSSL_Mutex *)&command_mutex) ; os_tsk_delete_self() ; #endif }
static void on_input_frame (void) { LockMutex (GraphicsLock); RotatePlanetSphere (TRUE); UnlockMutex (GraphicsLock); }
void var_lock (struct varlist *varlist, S4 index) { #if OS_AROS LockMutex (varlist[index].mutex); #else pthread_mutex_lock (&varlist[index].mutex); #endif }
// Initialise the surface graphics, and start the planet music. // Called from the GenerateFunctions.generateOribital() function // (when orbit is entered; either from IP, or from loading a saved game) // and when "starmap" is selected from orbit and then cancelled; // also after in-orbit comm and after defeating planet guards in combat. // SurfDefFrame contains surface definition images when a planet comes // with its own bitmap (currently only for Earth) void LoadPlanet (FRAME SurfDefFrame) { bool WaitMode = !(LastActivity & CHECK_LOAD); PLANET_DESC *pPlanetDesc; #ifdef DEBUG if (disableInteractivity) return; #endif assert (pSolarSysState->InOrbit && !pSolarSysState->TopoFrame); CreatePlanetContext (); if (WaitMode) { LockMutex (GraphicsLock); DrawOrbitalDisplay (DRAW_ORBITAL_WAIT); UnlockMutex (GraphicsLock); } StopMusic (); pPlanetDesc = pSolarSysState->pOrbitalDesc; GeneratePlanetSurface (pPlanetDesc, SurfDefFrame); SetPlanetMusic (pPlanetDesc->data_index & ~PLANET_SHIELDED); GeneratePlanetSide (); if (!PLRPlaying ((MUSIC_REF)~0)) PlayMusic (LanderMusic, TRUE, 1); if (WaitMode) { ZoomInPlanetSphere (); LockMutex (GraphicsLock); DrawOrbitalDisplay (DRAW_ORBITAL_UPDATE); UnlockMutex (GraphicsLock); } else { LockMutex (GraphicsLock); DrawOrbitalDisplay (DRAW_ORBITAL_FULL); UnlockMutex (GraphicsLock); } }