Ejemplo n.º 1
0
int GUI::OpenPipe(char *Command, EModel *notify) {
  int i;

  for (i = 0; i < MAX_PIPES; i++) {
    if (Pipes[i].used == 0) {
      Pipes[i].reading = 1;
      Pipes[i].stopped = 1;
      Pipes[i].id      = i;
      Pipes[i].bufused = 0;
      Pipes[i].bufpos  = 0;
      Pipes[i].buflen  = PIPE_BUFLEN;
      Pipes[i].Command = strdup(Command);
      Pipes[i].notify  = notify;
      Pipes[i].DoTerm  = 0;

      if ((Pipes[i].buffer = (char *)malloc(PIPE_BUFLEN)) == 0) {
        free(Pipes[i].Command);
        return -1;
      }

      if (0 != DosCreateMutexSem(0, &Pipes[i].Access, 0, 0)) {
        free(Pipes[i].Command);
        free(Pipes[i].buffer);
        return -1;
      }

      if (0 != DosCreateEventSem(0, &Pipes[i].ResumeRead, 0, 0)) {
        free(Pipes[i].Command);
        free(Pipes[i].buffer);
        DosCloseMutexSem(Pipes[i].Access);
        return -1;
      }

      if (0 != DosCreateEventSem(0, &Pipes[i].NewData, 0, 0)) {
        free(Pipes[i].Command);
        free(Pipes[i].buffer);
        DosCloseEventSem(Pipes[i].ResumeRead);
        DosCloseMutexSem(Pipes[i].Access);
        return -1;
      }

#if defined(__WATCOMC__) || defined(__MT__) || defined(__MULTI__)
      Pipes[i].tid = _beginthread(PipeThread,
                                  FAKE_BEGINTHREAD_NULL
                                  16384, &Pipes[i]);
#else // if defined(__WATCOMC__) || defined(__MT__) || defined(__MULTI__)
      DosCreateThread(Pipes[i].tid,
                      (PFNTHREAD)PipeThread,
                      &Pipes[i],
                      0, /* immediate */
                      16384);
#endif // if defined(__WATCOMC__) || defined(__MT__) || defined(__MULTI__)
      Pipes[i].used = 1;

      // fprintf(stderr, "Pipe Open: %d\n", i);
      return i;
    }
  }
  return -1;
}
Ejemplo n.º 2
0
static int RequestCom(void)
{
   USHORT res;
   HMTX sem=0;

   printf("Sending message to AM4PM to release COM port\n");
   res=SendExtQMsg(EQ_RELCOM, NULL, 0);
   if (res)
      return res;

   res=DosOpenMutexSem(szSemCom, &sem);
   if (res)
   {
      printf("Error %u opening semaphore\n", res);
      return 3;
   }

   res=DosRequestMutexSem(sem, 120000l);
   if (res)
   {
      DosCloseMutexSem(sem);
      if (res==ERROR_TIMEOUT)
      {
         printf("Timeout waiting for AM4PM to release COM port\n");
         return 4;
      }
      printf("Error %u waiting for semaphore\n", res);
      return 3;
   }

   DosReleaseMutexSem(sem);
   DosCloseMutexSem(sem);
   return 0;
}
Ejemplo n.º 3
0
int CloseMarkerList(PMARKERLIST pList)
{
   if (DosCloseMutexSem(pList->hmtxAccess))
      return 1;
   else
      return 0;
}
Ejemplo n.º 4
0
/*
** This routine deallocates a previously allocated mutex.
** SQLite is careful to deallocate every mutex that it allocates.
*/
void sqlite3_mutex_free(sqlite3_mutex *p){
  assert( p );
  assert( p->nRef==0 );
  assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
  DosCloseMutexSem( p->mutex );
  sqlite3_free( p );
}
Ejemplo n.º 5
0
//---------------------------------------------------------------------
// LibMain
//
// This gets called at DLL initialization and termination.
//---------------------------------------------------------------------
unsigned _System LibMain(unsigned hmod, unsigned termination)
{
  int i;

  if (termination)
  {
    // Cleanup!
    if (bRunning)
      SSModule_StopSaving();

    // Free NLS text, if it wouldn't be (safety net)
    for (i=0; i<SSMODULE_NLSTEXT_MAX+1; i++)
    {
      if (apchNLSText[i])
      {
        free(apchNLSText[i]);
        apchNLSText[i] = NULL;
      }
    }
    // Free semaphore
    DosCloseMutexSem(hmtxUseNLSTextArray); hmtxUseNLSTextArray = NULLHANDLE;
  } else
  {
    // Startup!
    hmodOurDLLHandle = (HMODULE) hmod;
    bRunning = FALSE;
    // Initialize NLS text array
    for (i=0; i<SSMODULE_NLSTEXT_MAX+1; i++)
      apchNLSText[i] = NULL;
    // Create semaphore to protect it
    DosCreateMutexSem(NULL, &hmtxUseNLSTextArray, 0, FALSE);
  }
  return 1;
}
Ejemplo n.º 6
0
/*
** This routine deallocates a previously allocated mutex.
** SQLite is careful to deallocate every mutex that it allocates.
*/
static void os2MutexFree(sqlite3_mutex *p){
  if( p==0 ) return;
  assert( p->nRef==0 );
  assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
  DosCloseMutexSem( p->mutex );
  sqlite3_free( p );
}
Ejemplo n.º 7
0
static cairo_status_t
_cairo_os2_surface_finish (void *abstract_surface)
{
    cairo_os2_surface_t *local_os2_surface;

    local_os2_surface = (cairo_os2_surface_t *) abstract_surface;
    if ((!local_os2_surface) ||
        (local_os2_surface->base.backend != &cairo_os2_surface_backend))
    {
        /* Invalid parameter (wrong surface)! */
        return _cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
    }

    DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT);

    /* Destroy old image surface */
    cairo_surface_destroy ((cairo_surface_t *) (local_os2_surface->image_surface));
    /* Destroy old pixel buffer */
    _buffer_free (local_os2_surface->pixels);
    DosCloseMutexSem (local_os2_surface->hmtx_use_private_fields);
    DosCloseEventSem (local_os2_surface->hev_pixel_array_came_back);

    /* The memory itself will be free'd by the cairo_surface_destroy ()
     * who called us.
     */

    return CAIRO_STATUS_SUCCESS;
}
Ejemplo n.º 8
0
int GetClipText(ClipData *cd) {
    int rc;
    ULONG PostCount;
    char *mem;
    
    rc = DosOpenMutexSem(SEM_PREFIX "CLIPSYN", &hmtxSyn);
    if (rc != 0) return -1;
    rc = DosOpenEventSem(SEM_PREFIX "CLIPGET", &hevGet);
    if (rc != 0) return -1;
/*    rc = DosOpenEventSem(SEM_PREFIX "CLIPPUT", &hevPut);*/
/*    if (rc != 0) return -1;*/
    rc = DosOpenEventSem(SEM_PREFIX "CLIPEND", &hevEnd);
    if (rc != 0) return -1;
    
    DosRequestMutexSem(hmtxSyn, SEM_INDEFINITE_WAIT);
    DosResetEventSem(hevEnd, &PostCount);
    DosPostEventSem(hevGet);
    DosWaitEventSem(hevEnd, SEM_INDEFINITE_WAIT);
    if (0 == DosGetNamedSharedMem((void **)&mem, MEM_PREFIX "CLIPDATA", PAG_READ | PAG_WRITE)) {
        cd->fLen = *(ULONG*)mem;
        cd->fChar = strdup(mem + 4);
        DosFreeMem(mem);
    } else {
        cd->fLen = 0;
        cd->fChar = 0;
    }
    DosPostEventSem(hevGet);
    DosReleaseMutexSem(hmtxSyn);
/*    DosCloseEventSem(hevPut);*/
    DosCloseEventSem(hevGet);
    DosCloseEventSem(hevEnd);
    DosCloseMutexSem(hmtxSyn);
    return 0;
}
Ejemplo n.º 9
0
omni_condition::~omni_condition(void)
{
    DosCloseMutexSem( crit );
    DB( if (waiting_head != NULL) {
    cerr << "omni_condition::~omni_condition: list of waiting threads "
         << "is not empty\n";
    } )
}
Ejemplo n.º 10
0
void Uninitialize_ChannelSetList()
{
  if (ChannelSetListProtector_Sem==-1) return;

  EraseChannelSetList();

  DosCloseMutexSem(ChannelSetListProtector_Sem); ChannelSetListProtector_Sem = -1;
}
Ejemplo n.º 11
0
void fly_terminate (void)
{
    int  rc;
    
    WinPostMsg (hwndFrame, WM_QUIT, 0, 0);
    
    rc = DosCloseMutexSem (mtx_Queue);
    debug_tools ("rc = %d after DosCloseMutexSem1\n", rc);
    
    rc = DosCloseMutexSem (mtx_Video);
    
    debug_tools ("%d menu item changes\n", item_status_change);
    
    _tfree (tiled1);
    _tfree (us1_16);
    _tfree (us2_16);
    fl_opt.initialized = FALSE;
}
Ejemplo n.º 12
0
void Uninitialize_PluginList()
{
  if (PluginListProtector_Sem==-1) return;

  UninitializeAllPlugins(HWND_DESKTOP);
  ErasePluginList();

  DosCloseMutexSem(PluginListProtector_Sem); PluginListProtector_Sem = -1;
}
Ejemplo n.º 13
0
/* Free the semaphore */
DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_sem *sem)
{
        if ( sem ) {
                if ( sem->id ) {
                        DosCloseEventSem(sem->changed);
                        DosCloseMutexSem(sem->id);
                        sem->id = 0;
                }
                SDL_free(sem);
        }
}
Ejemplo n.º 14
0
int DLLCALL pthread_mutex_destroy(pthread_mutex_t* mutex)
{
#if defined(PTHREAD_MUTEX_AS_WIN32_MUTEX)
	return (CloseHandle(*mutex) ? 0 : GetLastError());
#elif defined(_WIN32)	/* Win32 Critical Section */
	DeleteCriticalSection(mutex);
	return 0;	/* No error */
#elif defined(__OS2__)
	return DosCloseMutexSem(*mutex);
#endif
}
Ejemplo n.º 15
0
/* Free the mutex */
DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex *mutex)
{
  if ( mutex )
  {
    if ( mutex->hmtxID )
    {
      DosCloseMutexSem(mutex->hmtxID);
      mutex->hmtxID = 0;
    }
    SDL_free(mutex);
  }
}
Ejemplo n.º 16
0
/*
** This routine deallocates a previously allocated mutex.
** SQLite is careful to deallocate every mutex that it allocates.
*/
static void os2MutexFree(sqlite3_mutex *p){
#ifdef SQLITE_DEBUG
  TID tid;
  PID pid;
  ULONG ulCount;
  DosQueryMutexSem(p->mutex, &pid, &tid, &ulCount);
  assert( ulCount==0 );
  assert( p->id==SQLITE_MUTEX_FAST || p->id==SQLITE_MUTEX_RECURSIVE );
#endif
  DosCloseMutexSem( p->mutex );
  sqlite3_free( p );
}
Ejemplo n.º 17
0
void enter_sync()
{
    if (Mutex == NULL)
    {   // first call => initialize mutex
        HMTX newmtx;
        DosCreateMutexSem(NULL, &newmtx, 0, FALSE);
        if (InterlockedCxc((volatile unsigned*)&Mutex, 0, (unsigned)newmtx) != 0)
            // compare exchange failed => destroy mutex
            DosCloseMutexSem(newmtx);
    }
    DosRequestMutexSem(Mutex, SEM_INDEFINITE_WAIT);
}
Ejemplo n.º 18
0
/* Strange! If video_init fails this is called without calling DosOpen before! */
void joystick_close(void)
{
    APIRET rc;
    DosRequestMutexSem(hmtxJoystick, SEM_INDEFINITE_WAIT);
    rc=DosClose(SWhGame);
    DosCloseMutexSem(hmtxJoystick);

    if (!rc)
        return;

    log_error(joylog, "DosClose 'GAME$' (rc=%i)", rc);
}
Ejemplo n.º 19
0
void            __FiniFThreadProcessing( void ) {
//===============================================

#if defined( __OS2__ )
    DosCloseMutexSem( __fio_sem );
#elif defined( __NETWARE__ )
    CloseLocalSemaphore( __fio_sem );
#elif defined( __NT__ )
    CloseHandle( __fio_sem );
#elif defined( __LINUX__ )
// TODO: semaphore support for Linux!
#endif
}
Ejemplo n.º 20
0
RTDECL(int)  RTSemMutexDestroy(RTSEMMUTEX hMutexSem)
{
    if (hMutexSem == NIL_RTSEMMUTEX)
        return VINF_SUCCESS;

    /*
     * Close semaphore handle.
     */
    int rc = DosCloseMutexSem(SEM2HND(hMutexSem));
    if (!rc)
        return VINF_SUCCESS;
    AssertMsgFailed(("Destroy hMutexSem %p failed, rc=%d\n", hMutexSem, rc));
    return RTErrConvertFromOS2(rc);
}
Ejemplo n.º 21
0
static apr_status_t thread_cond_cleanup(void *data)
{
    apr_thread_cond_t *cv = data;

    if (cv->semaphore) {
        DosCloseEventSem(cv->semaphore);
    }

    if (cv->mutex) {
        DosCloseMutexSem(cv->mutex);
    }

    return APR_SUCCESS;
}
Ejemplo n.º 22
0
VOID gropDone()
{
  debug( "Enter" );

  if ( lInitTime == 0 )
    return;

  lInitTime--;
  if ( lInitTime == 0 )
  {
    debug( "%u GROP objects left.", lnkseqGetCount( &lsGropList ) );
    _gropAllToDesktop();
    DosCloseMutexSem( hmtxGropList );
    hmtxGropList = NULLHANDLE;
    debugDone();
  }
}
Ejemplo n.º 23
0
APR_DECLARE(apr_status_t) apr_thread_mutex_destroy(apr_thread_mutex_t *mutex)
{
    ULONG rc;

    if (mutex->hMutex == 0)
        return APR_SUCCESS;

    while (DosReleaseMutexSem(mutex->hMutex) == 0);

    rc = DosCloseMutexSem(mutex->hMutex);

    if (!rc) {
        mutex->hMutex = 0;
        return APR_SUCCESS;
    }

    return APR_FROM_OS_ERROR(rc);
}
/****************************************************************\
 * Routine to really stop semaphore example.                    *
 *--------------------------------------------------------------*
 *                                                              *
 *  Name:     StopSemaphore( PVOID pvArg )                      *
 *                                                              *
 *  Purpose:  Waits for threads to complete,                    *
 *            Sends message to message thread to indicate this  *
 *            has occurred, and exits.                          *
 *                                                              *
 *  Usage:    Exec'd from BeginStop when user selects Stop from *
 *            Semaphore menu.                                   *
 *                                                              *
 *  Method:   Turns off Auto mode, if present by posting auto   *
 *            semaphore.  Then stop event is posted.  Waits     *
 *            for threads to die.                               *
 *  Returns:                                                    *
 *                                                              *
\****************************************************************/
VOID StopSemaphore( PVOID pvArg )
{
   ULONG rc,usCount, i;
   PULONG pfAutoMode = (PULONG)pvArg;

   if (*pfAutoMode)
   {
      rc = DosWaitThread(&tidAutoThread,0L);
      if (rc && (rc != ERROR_INVALID_THREADID))
      {
         SemError("DosWaitThread",rc);
      }
      *pfAutoMode = FALSE;
   }
   /* Wait for usConsumer threads to die.  Order of death not important. */

   for (usCount = 0; usCount < usConsumerThreadsCreated; usCount++)
   {
      rc = DosWaitThread(&thrConsumers[usCount].tid,0L);

      /* rc is ERROR_INVALID_THREADID the thread is already dead.*\
      \* This is OK and not a error.                             */

      if (rc && (rc != ERROR_INVALID_THREADID))
      {
         SemError("DosWaitThread",rc);
      }
   }
                /* Threads dead so we don't need semaphores any more.  */
   DosCloseEventSem(hevStopAuto);
   DosCloseEventSem(hevStop);
   DosCloseMutexSem(hmtxOwnResource);
   for (i = 0; i < MAXRESOURCES; i++)
   {
      DosCloseEventSem(aSquares[i].hev);
   }
   DosCloseMuxWaitSem (hmuxResource);
   WinPostMsg (hwndMain, WM_COMMAND, (MPARAM)IDM_STOPFINISHED, (MPARAM)NULL);
   DosExit (EXIT_THREAD, 0);
   return;
}
Ejemplo n.º 25
0
_WCRTLINK void __CloseSemaphore( semaphore_object *obj )
{
#if defined( __RUNTIME_CHECKS__ ) && defined( _M_IX86 )
    // 0 is ok
    // 1 is ok  // JBS I don't think so. I would mean a critical section is active.
                // JBS For every lock, there should be an unlock.
//    if( obj->count >= 2 ) {
//        __fatal_runtime_error( "Semaphore locked too many times", 1 );
//    }
    if( obj->count >= 1 ) {
        __fatal_runtime_error( "Semaphore not unlocked", 1 );
    }
#endif
#if !defined( __NT__ )
  #if defined( _M_I86 )
    if( obj->count > 0 ) {
        DosSemClear( &obj->semaphore );
    }
  #else
    if( obj->initialized != 0 ) {
    #if defined( __NETWARE__ )
        obj->semaphore = 0;
    #elif defined( __QNX__ )
        __qsem_destroy( &obj->semaphore );
    #elif defined( __LINUX__ )
        // TODO: Close the semaphore for Linux!
    #elif defined( __RDOS__ )
        RdosDeleteSection( obj->semaphore );
        obj->semaphore = 0;
    #elif defined( __RDOSDEV__ )
    #else
        DosCloseMutexSem( obj->semaphore );
    #endif
    }
  #endif
    obj->initialized = 0;
    obj->owner = 0;
    obj->count = 0;
#endif
}
Ejemplo n.º 26
0
extern "C" APIRET APIENTRY InitSrvConn(char *remotemachineName, ULONG *obj)
{
  int  rc;

  /* First  let's look for FreePM.ini and read it if any */
  FPM_config.Read("fpm.ini");

  if (remotemachineName)
  {
    strcpy(FPM_config.ExternMachineName, remotemachineName);
    ExternMachine = &FPM_config.ExternMachineName[0];
  } else {
    /* test for FreePM's semaphore  at local machine */

    HMTX    FREEPM_hmtx     = NULLHANDLE; /* Mutex semaphore handle */

    rc = DosOpenMutexSem(FREEPM_MUTEX_NAME,    /* Semaphore name */
                         &FREEPM_hmtx);        /* Handle returned */

    DosCloseMutexSem(FREEPM_hmtx);

    if (rc)
      /* FreePM server is not running at local machine, let's look for FreePM.ini */
      ExternMachine = &FPM_config.ExternMachineName[0];
    else
      ExternMachine = NULL;
  }

  /* init connection to FreePM server */
  rc = InitServerConnection(ExternMachine, obj);

  if (rc && ExternMachine)
  {
     ExecuteFreePMServer();
     DosSleep(1000);
     rc = InitServerConnection(NULL, obj);
  }

  return rc;
}
void EditBoxCollection::Done()
{
    StoreHistory();
    shutdown = 1;

    lock();
    RemoveAll();

//    MouClose(MouHandle);
    npFED.Close();
    DosCloseMutexSem(hMtx);

    DosSleep(1);
    DosSleep(1);
    DosSleep(1);

    delete ppTmr;
    delete ppMou;
    delete ppPip;

    vio_shutdown();
}
Ejemplo n.º 28
0
int GUI::ClosePipe(int id) {
  if ((id < 0) || (id > MAX_PIPES)) return -1;

  if (Pipes[id].used == 0) return -1;

  if (Pipes[id].reading == 1) {
    Pipes[id].DoTerm = 1;
    DosPostEventSem(Pipes[id].ResumeRead);
    DosWaitThread(&Pipes[id].tid, DCWW_WAIT);
  }
  free(Pipes[id].buffer);
  free(Pipes[id].Command);
  DosCloseEventSem(Pipes[id].NewData);
  DosCloseEventSem(Pipes[id].ResumeRead);
  DosCloseMutexSem(Pipes[id].Access);

  //    fprintf(stderr, "Pipe Close: %d\n", id);
  Pipes[id].used = 0;

  // ConContinue();
  return Pipes[id].RetCode;
}
Ejemplo n.º 29
0
int PutClipText(ClipData *cd) {
    int rc;
    ULONG PostCount;
    char *mem;
    
    rc = DosOpenMutexSem(SEM_PREFIX "CLIPSYN", &hmtxSyn);
    if (rc != 0) return -1;
/*    rc = DosOpenEventSem(SEM_PREFIX "CLIPGET", &hevGet);*/
/*    if (rc != 0) return -1;*/
    rc = DosOpenEventSem(SEM_PREFIX "CLIPPUT", &hevPut);
    if (rc != 0) return -1;
    rc = DosOpenEventSem(SEM_PREFIX "CLIPEND", &hevEnd);
    if (rc != 0) return -1;
    
    DosRequestMutexSem(hmtxSyn, SEM_INDEFINITE_WAIT);
    DosResetEventSem(hevEnd, &PostCount);
    if (0 == DosAllocSharedMem((void **)&mem,
                               MEM_PREFIX "CLIPDATA",
                               cd->fLen + 5,
                               PAG_COMMIT | PAG_READ | PAG_WRITE))
    {
        ULONG L = cd->fLen;
        memcpy((void *)mem, (void *)&L, 4);
        strcpy(mem + 4, cd->fChar);
    }
    DosPostEventSem(hevPut);
    DosWaitEventSem(hevEnd, SEM_INDEFINITE_WAIT);
    DosPostEventSem(hevPut);
    DosReleaseMutexSem(hmtxSyn);
    DosCloseEventSem(hevPut);
/*    DosCloseEventSem(hevGet); */
    DosCloseEventSem(hevEnd);
    DosCloseMutexSem(hmtxSyn);
    if (mem)
        DosFreeMem(mem);
    return 0;
    
}
Ejemplo n.º 30
0
void TThreads::suspend() {
   shutDownFlag=1;
   TID localTID=mouseThreadID;
   if (localTID != 0xFFFF) DosWaitThread(&localTID,DCWW_WAIT);
   //  cerr << " MouseThread has ended\n";
   ULONG count;
   assert(! DosQueryEventSem(TThreads::hevKeyboard2,&count));
   if (!count)
      assert(! DosPostEventSem(TThreads::hevKeyboard2));  // Make sure the thread is running.
   localTID=keyboardThreadID;
   DosWaitThread(&localTID,DCWW_WAIT);
   //  cerr << " KeyboardThread has ended\n";

   assert(!DosCloseMutexSem(hmtxMouse1));
   assert(!DosCloseEventSem(hevKeyboard2));
   assert(!DosCloseEventSem(hevKeyboard1));
   assert(!DosCloseEventSem(hevMouse2));
   assert(!DosCloseEventSem(hevMouse1));
   assert(!DosCloseMuxWaitSem(hmuxMaster));

   if (tiled->mouseHandle != 0xFFFF) MouClose(tiled->mouseHandle);   // This doesn't work, the mouseThread uses the handle.
   assert(! DosFreeMem(tiled));  // Better not, dito
}