Changeset 6550 for trunk/src


Ignore:
Timestamp:
Aug 16, 2001, 8:13:24 PM (24 years ago)
Author:
sandervl
Message:

CT: capi update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/capi2032/capi2032.cpp

    r4507 r6550  
    1 /* $Id: capi2032.cpp,v 1.5 2000-10-21 09:24:03 sandervl Exp $ */
     1/* $Id: capi2032.cpp,v 1.6 2001-08-16 18:13:24 sandervl Exp $ */
    22
    33/*
     
    5353                             maxBDataBlocks, maxBDataLen, pApplID );
    5454
    55    SetFS(sel);
    5655   if( dwResult )
    5756   {
    5857      dprintf((" failed (%X)!\n", dwResult ));
     58      SetFS(sel);
    5959      return(0x1108);
    6060   }
    6161   dprintf((" successfull (ApplID: %d)\n", *pApplID ));
    6262
    63     // create named semaphore if neccessary
    64    if( !hEvent )
    65    {
    66       // create named semaphore with Application ID as last character sequenz
    67       sprintf( szSemName, "\\SEM32\\CAPI2032\\SEM%d" , *pApplID );
    68       rc = DosCreateEventSem( szSemName, &hEvent, DC_SEM_SHARED, FALSE );
    69       if( rc )
    70       {
    71          dprintf((" failed (DosCreateEventSem): %d!\n",rc));
    72          return 0x1108; // OS ressource error (error class 0x11..)
    73       }
    74       dprintf((" ok (DosCreateEventSem): hEvent:%d %s!\n", hEvent, szSemName));
    75 
    76       dwResult = CAPI_SET_SIGNAL( *pApplID, hEvent );
    77       if( dwResult )
    78       {
    79          dprintf((" failed (CAPI_SET_SIGNAL: %X)!\n", dwResult));
    80          return 0x1108; // OS ressource error (error class 0x11..)
    81       }
    82    }
     63   // create named semaphore with Application ID as last character sequenz
     64   rc = DosCreateEventSem( szSemName, &hEvent, DC_SEM_SHARED, FALSE );
     65   if( rc )
     66   {
     67      dprintf((" failed (DosCreateEventSem): %d!\n",rc));
     68      SetFS(sel);
     69      return 0x1108; // OS ressource error (error class 0x11..)
     70   }
     71   dprintf((" ok (DosCreateEventSem): hEvent:%d %s!\n", hEvent, szSemName));
     72
     73   dwResult = CAPI_SET_SIGNAL( *pApplID, hEvent );
     74   if( dwResult )
     75   {
     76      dprintf((" failed (CAPI_SET_SIGNAL: %X)!\n", dwResult));
     77      SetFS(sel);
     78      return 0x1108; // OS ressource error (error class 0x11..)
     79   }
     80
     81   SetFS(sel);
    8382   return dwResult;
    8483}
     
    9796   dprintf(("CAPI2032: CAPI_RELEASE (ApplID: %d)\n", ApplID));
    9897
    99    // open semaphore
     98   // open semaphore ( get the event Handle )
    10099   sprintf( szSemName, "\\SEM32\\CAPI2032\\SEM%d" , ApplID );
     100
     101   // enter critical section, so no other thread can access the sem
     102   DosEnterCritSec();
     103   // open semaphore to get the event handle
    101104   rc = DosOpenEventSem( szSemName, &hEvent );
    102105   if(rc)
     
    104107      dprintf((" failed (DosOpenEventSem) rc: %d!\n",rc));
    105108   }
     109   // close semaphore, this will decrement the open count
     110   DosCloseEventSem( hEvent );
     111
    106112   // cleanup
    107113   if( hEvent )
    108114   {
    109115      dprintf(("(DosCloseEventSem) hEvent:%d %s!\n",hEvent, szSemName));
     116      // final cleanup semaphore.
    110117      rc = DosCloseEventSem( hEvent );
    111       hEvent = NULLHANDLE;
    112118      if(rc)
    113119      {
    114120         dprintf((" failed (DosCloseEventSem) rc: %d!\n",rc));
    115121      }
    116    }
     122
     123   }
     124   DosExitCritSec();
     125
    117126   dwResult = CAPI_RELEASE( ApplID );
    118127
     
    171180   dprintf(("CAPI2032: CAPI_WAIT_FOR_SIGNAL (ApplID: %d)", ApplID));
    172181
    173    // open semaphore
    174182   sprintf( szSemName, "\\SEM32\\CAPI2032\\SEM%d" , ApplID );
     183
     184   // enter critical section, so no other thread can access the sem
     185   DosEnterCritSec();
     186   // open semaphore to get the event handle
    175187   rc = DosOpenEventSem( szSemName, &hEvent );
    176188   if(rc)
    177189   {
     190      DosExitCritSec();
    178191      dprintf((" failed (DosOpenEventSem) rc: %d!\n",rc));
    179192      return 0x1101;
    180193   }
     194   // close semaphore
     195   DosCloseEventSem( hEvent );
     196   DosExitCritSec();
    181197
    182198   // wait for event
Note: See TracChangeset for help on using the changeset viewer.