Example #1
0
void vlc_sem_wait (vlc_sem_t *sem)
{
    ULONG rc;

    do
    {
        vlc_testcancel ();

        DosRequestMutexSem(sem->wait_mutex, SEM_INDEFINITE_WAIT);

        rc = vlc_WaitForSingleObject (sem->hev, SEM_INDEFINITE_WAIT );

        if (!rc)
        {
            DosRequestMutexSem(sem->count_mutex, SEM_INDEFINITE_WAIT);

            sem->count--;
            if (sem->count == 0)
            {
                ULONG ulPost;

                DosResetEventSem(sem->hev, &ulPost);
            }

            DosReleaseMutexSem(sem->count_mutex);
        }

        DosReleaseMutexSem(sem->wait_mutex);
    } while (rc == ERROR_INTERRUPT);
}
Example #2
0
static apr_status_t thread_cond_timedwait(apr_thread_cond_t *cond,
                                          apr_thread_mutex_t *mutex,
                                          ULONG timeout_ms )
{
    ULONG rc;
    apr_status_t rv = APR_SUCCESS;
    int wake = FALSE;
    unsigned long generation;

    DosRequestMutexSem(cond->mutex, SEM_INDEFINITE_WAIT);
    cond->num_waiting++;
    generation = cond->generation;
    DosReleaseMutexSem(cond->mutex);

    apr_thread_mutex_unlock(mutex);

    do {
        rc = DosWaitEventSem(cond->semaphore, timeout_ms);

        DosRequestMutexSem(cond->mutex, SEM_INDEFINITE_WAIT);

        if (cond->num_wake) {
            if (cond->generation != generation) {
                cond->num_wake--;
                cond->num_waiting--;
                rv = APR_SUCCESS;
                break;
            } else {
                wake = TRUE;
            }
        }
        else if (rc != 0) {
            cond->num_waiting--;
            rv = APR_TIMEUP;
            break;
        }

        DosReleaseMutexSem(cond->mutex);

        if (wake) {
            wake = FALSE;
            DosPostEventSem(cond->semaphore);
        }
    } while (1);

    DosReleaseMutexSem(cond->mutex);
    apr_thread_mutex_lock(mutex);
    return rv;
}
Example #3
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;
}
Example #4
0
static void dump_buffer (int i)
{
    static int index = 0;
    void *b;

    b = buffer;

    if (index + i > bsize) {

        do {
            DosRequestMutexSem (mutex, SEM_INDEFINITE_WAIT);
            if (ready != 0) {
                DosReleaseMutexSem(mutex);
                break;
            }

            DosReleaseMutexSem (mutex);
            DosSleep (20);
        } while (TRUE);

        MixBuffers[next].ulBufferLength = index;
        MixSetupParms.pmixWrite (MixSetupParms.ulMixHandle,
                                 &(MixBuffers[next]),1);
        ready--;
        next++;
        index = 0;

        if (next == BUFFERCOUNT) {
            next=0;
        }
    }

    memcpy (&((char*)MixBuffers[next].pBuffer)[index], b, i);
    index += i;
}
Example #5
0
	/* virtual */ void BeginCritical(bool allow_recursive = false)
	{
		/* os2 mutex is recursive by itself */
		DosRequestMutexSem(mutex, (unsigned long) SEM_INDEFINITE_WAIT);
		this->recursive_count++;
		if (!allow_recursive && this->recursive_count != 1) NOT_REACHED();
	}
Example #6
0
void mute(int state)
{
    ULONG rc;

    if ((rc=DosRequestMutexSem(hmtxOC, SEM_INDEFINITE_WAIT)))
    {
        log_warning(dlog, "mute, DosRequestMutexSem rc=%i", rc);
        return;
    }
    if (usDeviceID)
    {
        MCI_SET_PARMS MciSetParms;

        memset(&MciSetParms, 0, sizeof(MCI_SET_PARMS));

        MciSetParms.ulAudio = MCI_SET_AUDIO_ALL;
        rc = mciSendCommand(usDeviceID, MCI_SET, MCI_WAIT|state|MCI_SET_AUDIO,
                            (PVOID) &MciSetParms, 0);

        if (rc != MCIERR_SUCCESS)
            sound_err(dlog, rc, "Setting mute state (MCI_SET_ON/OFF).");
    }
    DosReleaseMutexSem(hmtxOC);

    if (state==MCI_SET_ON)
        set_volume(volume);
}
Example #7
0
/*
** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
** to enter a mutex.  If another thread is already within the mutex,
** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
** SQLITE_BUSY.  The sqlite3_mutex_try() interface returns SQLITE_OK
** upon successful entry.  Mutexes created using SQLITE_MUTEX_RECURSIVE can
** be entered multiple times by the same thread.  In such cases the,
** mutex must be exited an equal number of times before another thread
** can enter.  If the same thread tries to enter any other kind of mutex
** more than once, the behavior is undefined.
*/
static void os2MutexEnter(sqlite3_mutex *p){
  assert( p->id==SQLITE_MUTEX_RECURSIVE || os2MutexNotheld(p) );
  DosRequestMutexSem(p->mutex, SEM_INDEFINITE_WAIT);
#ifdef SQLITE_DEBUG
  if( p->trace ) os2MutexTrace(p, "enter");
#endif
}
static void internal_SetPageFont(HWND hwnd)
{
  char *pchTemp;

  // Set new window fonts!
  if (DosRequestMutexSem(hmtxUseNLSTextArray, SEM_INDEFINITE_WAIT)==NO_ERROR)
  {
    pchTemp = apchNLSText[SSMODULE_NLSTEXT_FONTTOUSE];
    if (pchTemp)
    {
      HWND hwndChild;
      HENUM henum;

      // Oookay, we have the font, set the page and all controls inside it!
      WinSetPresParam(hwnd, PP_FONTNAMESIZE,
		      strlen(pchTemp)+1,
		      pchTemp);

      // Now go through all of its children, and set it there, too!
      henum = WinBeginEnumWindows(hwnd);

      while ((hwndChild = WinGetNextWindow(henum))!=NULLHANDLE)
      {
	WinSetPresParam(hwndChild, PP_FONTNAMESIZE,
			strlen(pchTemp)+1,
			pchTemp);

      }
      WinEndEnumWindows(henum);
    }

    DosReleaseMutexSem(hmtxUseNLSTextArray);
  }
}
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;
}
static void internal_SetPwdProtWindowText(HWND hwnd)
{
  char *pchTemp;

  // Set new window texts!
  if (DosRequestMutexSem(hmtxUseNLSTextArray, SEM_INDEFINITE_WAIT)==NO_ERROR)
  {
    pchTemp = apchNLSText[SSMODULE_NLSTEXT_PWDPROT_ASK_TITLE];
    if (pchTemp)
      WinSetWindowText(hwnd, pchTemp);

    pchTemp = apchNLSText[SSMODULE_NLSTEXT_PWDPROT_ASK_TEXT];
    if (pchTemp)
      WinSetDlgItemText(hwnd, ST_PLEASEENTERTHEPASSWORD, pchTemp);

    pchTemp = apchNLSText[SSMODULE_NLSTEXT_PWDPROT_ASK_OKBUTTON];
    if (pchTemp)
      WinSetDlgItemText(hwnd, PB_OK, pchTemp);

    pchTemp = apchNLSText[SSMODULE_NLSTEXT_PWDPROT_ASK_CANCELBUTTON];
    if (pchTemp)
      WinSetDlgItemText(hwnd, PB_CANCEL, pchTemp);

    DosReleaseMutexSem(hmtxUseNLSTextArray);
  }
}
static void
_cairo_os2_surface_release_source_image (void                  *abstract_surface,
                                         cairo_image_surface_t *image,
                                         void                  *image_extra)
{
    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;
    }

    /* Decrease Lend counter! */
    DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT);

    if (local_os2_surface->pixel_array_lend_count > 0)
        local_os2_surface->pixel_array_lend_count--;
    DosPostEventSem (local_os2_surface->hev_pixel_array_came_back);

    DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields);
    return;
}
/**
 * cairo_os2_surface_set_hwnd:
 * @surface: the cairo surface to associate with the window handle
 * @hwnd_client_window: the window handle of the client window
 *
 * Sets window handle for surface. If Cairo wants to blit into the window
 * because it is set to blit as the surface changes (see
 * cairo_os2_surface_set_manual_window_refresh()), then there are two ways it
 * can choose:
 * If it knows the HWND of the surface, then it invalidates that area, so the
 * application will get a WM_PAINT message and it can call
 * cairo_os2_surface_refresh_window() to redraw that area. Otherwise cairo itself
 * will use the HPS it got at surface creation time, and blit the pixels itself.
 * It's also a solution, but experience shows that if this happens from a non-PM
 * thread, then it can screw up PM internals.
 *
 * So, best solution is to set the HWND for the surface after the surface
 * creation, so every blit will be done from application's message processing
 * loop, which is the safest way to do.
 *
 * Since: 1.4
 **/
void
cairo_os2_surface_set_hwnd (cairo_surface_t *surface,
                            HWND             hwnd_client_window)
{
    cairo_os2_surface_t *local_os2_surface;

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

    if (DosRequestMutexSem (local_os2_surface->hmtx_use_private_fields, SEM_INDEFINITE_WAIT)
        != NO_ERROR)
    {
        /* Could not get mutex! */
        return;
    }

    local_os2_surface->hwnd_client_window = hwnd_client_window;

    DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields);
}
Example #13
0
WaWEPlugin_p GetExportPluginForFormat(WaWEExP_Create_Desc_p pFormatDesc)
{
  WaWEPlugin_p pResult = NULL;
  WaWEPlugin_p temp = NULL;
  int iImportance;

  if (DosRequestMutexSem(PluginListProtector_Sem, SEM_INDEFINITE_WAIT)==NO_ERROR)
  {
    // Go through all plugins, in order of importance,
    // and check them if they can open the file.
    // Return the first one, which reports success!
    for (iImportance = WAWE_PLUGIN_IMPORTANCE_MAX;
         iImportance >= WAWE_PLUGIN_IMPORTANCE_MIN;
         iImportance--)
    {
      temp = PluginListHead;
      while ((temp) && (!pResult))
      {
        if ((temp->iPluginType == WAWE_PLUGIN_TYPE_EXPORT) &&
            (temp->iPluginImportance == iImportance))
        {
          if (temp->TypeSpecificInfo.ExportPluginInfo.fnIsFormatSupported(pFormatDesc))
          {
            // Hey, found a plugin which can write in this format!
            pResult = temp;
          }
        }
        temp = temp->pNext;
      }
      if (pResult) break;
    }
    DosReleaseMutexSem(PluginListProtector_Sem);
  }
  return pResult;
}
RC MCIDRVSave (FUNCTION_PARM_BLOCK *pFuncBlock)
{
  ULONG                ulrc = MCIERR_SUCCESS;    // Propogated Error Code
  ULONG                ulParam1;                 // Message flags
  PMCI_INFO_PARMS      pInfoParms;               // Pointer to info structure
  PMCI_GENERIC_PARMS   pDrvSaveParms;            // Pointer to GENERIC structure
  PINSTANCE            pInstance;                // Pointer to instance

  /*****************************************************/
  /* dereference the values from pFuncBlock            */
  /*****************************************************/
  ulParam1       = pFuncBlock->ulParam1;
  pInstance      = pFuncBlock->pInstance;
  pDrvSaveParms     = (PMCI_GENERIC_PARMS)pFuncBlock->pParam2;

  /*****************************************************/
  /* NOTE ----->>>                                     */
  /*  This is the basic function that should be        */
  /*  performed.  See the other samples in the toolkit */
  /*  for streaming and MMIO considerations            */
  /*****************************************************/
  DosRequestMutexSem (pInstance->hmtxAccessSem, -2);  // wait for semaphore
  pInstance->Active = FALSE;
  DosReleaseMutexSem (pInstance->hmtxAccessSem);      // release semaphore


  return (ulrc);

}      /* end of MCIDRVSave */
Example #15
0
WaWEPluginList_p CreatePluginList(int iPluginType)
{
  WaWEPluginList_p pResult = NULL;
  WaWEPluginList_p pLast = NULL;
  WaWEPluginList_p pNew;
  WaWEPlugin_p temp;

  if (DosRequestMutexSem(PluginListProtector_Sem, SEM_INDEFINITE_WAIT)==NO_ERROR)
  {
    temp = PluginListHead;
    while (temp)
    {
      if (temp->iPluginType == iPluginType)
      {
        pNew = (WaWEPluginList_p) dbg_malloc(sizeof(WaWEPluginList_t));
        if (pNew)
        {
          pNew->pNext = NULL;
          pNew->pPlugin = temp;
          if (!pResult)
          {
            pResult = pNew;
          } else
          {
            pLast->pNext = pNew;
          }
          pLast = pNew;
        }
      }
      temp = temp->pNext;
    }
    DosReleaseMutexSem(PluginListProtector_Sem);
  }
  return pResult;
}
Example #16
0
WaWEPlugin_p GetDefaultEditorPlugin()
{
  WaWEPlugin_p pResult = NULL;
  WaWEPlugin_p pTemp;

  // The default editor plugin is the edit plugin with the
  // greatest iPluginImportance value!

  if (DosRequestMutexSem(PluginListProtector_Sem, SEM_INDEFINITE_WAIT)==NO_ERROR)
  {
    pTemp = PluginListHead;
    while (pTemp)
    {
      if (pTemp->iPluginType == WAWE_PLUGIN_TYPE_EDITOR)
      {
        if (!pResult) pResult = pTemp;
        else
          if (pResult->iPluginImportance < pTemp->iPluginImportance)
            pResult = pTemp;
      }
      pTemp = pTemp->pNext;
    }

    DosReleaseMutexSem(PluginListProtector_Sem);
  }
  return pResult;
}
void omni_condition::wait(void)
{
    _internal_omni_thread_helper me;

    DosRequestMutexSem( crit , SEM_INDEFINITE_WAIT );

    me->cond_next = NULL;
    me->cond_prev = waiting_tail;
    if (waiting_head == NULL)
    waiting_head = me;
    else
    waiting_tail->cond_next = me;
    waiting_tail = me;
    me->cond_waiting = TRUE;

    DosReleaseMutexSem( crit );

    mutex->unlock();

    APIRET result =  DosWaitEventSem(me->cond_semaphore, SEM_INDEFINITE_WAIT);
    ULONG c;
    DosResetEventSem(me->cond_semaphore,&c);

    mutex->lock();

    if (result != 0) throw omni_thread_fatal(result);
}
static cairo_status_t
_cairo_os2_surface_acquire_dest_image (void                     *abstract_surface,
                                       cairo_rectangle_int_t    *interest_rect,
                                       cairo_image_surface_t   **image_out,
                                       cairo_rectangle_int_t    *image_rect,
                                       void                    **image_extra)
{
    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);

    /* Increase lend counter */
    local_os2_surface->pixel_array_lend_count++;

    *image_out = local_os2_surface->image_surface;
    *image_extra = NULL;

    image_rect->x = 0;
    image_rect->y = 0;
    image_rect->width = local_os2_surface->bitmap_info.cx;
    image_rect->height = local_os2_surface->bitmap_info.cy;

    DosReleaseMutexSem (local_os2_surface->hmtx_use_private_fields);

    return CAIRO_STATUS_SUCCESS;
}
Example #19
0
void set_volume(int vol)
{
    ULONG rc;

    if ((rc=DosRequestMutexSem(hmtxOC, SEM_INDEFINITE_WAIT)))
    {
        log_warning(dlog, "set_volume, DosRequestMutexSem rc=%i", rc);
        return;
    }
    if (usDeviceID)
    {
        MCI_SET_PARMS  MciSetParms;

        memset(&MciSetParms, 0, sizeof(MCI_SET_PARMS));

        MciSetParms.ulLevel = vol;
        MciSetParms.ulAudio = MCI_SET_AUDIO_ALL;

        log_message(dlog, "Setting volume to %d%%", vol);

        rc = mciSendCommand(usDeviceID, MCI_SET, MCI_WAIT|
                            MCI_SET_VOLUME|MCI_SET_AUDIO,
                            (PVOID) &MciSetParms, 0);
        if (rc != MCIERR_SUCCESS)
            sound_err(dlog, rc, "Setting up Volume (MCI_SET).");
    }
    volume=vol;
    DosReleaseMutexSem(hmtxOC);
}
Example #20
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;
}
Example #21
0
/* Try to grab a lock on a mutex. */
int
__objc_mutex_trylock(objc_mutex_t mutex)
{
  if (DosRequestMutexSem ((HMTX)(mutex->backend),0L) != 0)
    return -1;
  else
    return 0;
}
Example #22
0
void PM_mainloop(VOID *arg)
{
    SIZEL sizelHps = {0,0};
    HAB   hab;  // Anchor Block to PM
    HMQ   hmq;  // Handle to Msg Queue
    HDC   hdc;  // Handle to Device (Window-Screen)
    QMSG  qmsg; // Msg Queue Event
    video_canvas_t *ptr=(video_canvas_t*)arg;

    hab = WinInitialize(0);            // Initialize PM
    hmq = WinCreateMsgQueue(hab, 0);   // Create Msg Queue

    // 2048 Byte Memory (Used eg for the Anchor Blocks
    WinRegisterClass(hab, szClientClass, PM_winProc, CS_SIZEREDRAW, 2048);

    (*ptr)->hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
                                   WS_ANIMATE, &flFrameFlags,
                                   szClientClass, szTitleBarText, 0L, 0, 0,
                                   &((*ptr)->hwndClient));

    WinSetWindowPos((*ptr)->hwndFrame, HWND_TOP, 0, 0,
                    (*ptr)->width*stretch,
                    (*ptr)->height*stretch+
                    WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR), // +1 with gcc?
                    SWP_SIZE|SWP_SHOW|SWP_ZORDER|SWP_ACTIVATE);    // Make visible, resize, top window
    WinSetWindowPtr((*ptr)->hwndClient, QWL_USER, (VOID*)(*ptr));
    // --------------------
    // maybe ---> WM_CREATE
    // --------------------
    hdc         = WinOpenWindowDC((*ptr)->hwndFrame);
    (*ptr)->hps = GpiCreatePS(WinQueryAnchorBlock((*ptr)->hwndFrame),
                              hdc, &sizelHps,
                              PU_PELS|GPIF_DEFAULT|GPIT_MICRO|GPIA_ASSOC); // GPIT_NORMAL does also work with vac++

    (*ptr)->pbmi = lib_calloc(1, 16+sizeof(RGB2)*256);
    (*ptr)->pbmi->cbFix      = 16; // Size of cbFix, cPlanes, cBitCount = Begin of RGB2
    (*ptr)->pbmi->cPlanes    =  1;
    (*ptr)->pbmi->cBitCount  =  8; // Using 8-bit color mode
    (*ptr)->palette=(RGB2*)((ULONG)(*ptr)->pbmi+(*ptr)->pbmi->cbFix);

    vidlog("pbmiAllocated",0);
    (*ptr)->pbmi_initialized = TRUE;    // All stuff for pbmi created
    //    DosReleaseMutexSem(hmtx); // gfx init end
    //-----------------------
    
    while (WinGetMsg (hab, &qmsg, NULLHANDLE, 0, 0))
        WinDispatchMsg (hab, &qmsg) ;

    //    (*ptr)->pbmi_initialized = FALSE;
    DosRequestMutexSem(hmtx, SEM_INDEFINITE_WAIT);
    GpiDestroyPS((*ptr)->hps);
    WinDestroyWindow ((*ptr)->hwndFrame); // why was this commented out? --> WM_CLOSE ??
    WinDestroyMsgQueue(hmq);  // Destroy Msg Queue
    WinTerminate (hab);       // Release Anchor to PM
    lib_free((*ptr)->pbmi);   // is this the right moment to do this???
    //    lib_free(*ptr); // Vice crashes... why??? This must be done in the main thread!
    exit(0);                  // Kill VICE, All went OK
}
Example #23
0
LONG APIENTRY DARTEvent (ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags)
{
    ULONG rc;
    switch (ulFlags)
    {
    case MIX_WRITE_COMPLETE:
        //
        // start the playback of the next buffer
        //
        rc=MixSetupParms.pmixWrite(MixSetupParms.ulMixHandle,
                                   &(buffers[play]), 1);
        //
        // get the sound mutex
        //
        if (DosRequestMutexSem(hmtxSnd, SEM_INDEFINITE_WAIT))
            return TRUE;
        //
        // empty the buffer which was finished
        //
        memset(buffers[last].pBuffer, 0, BufferParms.ulBufferSize);

        //
        // point to the next playable buffer and remember this buffer
        // as the last one which was played
        //
        last  = play++;
        play %= BufferParms.ulNumBuffers;

        //
        // release mutex
        //
        DosReleaseMutexSem(hmtxSnd);

        if (rc != MCIERR_SUCCESS)
            sound_err(dlog, rc, "Writing to Mixer (pmixWrite, MIX_WRITE_COMPLETE).");
        return TRUE;

    case MIX_STREAM_ERROR | MIX_WRITE_COMPLETE: // 130  /* error occur in device */
        switch (ulStatus)
        {
        case ERROR_DEVICE_UNDERRUN: // 5626
            sound_err(dlog, ulStatus, "Device underrun.");
            play += 2;
            play %= BufferParms.ulNumBuffers;
            break;
        case ERROR_DEVICE_OVERRUN:  // 5627
            sound_err(dlog, ulStatus, "Device overrun.");
            break;
        }
        rc=MixSetupParms.pmixWrite(MixSetupParms.ulMixHandle,
                                   &(buffers[play]), 1);
        if (rc != MCIERR_SUCCESS)
            sound_err(dlog, rc, "Writing to Mixer (pmixWrite, MIX_STREAM_ERROR).");

        return TRUE;
    }
    return TRUE;
}
Example #24
0
/* rc = 0 (NO_ERROR) - Ok
      = 1 - error
      = 2 - DUPLICATE_NAME
*/
int SetupSemaphore(void)
{
    PID     pidOwner = 0;          /* PID of current mutex semaphore owner */
    TID     tidOwner = 0;          /* TID of current mutex semaphore owner */
    ULONG   ulCount  = 0;          /* Request count for the semaphore */
    APIRET  rc       = NO_ERROR;   /* Return code */
    char *pstr;
    pstr = FREEPM_MUTEX_NAME;
    rc = DosCreateMutexSem(FREEPM_MUTEX_NAME,      /* Semaphore name */
                           &FREEPM_hmtx, 0, FALSE);  /* Handle returned */
    if (rc != NO_ERROR)
    {
        if(rc == ERROR_DUPLICATE_NAME)
        {   return 2;
        } else {
            printf("DosCreateMutexSem error: return code = %u\n", rc);
            return 1;
        }
    }
//  if(!detachedMode)
//       printf("DosCreateMutexSem %i \n",__LINE__);
    /* This would normally be done by another unit of work */
    rc = DosOpenMutexSem(FREEPM_MUTEX_NAME,      /* Semaphore name  */
                         &FREEPM_hmtx);          /* Handle returned */
    if (rc != NO_ERROR) {
        printf("DosOpenMutexSem error: return code = %u\n", rc);
        return 1;
    }
//  if(!detachedMode)
//       printf("DosOpenMutexSem %i\n",__LINE__);

    rc = DosRequestMutexSem(FREEPM_hmtx,      /* Handle of semaphore */
                            (ULONG) 1000);  /* Timeout  */
    if (rc != NO_ERROR) {
        printf("DosRequestMutexSem error: return code = %u\n", rc);
        return 1;
    }
//  if(!detachedMode)
//      printf("DosRequestMutexSem %i\n",__LINE__);

    rc = DosQueryMutexSem(FREEPM_hmtx,         /* Handle of semaphore */
                          &pidOwner,    /* Process ID of owner */
                          &tidOwner,    /* Thread ID of owner */
                          &ulCount);    /* Count */
    if (rc != NO_ERROR) {
        printf("DosQueryMutexSem error: return code = %u\n", rc);
        return 1;
    } else if (!_FreePM_detachedMode)  {
        printf("Semaphore owned by PID %u, TID %u.", pidOwner, tidOwner);
        printf("  Request count is %u.\n", ulCount);
    } /* endif */

//  if(!detachedMode)
//       printf("DosQueryMutexSem %i\n",__LINE__);

    return NO_ERROR;
}
Example #25
0
int que_n (void)
{
    int result;

    DosRequestMutexSem (mtx_Queue, SEM_INDEFINITE_WAIT);
    result = nq;
    DosReleaseMutexSem (mtx_Queue);
    return result;
}
Example #26
0
static int dart_write2(SWORD *pbuf, size_t nr)
{
    APIRET rc;
    int nrtowrite;

    written += nr;
    nr *= sizeof(SWORD);

    while (nr)
    {
        //
        // check if the buffer can be filled completely
        //
        nrtowrite = nr>rest ? rest : nr;

        if ((rc=DosRequestMutexSem(hmtxSnd, SEM_INDEFINITE_WAIT)))
        {
            log_warning(dlog, "dart_write2, DosRequestMutexSem rc=%i", rc);
            return 1;
        }

        //
        // if the buffer we want to write to is the next one which is
        // played, skip one buffer and write to the overnext
        //

        if (play==(pos+1)%BufferParms.ulNumBuffers)
        {
            pos      = (++pos)%BufferParms.ulNumBuffers;
            written += BufferParms.ulBufferSize/sizeof(SWORD);
        }

        //
        // fill the pos-th buffer
        //
        memcpy((void*)((ULONG)buffers[pos].pBuffer+(BufferParms.ulBufferSize-rest)),
               pbuf, nrtowrite);

        rest -= nrtowrite;

        //
        // check if the buffer was filled completely
        //
        if (!rest)
        {
            pos++;
            pos %= BufferParms.ulNumBuffers;
            rest = BufferParms.ulBufferSize;
        }

        DosReleaseMutexSem(hmtxSnd);

        nr -= nrtowrite;
    }
    return 0;
}
Example #27
0
static int os2MutexTry(sqlite3_mutex *p){
  int rc = SQLITE_BUSY;
  assert( p->id==SQLITE_MUTEX_RECURSIVE || os2MutexNotheld(p) );
  if( DosRequestMutexSem(p->mutex, SEM_IMMEDIATE_RETURN) == NO_ERROR ) {
    rc = SQLITE_OK;
#ifdef SQLITE_DEBUG
    if( p->trace ) os2MutexTrace(p, "try");
#endif
  }
  return rc;
}
Example #28
0
int DLLCALL pthread_mutex_lock(pthread_mutex_t* mutex)
{
#if defined(PTHREAD_MUTEX_AS_WIN32_MUTEX)
	return (WaitForSingleObject(*mutex, INFINITE)==WAIT_OBJECT_0 ? 0 : EBUSY);
#elif defined(_WIN32)	/* Win32 Critical Section */
	EnterCriticalSection(mutex);
	return 0;	/* No error */
#elif defined(__OS2__)
	return DosRequestMutexSem(*mutex, -1 /* SEM_INDEFINITE_WAIT */);
#endif
}
Example #29
0
/*
** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
** to enter a mutex.  If another thread is already within the mutex,
** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
** SQLITE_BUSY.  The sqlite3_mutex_try() interface returns SQLITE_OK
** upon successful entry.  Mutexes created using SQLITE_MUTEX_RECURSIVE can
** be entered multiple times by the same thread.  In such cases the,
** mutex must be exited an equal number of times before another thread
** can enter.  If the same thread tries to enter any other kind of mutex
** more than once, the behavior is undefined.
*/
static void os2MutexEnter(sqlite3_mutex *p){
  TID tid;
  PID holder1;
  ULONG holder2;
  if( p==0 ) return;
  assert( p->id==SQLITE_MUTEX_RECURSIVE || os2MutexNotheld(p) );
  DosRequestMutexSem(p->mutex, SEM_INDEFINITE_WAIT);
  DosQueryMutexSem(p->mutex, &holder1, &tid, &holder2);
  p->owner = tid;
  p->nRef++;
}
Example #30
0
int DLLCALL pthread_mutex_trylock(pthread_mutex_t* mutex)
{
#if defined(PTHREAD_MUTEX_AS_WIN32_MUTEX)
	return (WaitForSingleObject(*mutex, 0)==WAIT_OBJECT_0 ? 0 : EBUSY);
#elif defined(_WIN32)	/* Win32 Critical Section */
	/* TryEnterCriticalSection only available on NT4+ :-( */
	return (TryEnterCriticalSection(mutex) ? 0 : EBUSY);
#elif defined(__OS2__)
	return DosRequestMutexSem(*mutex, 0 /* SEM_IMMEDIATE_RETURN */);
#endif
}