Ignore:
Timestamp:
Jul 12, 1999, 7:20:04 PM (26 years ago)
Author:
phaller
Message:

Fix: console input queue fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/console.cpp

    r278 r296  
    1 /* $Id: console.cpp,v 1.8 1999-07-06 15:48:45 phaller Exp $ */
     1/* $Id: console.cpp,v 1.9 1999-07-12 17:20:03 phaller Exp $ */
    22
    33/*
     
    184184
    185185/*****************************************************************************
     186 * Name      : iConsoleInputQueueLock
     187 * Purpose   : lock the input queue to ensure correct event sequence
     188 * Parameters:
     189 * Variables :
     190 * Result    :
     191 * Remark    :
     192 * Status    :
     193 *
     194 * Author    : Patrick Haller [Tue, 1998/02/10 01:55]
     195 *****************************************************************************/
     196
     197void static iConsoleInputQueueLock()
     198{
     199  DosRequestMutexSem(ConsoleInput.hmtxInputQueue,
     200                     SEM_INDEFINITE_WAIT);
     201}
     202
     203
     204/*****************************************************************************
     205 * Name      : iConsoleInputQueueUnlock
     206 * Purpose   : unlock the input queue
     207 * Parameters:
     208 * Variables :
     209 * Result    :
     210 * Remark    :
     211 * Status    :
     212 *
     213 * Author    : Patrick Haller [Tue, 1998/02/10 01:55]
     214 *****************************************************************************/
     215
     216void static iConsoleInputQueueUnlock()
     217{
     218  DosReleaseMutexSem(ConsoleInput.hmtxInputQueue);
     219}
     220
     221
     222/*****************************************************************************
    186223 * Name      :
    187224 * Purpose   :
     
    225262  }
    226263
     264
     265  rc = DosCreateMutexSem(NULL,
     266                         &ConsoleInput.hmtxInputQueue,
     267                         0L,
     268                         FALSE);
     269  if (rc != NO_ERROR)                                       /* other error ? */
     270  {
     271    DosCloseEventSem(ConsoleGlobals.hevConsole);    /* close other semaphore */
     272    DosCloseEventSem(ConsoleInput.hevInputQueue);   /* close other semaphore */
     273    return (rc);                                    /* raise error condition */
     274  }
    227275
    228276  /***************************************************************************
     
    332380  ConsoleGlobals.Options.coordDefaultPosition.Y  = 0;
    333381  ConsoleGlobals.Options.coordDefaultSize.X      = 80;
    334   ConsoleGlobals.Options.coordDefaultSize.Y      = 35;
     382  ConsoleGlobals.Options.coordDefaultSize.Y      = 25;
    335383  ConsoleGlobals.coordWindowSize.X               = ConsoleGlobals.Options.coordDefaultSize.X;
    336384  ConsoleGlobals.coordWindowSize.Y               = ConsoleGlobals.Options.coordDefaultSize.Y;
     
    496544{
    497545  APIRET rc;
     546
     547  DosCloseEventSem(ConsoleGlobals.hevConsole);      /* close other semaphore */
     548  DosCloseEventSem(ConsoleInput.hevInputQueue);     /* close other semaphore */
     549  DosCloseMutexSem(ConsoleInput.hmtxInputQueue);          /* close semaphore */
     550
    498551
    499552  WinPostMsg (ConsoleGlobals.hwndFrame,         /* force thread to terminate */
     
    13081361           pInputRecord));
    13091362#endif
     1363
     1364  iConsoleInputQueueLock();
    13101365                                                           /* get free event */
    13111366  pirFree = &ConsoleInput.arrInputRecord[ConsoleInput.ulIndexFree];
    13121367  if (pirFree->EventType != 0x0000)
     1368  {
     1369    iConsoleInputQueueUnlock();
    13131370    return (ERROR_QUE_NO_MEMORY);                         /* queue is full ! */
    1314 
     1371  }
    13151372                                                       /* put event in queue */
     1373
     1374  ConsoleInput.ulIndexFree++;                        /* update index counter */
     1375  if (ConsoleInput.ulIndexFree >= CONSOLE_INPUTQUEUESIZE)
     1376    ConsoleInput.ulIndexFree = 0;
     1377
     1378  ConsoleInput.ulEvents++;                   /* increate queue event counter */
     1379
     1380  iConsoleInputQueueUnlock();
     1381
    13161382  memcpy(pirFree,                                               /* copy data */
    13171383         pInputRecord,
    13181384         sizeof (INPUT_RECORD) );
    1319 
    1320   ConsoleInput.ulIndexFree++;                        /* update index counter */
    1321   if (ConsoleInput.ulIndexFree >= CONSOLE_INPUTQUEUESIZE)
    1322     ConsoleInput.ulIndexFree = 0;
    1323 
    1324   ConsoleInput.ulEvents++;                   /* increate queue event counter */
    1325 
    13261385                                                  /* unblock reading threads */
    13271386  rc = DosPostEventSem(ConsoleInput.hevInputQueue);
     
    13551414    return (ERROR_QUE_EMPTY);                            /* queue is empty ! */
    13561415
     1416  iConsoleInputQueueLock();
    13571417                                                          /* get first event */
    13581418  pirEvent = &ConsoleInput.arrInputRecord[ConsoleInput.ulIndexEvent];
    13591419  if (pirEvent->EventType == 0x0000)
     1420  {
     1421    iConsoleInputQueueUnlock();
    13601422    return (ERROR_QUE_EMPTY);                            /* queue is empty ! */
     1423  }
     1424
     1425  if (ConsoleInput.ulEvents >= 0)       /* decrease number of console events */
     1426    ConsoleInput.ulEvents--;
     1427
     1428  ConsoleInput.ulIndexEvent++;                       /* update index counter */
     1429  if (ConsoleInput.ulIndexEvent >= CONSOLE_INPUTQUEUESIZE)
     1430    ConsoleInput.ulIndexEvent = 0;
    13611431
    13621432                                                       /* put event in queue */
     
    13671437  pirEvent->EventType = 0x0000;                 /* mark event as read = free */
    13681438
    1369   if (ConsoleInput.ulEvents >= 0)       /* decrease number of console events */
    1370     ConsoleInput.ulEvents--;
    1371 
    1372   ConsoleInput.ulIndexEvent++;                       /* update index counter */
    1373   if (ConsoleInput.ulIndexEvent >= CONSOLE_INPUTQUEUESIZE)
    1374     ConsoleInput.ulIndexEvent = 0;
     1439  iConsoleInputQueueUnlock();
    13751440
    13761441  return (NO_ERROR);                                                   /* OK */
Note: See TracChangeset for help on using the changeset viewer.