int main(int argc, char **argv) { ULONG FrameFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER | FCF_HIDEBUTTON | FCF_SHELLPOSITION | FCF_TASKLIST; HAB hab; HMQ hmq; HWND Client; QMSG qmsg; arglist args; int python_tid; /* init PM and create message queue */ hab = WinInitialize(0); hmq = WinCreateMsgQueue(hab, 0); /* create a (hidden) Window to house the window procedure */ args.Frame = WinCreateStdWindow(HWND_DESKTOP, 0, &FrameFlags, NULL, "PythonPM", 0L, 0, 0, &Client); /* run Python interpreter in a thread */ args.argc = argc; args.argv = argv; args.running = 0; if (-1 == (python_tid = _beginthread(PythonThread, NULL, 1024 * 1024, &args))) { /* couldn't start thread */ WinAlarm(HWND_DESKTOP, WA_ERROR); PythonRC = 1; } else { /* process PM messages, until Python exits */ while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0)) WinDispatchMsg(hab, &qmsg); if (args.running > 0) DosKillThread(python_tid); } /* destroy window, shutdown message queue and PM */ WinDestroyWindow(args.Frame); WinDestroyMsgQueue(hmq); WinTerminate(hab); return PythonRC; }
void StopKeyBarService(void) { if (KeyBarHelp.service) { KeyBarHelp.flag=0; DosKillThread(KeyBarHelp.service); KeyBarHelp.service=0L; ResetKeyBar(); } }
void StopTimeService(void) { if (Times.service) { DosKillThread(Times.service); Times.service=0L; if (Times.add_service) CHF_RemoveChain(Times.add_service); } }
/*-------------------------------------------------- * Stops the thread *-------------------------------------------------*/ PMThread& PMThread::stop() { if( is_alive() && tid() != -1 ) { APIRET rc = DosKillThread( tid()); if( rc != NO_ERROR && rc != ERROR_INVALID_THREADID ) PM_THROW_OS2ERROR(rc); run_alive = FALSE; run_id = -1; } return *this; }
int sanei_thread_kill( SANE_Pid pid ) { DBG(2, "sanei_thread_kill() will kill %ld\n", (long) pid); #ifdef USE_PTHREAD #if defined (__APPLE__) && defined (__MACH__) return pthread_kill((pthread_t)pid, SIGUSR2); #else return pthread_cancel((pthread_t)pid); #endif #elif defined HAVE_OS2_H return DosKillThread(pid); #else return kill( pid, SIGTERM ); #endif }
/*--------------------------------------------------------------------------------------*\ * Procedure to create/close a secondary thread. * * Req: * * bCreate ....... Create/close a thread * * pUPS_Thread ... Pointer to a function implementing the thread * * Returns: * * TRUE/FALSE .... If called sucessfully/unsucessfully * \*--------------------------------------------------------------------------------------*/ BOOL UPS_ThreadCreate(BOOL bCreate, PFNTHREAD pUPS_Thread) { static ULONG ulThreadArg=0; static ULONG ulThreadFlag=0; static ULONG ulStackSize=8192; static TID tidThread; if(bCreate==TRUE) { DosCreateThread( /* Create a secondary thread */ &tidThread, /* Thread ID of created thread */ pUPS_Thread, /* Pointer to thread */ ulThreadArg, /* Thread arguments */ ulThreadFlag, /* Thread flags */ ulStackSize); /* Thread's stack size */ return(TRUE); } else { DosKillThread( /* Kill the secondary thread */ tidThread); /* Thread ID of thread to be killed */ return(TRUE); } }
void ap_mpm_child_main(apr_pool_t *pconf) { ap_listen_rec *lr = NULL; int requests_this_child = 0; int rv = 0; unsigned long ulTimes; int my_pid = getpid(); ULONG rc, c; HQUEUE workq; apr_pollset_t *pollset; int num_listeners; TID server_maint_tid; void *sb_mem; /* Stop Ctrl-C/Ctrl-Break signals going to child processes */ DosSetSignalExceptionFocus(0, &ulTimes); set_signals(); /* Create pool for child */ apr_pool_create(&pchild, pconf); ap_run_child_init(pchild, ap_server_conf); /* Create an event semaphore used to trigger other threads to shutdown */ rc = DosCreateEventSem(NULL, &shutdown_event, 0, FALSE); if (rc) { ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(rc), ap_server_conf, "unable to create shutdown semaphore, exiting"); clean_child_exit(APEXIT_CHILDFATAL); } /* Gain access to the scoreboard. */ rc = DosGetNamedSharedMem(&sb_mem, ap_scoreboard_fname, PAG_READ|PAG_WRITE); if (rc) { ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(rc), ap_server_conf, "scoreboard not readable in child, exiting"); clean_child_exit(APEXIT_CHILDFATAL); } ap_calc_scoreboard_size(); ap_init_scoreboard(sb_mem); /* Gain access to the accpet mutex */ rc = DosOpenMutexSem(NULL, &ap_mpm_accept_mutex); if (rc) { ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(rc), ap_server_conf, "accept mutex couldn't be accessed in child, exiting"); clean_child_exit(APEXIT_CHILDFATAL); } /* Find our pid in the scoreboard so we know what slot our parent allocated us */ for (child_slot = 0; ap_scoreboard_image->parent[child_slot].pid != my_pid && child_slot < HARD_SERVER_LIMIT; child_slot++); if (child_slot == HARD_SERVER_LIMIT) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, "child pid not found in scoreboard, exiting"); clean_child_exit(APEXIT_CHILDFATAL); } ap_my_generation = ap_scoreboard_image->parent[child_slot].generation; memset(ap_scoreboard_image->servers[child_slot], 0, sizeof(worker_score) * HARD_THREAD_LIMIT); /* Set up an OS/2 queue for passing connections & termination requests * to worker threads */ rc = DosCreateQueue(&workq, QUE_FIFO, apr_psprintf(pchild, "/queues/httpd/work.%d", my_pid)); if (rc) { ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(rc), ap_server_conf, "unable to create work queue, exiting"); clean_child_exit(APEXIT_CHILDFATAL); } /* Create initial pool of worker threads */ for (c = 0; c < ap_min_spare_threads; c++) { // ap_scoreboard_image->servers[child_slot][c].tid = _beginthread(worker_main, NULL, 128*1024, (void *)c); } /* Start maintenance thread */ server_maint_tid = _beginthread(server_maintenance, NULL, 32768, NULL); /* Set up poll */ for (num_listeners = 0, lr = ap_listeners; lr; lr = lr->next) { num_listeners++; } apr_pollset_create(&pollset, num_listeners, pchild, 0); for (lr = ap_listeners; lr != NULL; lr = lr->next) { apr_pollfd_t pfd = { 0 }; pfd.desc_type = APR_POLL_SOCKET; pfd.desc.s = lr->sd; pfd.reqevents = APR_POLLIN; pfd.client_data = lr; apr_pollset_add(pollset, &pfd); } /* Main connection accept loop */ do { apr_pool_t *pconn; worker_args_t *worker_args; int last_poll_idx = 0; apr_pool_create(&pconn, pchild); worker_args = apr_palloc(pconn, sizeof(worker_args_t)); worker_args->pconn = pconn; if (num_listeners == 1) { rv = apr_socket_accept(&worker_args->conn_sd, ap_listeners->sd, pconn); } else { const apr_pollfd_t *poll_results; apr_int32_t num_poll_results; rc = DosRequestMutexSem(ap_mpm_accept_mutex, SEM_INDEFINITE_WAIT); if (shutdown_pending) { DosReleaseMutexSem(ap_mpm_accept_mutex); break; } rv = APR_FROM_OS_ERROR(rc); if (rv == APR_SUCCESS) { rv = apr_pollset_poll(pollset, -1, &num_poll_results, &poll_results); DosReleaseMutexSem(ap_mpm_accept_mutex); } if (rv == APR_SUCCESS) { if (last_poll_idx >= num_listeners) { last_poll_idx = 0; } lr = poll_results[last_poll_idx++].client_data; rv = apr_socket_accept(&worker_args->conn_sd, lr->sd, pconn); last_poll_idx++; } } if (rv != APR_SUCCESS) { if (!APR_STATUS_IS_EINTR(rv)) { ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, "apr_socket_accept"); clean_child_exit(APEXIT_CHILDFATAL); } } else { DosWriteQueue(workq, WORKTYPE_CONN, sizeof(worker_args_t), worker_args, 0); requests_this_child++; } if (ap_max_requests_per_child != 0 && requests_this_child >= ap_max_requests_per_child) break; } while (!shutdown_pending && ap_my_generation == ap_scoreboard_image->global->running_generation); ap_scoreboard_image->parent[child_slot].quiescing = 1; DosPostEventSem(shutdown_event); DosWaitThread(&server_maint_tid, DCWW_WAIT); if (is_graceful) { char someleft; /* tell our worker threads to exit */ for (c=0; c<HARD_THREAD_LIMIT; c++) { if (ap_scoreboard_image->servers[child_slot][c].status != SERVER_DEAD) { DosWriteQueue(workq, WORKTYPE_EXIT, 0, NULL, 0); } } do { someleft = 0; for (c=0; c<HARD_THREAD_LIMIT; c++) { if (ap_scoreboard_image->servers[child_slot][c].status != SERVER_DEAD) { someleft = 1; DosSleep(1000); break; } } } while (someleft); } else { DosPurgeQueue(workq); for (c=0; c<HARD_THREAD_LIMIT; c++) { if (ap_scoreboard_image->servers[child_slot][c].status != SERVER_DEAD) { DosKillThread(ap_scoreboard_image->servers[child_slot][c].tid); } } } apr_pool_destroy(pchild); }
int main (int argc, char *argv[]) { APIRET rc; PCHAR pcEnv; PRFPROFILE prfProfile; #ifdef DEBUG ulDebugMask = 0xFFFFFFFF; #endif /* DEBUG */ hab = WinInitialize(0); hmq = WinCreateMsgQueue(hab, 0); DebugS (1, "PM Interface initialized"); /* Shared Memory organisieren */ if (rc = DosGetNamedSharedMem ((PPVOID) &pShareInitOS2, SHARE_INITOS2, PAG_READ | PAG_WRITE)) { if (rc = DosAllocSharedMem( (PPVOID) &pShareInitOS2, // Pointer to shared mem SHARE_INITOS2, // Name CCHSHARE_INITOS2, // Size of shared mem PAG_COMMIT | PAG_READ | PAG_WRITE)) // Flags return(1); else { /* Shared Memory initialisieren */ memset (pShareInitOS2, '\0', CCHSHARE_INITOS2); pShareInitOS2->pszRegFile = (PCHAR) pShareInitOS2 + sizeof(*pShareInitOS2); strcpy (pShareInitOS2->pszRegFile, DosScanEnv (ENV_SYSTEM_INI, &pcEnv) ? "" : pcEnv); pShareInitOS2->pszRootUserIni = pShareInitOS2->pszRegFile + strlen(pShareInitOS2->pszRegFile) + 1; pShareInitOS2->pszRootSystemIni = pShareInitOS2->pszRootUserIni + 1; pShareInitOS2->pszUserIni = pShareInitOS2->pszRootSystemIni + 1; pShareInitOS2->pszSystemIni = pShareInitOS2->pszUserIni + CCHMAXPATH; pShareInitOS2->pszEnvironment = pShareInitOS2->pszSystemIni + CCHMAXPATH; } } DebugS (1, "Shared Memory initialized"); /* Semaphoren organisieren */ rc = DosOpenEventSem (HEV_SAMMY, &hevSammy); if( rc ) rc = DosCreateEventSem( HEV_SAMMY, // Name &hevSammy, // Pointer to sem 0, // Not used with named sems FALSE); // Initial state (FALSE = SET) else /* Sammy ist bereits installiert */ { pShareInitOS2->pszEnvironment[0] = '\0'; pShareInitOS2->pszEnvironment[1] = '\0'; pShareInitOS2->pszSystemIni[0] = '\0'; pShareInitOS2->pszUserIni[0] = '\0'; DosPostEventSem(hevSammy); goto Exit; } if( rc ) { intSammyRetCode = rc; goto Exit; } rc = DosOpenEventSem (HEV_PRFRESETLOCK, &hevPrfResetLock); if( rc ) rc = DosCreateEventSem( HEV_PRFRESETLOCK, // Name &hevPrfResetLock, // Pointer to sem 0, // Not used with named sems TRUE); // Initial state (TRUE = POSTED) if( rc ) { intSammyRetCode = rc; goto Exit; } DebugS (1, "Semaphores initialized"); ChangeWPS(pShareInitOS2->pszUserIni, pShareInitOS2->pszSystemIni); /* Hintergrundloop starten, das Shell mit aktueller Env. startet */ DosCreateThread (&tid1, (PFNTHREAD) thStartProg, (ULONG) ((argc > 1) ? argv[1] : ""), 0, THREADSTACK); DebugS (1, "Background loop started"); /* Hintergrundloop starten, das jeweils nach L�schen einer Semaphore */ /* einen prfReset initiiert */ DosCreateThread (&tid2, (PFNTHREAD) thSwitch, (ULONG) 0, 0, THREADSTACK); while (WinGetMsg (hab, &qmsg, 0, 0, 0)) WinDispatchMsg (hab, &qmsg); if (intSammyRetCode) { DosKillThread (tid1); DosKillThread (tid2); WinSetObjectData(WinQueryObject("<WP_DESKTOP>"), "WORKAREA=NO"); WinPostMsg(WinQueryWindow(HWND_DESKTOP, QW_BOTTOM), WM_CLOSE, 0, 0); WinAlarm (HWND_DESKTOP, WA_ERROR); prfProfile.pszSysName = (DosScanEnv (ENV_SYSTEM_INI, &pcEnv) ? "" : pcEnv); prfProfile.pszUserName = (DosScanEnv (ENV_USER_INI, &pcEnv) ? "" : pcEnv); prfProfile.cchUserName = strlen(prfProfile.pszUserName); prfProfile.cchSysName = strlen(prfProfile.pszSysName); DosSleep (1000); DosKillProcess( DKP_PROCESSTREE, ulShellID ); if ( !PrfReset(hab, &prfProfile)) WinSetObjectData(WinQueryObject("<WP_DESKTOP>"), "OPEN=ICON;WORKAREA=YES"); } Exit: WinDestroyMsgQueue(hmq); WinTerminate(hab); DebugS (1, "Application terminated"); return intSammyRetCode; }
/* WARNING: This function is really a last resort. * Threads should be signaled and then exit by themselves. * TerminateThread() doesn't perform stack and DLL cleanup. */ void SDL_SYS_KillThread(SDL_Thread *thread) { DosKillThread(thread->handle); }
MRESULT EXPENTRY fnwpNotifyDlg(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2) { static MSG *pMessage; NOTIFYLST *pNotify; ULONG ulSubNumber; ULONG ulGroupNumber; int iMsgLen; USHORT usLength; USHORT usSubCount; ULONG *pulSubNum; char szMessage[80]; int iIndex; static TID tid; BYTE *pData; switch (msg) { case WM_INITDLG: pMessage = (MSG *)mp2; bNotifyLoop = FALSE; WinSendDlgItemMsg(hwnd,NOTIFY_SUB_NUMBER, SPBM_SETLIMITS, (MPARAM)usSubscriberListCount, (MPARAM)1); WinSendDlgItemMsg(hwnd,NOTIFY_MESSAGE,MLM_FORMAT,(MPARAM)MLFIE_WINFMT,(MPARAM)NULL); break; case WM_COMMAND: switch(SHORT1FROMMP(mp1)) { case DID_OK: if (bNotifyLoop) break; WinSendDlgItemMsg(hwnd,NOTIFY_SUB_NUMBER,SPBM_QUERYVALUE,&ulSubNumber,MPFROM2SHORT(0,SPBQ_DONOTUPDATE)); iMsgLen = WinQueryDlgItemTextLength(hwnd,NOTIFY_MESSAGE); // iMsgLen = (int)WinSendDlgItemMsg(hwnd,NOTIFY_MESSAGE,MLM_QUERYTEXTLENGTH,(MPARAM)NULL,(MPARAM)NULL); if (iMsgLen <= 0) { sprintf(szMessage,"Message is too short, length = %u",iMsgLen); MessageBox(hwnd,szMessage); break; } if (astSubList[ulSubNumber].usMaxMsgLen < iMsgLen) { sprintf(szMessage,"Message is to long for defined subscriber, remove at least %u characters.",(iMsgLen - astSubList[ulSubNumber].usMaxMsgLen)); MessageBox(hwnd,szMessage); break; } pNotify = (NOTIFYLST *)&pMessage->byData; pNotify->usSubCount = 1; pNotify->usGroupCount = 0; pNotify->usMsgLen = (USHORT)iMsgLen; pData = &pNotify->byData; iMsgLen = WinQueryDlgItemText(hwnd,NOTIFY_MESSAGE,(iMsgLen + 1),pData); pulSubNum = (ULONG *)(pData + iMsgLen); usSubCount = 0; for (iIndex = 0;iIndex < pNotify->usSubCount;iIndex++) { usSubCount++; *pulSubNum = (ULONG)ulSubNumber; pulSubNum++; } for (iIndex = 0;iIndex < pNotify->usGroupCount;iIndex++) { usSubCount++; *pulSubNum = (ULONG)ulGroupNumber; pulSubNum++; } usLength = ((sizeof(ULONG) * usSubCount) + (USHORT)iMsgLen); pMessage->cbDataSize = (usLength + sizeof(NOTIFYLST) - 1); if (Checked(hwnd,NOTIFY_CONTINUOUSLY)) { pMessage->fMessageType = REQ_NOTIFY; pMessage->cbSize = (pMessage->cbDataSize + sizeof(MSG) - 1); bNotifyLoop = TRUE; pNotifyLoopMsg = pMessage; DosCreateThread(&tid,(PFNTHREAD)NotifyLoopThread,(ULONG)pMessage,0,8192); } else WinDismissDlg(hwnd,TRUE); break; case DID_CANCEL: if (bNotifyLoop) DosKillThread(tid); WinDismissDlg(hwnd,FALSE); break; default: return(WinDefDlgProc(hwnd,msg,mp1,mp2)); } break; default: return(WinDefDlgProc(hwnd,msg,mp1,mp2)); } return(FALSE); }
VOID gropFree(PGROPDATA pGrop) { ULONG ulRC; HMQ hmq; TID tid; ulRC = DosRequestMutexSem( pGrop->hmtxData, 4000 ); if ( ulRC != NO_ERROR ) debug( "DosRequestMutexSem(), rc = %u", ulRC ); hmq = pGrop->hmq; tid = pGrop->tid; // Tune off all callback functions. memset( &pGrop->stCallback, 0, sizeof(GROPCALLBACK) ); DosReleaseMutexSem( pGrop->hmtxData ); if ( ( hmq == NULLHANDLE ) || !WinPostQueueMsg( hmq, WM_QUIT, 0, 0 ) ) { debug( "Hm... have not a thread?..." ); if ( pGrop->fFullscreen ) _setMode( pGrop, pGrop->ulModeIdx, FALSE ); if ( tid != ((TID)(-1)) ) { debug( "WTF?! %p %d", pGrop, tid ); DosKillThread( tid ); } } else if ( DosWaitThread( &tid, DCWW_NOWAIT ) != NO_ERROR ) { debug( "Wait thread semaphore" ); ulRC = DosWaitEventSem( pGrop->hevReady, 4000 ); if ( ulRC != NO_ERROR ) { PVIDEOMODE pMode = &pGrop->stModes.pList[pGrop->stModes.ulDesktopMode]; debug( "DosWaitEventSem(), rc = %u. Kill thread...", ulRC ); DosKillThread( tid ); if ( pGrop->hwndDT != NULLHANDLE ) { debug( "Return to the desktop..." ); pGrop->pVideoSys->fnSetMode( pGrop->pVSData, pMode, FALSE, pGrop->hwndDT, pGrop->hdcDT ); } } else { debug( "Wait thread" ); DosWaitThread( &tid, DCWW_WAIT ); } } else debug( "Thread already terminated." ); // Remove GROP object from the list. ulRC = DosRequestMutexSem( hmtxGropList, SEM_INDEFINITE_WAIT ); if ( ulRC != NO_ERROR ) debug( "DosRequestMutexSem(), rc = %u", ulRC ); lnkseqRemove( &lsGropList, pGrop ); DosReleaseMutexSem( hmtxGropList ); DosCloseEventSem( pGrop->hevReady ); debugFree( pGrop ); debug( "Success." ); }
PGROPDATA gropNew(ULONG ulVideoSys, PGROPCALLBACK pCallback, PVOID pUser) { ULONG ulRC; PGROPDATA pGrop; if ( hmtxGropList == NULLHANDLE ) { debug( "Module was not initialized." ); return NULL; } pGrop = debugCAlloc( 1, sizeof(GROPDATA) ); if ( pGrop == NULL ) { debug( "Not enough memory." ); return NULL; } pGrop->ulVideoSysIdx = ulVideoSys; pGrop->stCallback = *pCallback; pGrop->pUser = pUser; do { ulRC = DosCreateEventSem( NULL, &pGrop->hevReady, DCE_POSTONE, FALSE ); if ( ulRC != NO_ERROR ) { debug( "DosCreateEventSem(), rc = %u.", ulRC ); break; } pGrop->tid = _beginthread( wndThread, NULL, 65536, (PVOID)pGrop ); if ( pGrop->tid == -1 ) { debug( "_beginthread() failed." ); break; } ulRC = DosWaitEventSem( pGrop->hevReady, 5000 ); if ( ulRC == NO_ERROR ) { if ( pGrop->pVideoSys == NULL ) break; // Add new GROP object to the list. ulRC = DosRequestMutexSem( hmtxGropList, SEM_INDEFINITE_WAIT ); if ( ulRC != NO_ERROR ) debug( "DosRequestMutexSem(), rc = %u", ulRC ); lnkseqAdd( &lsGropList, pGrop ); DosReleaseMutexSem( hmtxGropList ); debug( "Success." ); return pGrop; } debug( "DosWaitEventSem(), rc = %u.", ulRC ); DosKillThread( pGrop->tid ); } while( FALSE ); DosCloseEventSem( pGrop->hevReady ); debugFree( pGrop ); return NULL; }