Jump to content

DosOpenMutexSem: Difference between revisions

From EDM2
Ak120 (talk | contribs)
Ak120 (talk | contribs)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
=== Syntax ===
DosOpenMutexSem gains access to a shared semaphore for the calling process. When access is granted to the calling process, DosOpenMutexSem increments, by one (1), the usage count for the semaphore pointed to by ''phmtxSemaphore'' or named in ''pszSemaphoreName''.


  rc = DosOpenMutexSem( ''pszSemaphoreName'',  
==Syntax==
                      ''phmtxSemaphore'' );
  DosOpenMutexSem( ''pszSemaphoreName'', ''phmtxSemaphore'' )


==Parameters==
;PSZ ''pszSemaphoreName'' (input):This is a pointer to a null-terminated string containing the name of the semaphore to gain access to. If ''pszSemaphoreName'' equals NULL then the handle contained in ''phmtxSemaphore'' will be used.
;PHMTX ''phmtxSemaphore'' (input/output):This is a pointer to the HMTX containing the handle of the semaphore to be opened. If the semaphore is to be opened by name using ''pszSemaphoreName'' then the input value of ''phmtxSemaphore'' must be NULL or ERROR_INVALID_PARAMETER will be returned. On successful return of this function, ''phmtxSemaphore'' will point to a mutex handle (HMTX) containing the opened semaphore.


=== Parameters ===
PSZ ''pszSemaphoreName'' (input)
This is a pointer to a null-terminated string containing the name of the
semaphore to gain access to.  If ''pszSemaphoreName'' equals NULL then the
handle contained in ''phmtxSemaphore'' will be used.
PHMTX ''phmtxSemaphore'' (input/output)
This is a pointer to the HMTX containing the handle of the semaphore to
be opened. If the semaphore is to be opened by name using ''pszSemaphoreName''
then the input value of ''phmtxSemaphore'' must be NULL or
ERROR_INVALID_PARAMETER will be returned. On successful return of this
function, ''phmtxSemaphore'' will point to a mutex handle (HMTX) containing
the opened semaphore.
=== Returns ===
=== Returns ===
  APIRET rc
;APIRET rc:The following values can be returned:
The following values can be returned
*0 NO_ERROR - Semaphore opened successfully
       
*6 ERROR_INVALID_HANDLE - Error, The value in ''phmtxSemaphore'' does not point to a valid semaphore
{| border="1"
*8 ERROR_NOT_ENOUGH_MEMORY - Error, The system memory limit has been exceeded
|-
*87 ERROR_INVALID_PARAMETER - Error, One or more parameters is not recognized, See parameters above
|0
*105 ERROR_SEM_OWNER_DIED - Error, The process that owns the semaphore has died before releasing it, [[DosQueryMutexSem]] can determine which process died
|NO_ERROR
*123 ERROR_INVALID_NAME - Error, The name pointed to by ''pszSemaphoreName'' has been rejected by the file system
|Semaphore opened successfully
*187 ERROR_SEM_NOT_FOUND - Error, There is no semaphore with the name in ''pszSemaphoreName''
|-
*291 ERROR_TOO_MANY_OPENS - Error, The usage count for the semaphore in question has exceeded the system limit of 65535
|6
|ERROR_INVALID_HANDLE
|Error, The value in ''phmtxSemaphore'' does not point to a valid semaphore
|-
|8
|ERROR_NOT_ENOUGH_MEMORY
|Error, The system memory limit has been exceeded
|-
|87
|ERROR_INVALID_PARAMETER
|Error, One or more parameters is not recognized, See parameters above
|-
|105
|ERROR_SEM_OWNER_DIED
|Error, The process that owns the semaphore has died before releasing it, [[DosQueryMutexSem]] can determine which process died
|-
|123
|ERROR_INVALID_NAME
|Error, The name pointed to by ''pszSemaphoreName'' has been rejected by the file system
|-
|187
|ERROR_SEM_NOT_FOUND
|Error, There is no semaphore with the name in ''pszSemaphoreName''
|-
|291
|ERROR_TOO_MANY_OPENS
|Error, The usage count for the semaphore in question has exceeded the system limit of 65535
|} 
=== Include Info ===
 
#define INCL_DOSSEMAPHORES
#include <os2.h>
 
 
=== Usage Explanation ===
 
DosOpenMutexSem gains access to a shared semaphore for the calling process.
When access is granted to the calling process, DosOpenMutexSem increments, by
one (1), the usage count for the semaphore pointed to by ''phmtxSemaphore''
or named in ''pszSemaphoreName''.
 


=== Relevant Structures ===
==Sample Code==
=== Gotchas ===
=== Sample Code ===
<pre>
<pre>
#define INCL_DOSSEMAPHORES
#define INCL_DOSSEMAPHORES
#include  
#include <os2.h>


UCHAR SemName[15];
UCHAR SemName[15];
Line 103: Line 44:
}
}
</pre>
</pre>
=== See Also ===
[[OS2 API:CPI:DosCloseMutexSem|DosCloseMutexSem]],
[[OS2 API:CPI:DosCreateMutexSem|DosCreateMutexSem]],
[[OS2 API:CPI:DosQueryMutexSem|DosQueryMutexSem]],
[[OS2 API:CPI:DosReleaseMutexSem|DosReleaseMutexSem]],
[[OS2 API:CPI:DosRequestMutexSem|DosRequestMutexSem]]


==See also==
*[[DosCloseMutexSem]]
*[[DosCreateMutexSem]]
*[[DosQueryMutexSem]]
*[[DosReleaseMutexSem]]
*[[DosRequestMutexSem]]


[[Category:The OS/2 API Project]]
[[Category:Dos]]

Latest revision as of 18:31, 29 August 2021

DosOpenMutexSem gains access to a shared semaphore for the calling process. When access is granted to the calling process, DosOpenMutexSem increments, by one (1), the usage count for the semaphore pointed to by phmtxSemaphore or named in pszSemaphoreName.

Syntax

DosOpenMutexSem( pszSemaphoreName, phmtxSemaphore )

Parameters

PSZ pszSemaphoreName (input)
This is a pointer to a null-terminated string containing the name of the semaphore to gain access to. If pszSemaphoreName equals NULL then the handle contained in phmtxSemaphore will be used.
PHMTX phmtxSemaphore (input/output)
This is a pointer to the HMTX containing the handle of the semaphore to be opened. If the semaphore is to be opened by name using pszSemaphoreName then the input value of phmtxSemaphore must be NULL or ERROR_INVALID_PARAMETER will be returned. On successful return of this function, phmtxSemaphore will point to a mutex handle (HMTX) containing the opened semaphore.

Returns

APIRET rc
The following values can be returned:
  • 0 NO_ERROR - Semaphore opened successfully
  • 6 ERROR_INVALID_HANDLE - Error, The value in phmtxSemaphore does not point to a valid semaphore
  • 8 ERROR_NOT_ENOUGH_MEMORY - Error, The system memory limit has been exceeded
  • 87 ERROR_INVALID_PARAMETER - Error, One or more parameters is not recognized, See parameters above
  • 105 ERROR_SEM_OWNER_DIED - Error, The process that owns the semaphore has died before releasing it, DosQueryMutexSem can determine which process died
  • 123 ERROR_INVALID_NAME - Error, The name pointed to by pszSemaphoreName has been rejected by the file system
  • 187 ERROR_SEM_NOT_FOUND - Error, There is no semaphore with the name in pszSemaphoreName
  • 291 ERROR_TOO_MANY_OPENS - Error, The usage count for the semaphore in question has exceeded the system limit of 65535

Sample Code

#define INCL_DOSSEMAPHORES
#include <os2.h>

UCHAR SemName[15];
PHMTX phmtxMySemaphore= NULL; /* pointer to my semaphore handle */

	/* a shared mutex semaphore is successfully created in another process */
	/* its name happens to be \SEM32\MySem */

	strcpy(SemName,"\\SEM32\\MySem");

	rc = DosOpenMutexSem(SemName, phmtxMySemaphore);

	if (rc != 0)
	{
	  /* We got an error to take care of. */
	}
	else
	{
	  /* The semaphore was successfully opened */
	  /* it may be accessed via the handle pointer, phmtxMySemaphore */
	}

See also