TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALL
from: DARIN MCBRIDE
date: 1997-08-31 09:50:00
subject: safequeue [3/6]

>>>>>>>>>> CSplit: Version 2.2 >>>>>>>>>>
>>>>>>>>>> CSplit: Begin part 3/6 >>>>>>>>>>
    mutable MutexSem m_msContainer;
};
#endif // MCBRIDE_SAFEQUEUE_H
>>>>>>>>>> CSplit: End file safequeue.h >>>>>>>>>>
>>>>>>>>>> CSplit: Begin file sem32.cc >>>>>>>>>>
/*
 * Code for implementing a semaphore.
 */
#include "sem32.h"
#define CSEM_PUBLIC 1
MutexSem::MutexSem() : m_hmtxProtFile(0)
{
}
MutexSem::~MutexSem()
{
    if (*this)
        Close();
}
Error MutexSem::Create()
{
    // create an anonymous semaphore
    APIRET ulrcCreateSem = DosCreateMutexSem(
                                             NULL,
                                             &m_hmtxProtFile,
                                             0L, // not shared
                                             false
                                            );
    // it cannot already be created...
    assert(ERROR_DUPLICATE_NAME != ulrcCreateSem);
    return ulrcCreateSem;
}
Error MutexSem::Create(const String& strSemName)
{
    assert(strSemName.length() > 0);
    if (strSemName.length() == 0)
        return false;
    {
        const String strSemPrefix = \
\
strupr(CStringOf(String(strSemName,0,7)));
        assert(strSemPrefix == "\\SEM32\\");
        if (strSemPrefix != "\\SEM32\\")
            return false;
    }
    // First try by creating the semaphore new
    APIRET ulrcCreateSem = DosCreateMutexSem(
                                             CStringOf(strSemName),
                                             &m_hmtxProtFile,
                                             DC_SEM_SHARED,
                                             false
                                            );
    // check if it's already created:
    if (ulrcCreateSem == ERROR_DUPLICATE_NAME) {
        APIRET ulrcOpenSem = DosOpenMutexSem(
                                             CStringOf(strSemName),
                                             &m_hmtxProtFile
                                            );
        if (ulrcOpenSem != NO_ERROR)
        {
            return ulrcOpenSem;
        }
    }
    else if (ulrcCreateSem != NO_ERROR)
    {
        // otherwise, it's an unknown error:
        return ulrcCreateSem;
    }
    return NO_ERROR; // save the success (so far)
}
Error MutexSem::Claim(unsigned long ulTimeOut)
{
    return DosRequestMutexSem(m_hmtxProtFile, ulTimeOut);
>>>>>>>>>> CSplit: End part 3/6 crc: f31e >>>>>>>>>>
--- FastEcho 1.46
---------------
* Origin: House of Fire BBS - Toronto - (416)601-0085 - v.34 (1:250/536)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.