| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Semaphores (16 & 32) |
Hello Darin!
Tuesday May 28 1996 22:12, Darin McBride wrote to Doug Nazar:
DM> Yup - but when I link with OS2286.LIB, the program can't even load. :-/
Only link with OS2286.LIB for 16-bit programs. The 16 bit functions are
still in OS2386.LIB but renamed. (ie. DosCreateSem -> Dos16CreateSem).
DM> APIENTRY16, actually. But I finally got the calling stuff set up, but...
DM> it still refuses to run. :-/
Here. I whipped up a quick demo program. It compiles (and runs!) with both
IBM VA & Watcom.
-- CUT -------- Begin test2.cpp -------- CUT --
#include
#define INCL_DOS
#include
extern "C" { /*fold00*/
#define DosSemClear DOS16SEMCLEAR
#define DosSemRequest DOS16SEMREQUEST
#define DosCreateSem DOS16CREATESEM
#define DosOpenSem DOS16OPENSEM
#define DosCloseSem DOS16CLOSESEM
typedef PVOID * _Seg16 HSEM16;
typedef HSEM * PHSEM16;
#define CSEM_PRIVATE 0
#define CSEM_PUBLIC 1
APIRET16 APIENTRY16 DosSemClear(HSEM16 hsem);
APIRET16 APIENTRY16 DosSemRequest(HSEM16 hsem,
LONG lTimeOut);
APIRET16 APIENTRY16 DosCreateSem(USHORT fExclusive,
PHSEM16 phsem,
PSZ pszSemName);
APIRET16 APIENTRY16 DosOpenSem(PHSEM16 phsem,
PSZ pszSemName);
APIRET16 APIENTRY16 DosCloseSem(HSEM16 hsem);
}
class OS2MSG { /*fold00*/
ULONG errorNumber;
char msgBuf[2048];
ULONG msgLen;
public:
OS2MSG(ULONG e, const char * msgFile = "OSO001.MSG") : errorNumber(e) {
if (errorNumber) {
APIRET rc = 0;
rc = DosGetMessage(0, 0, msgBuf, 2048, errorNumber,
"OSO001.MSG", &msgLen);
if (rc) {
msgLen = 0;
*msgBuf = '\0';
}
else
msgBuf[msgLen] = '\0';
}
}
friend ostream& operator<< (ostream& os, const OS2MSG& os2Msg);
};
ostream& operator<< (ostream& os, const OS2MSG& os2Msg) {
if (os2Msg.errorNumber) {
os << os2Msg.msgBuf;
}
return os;
}
int main() { /*FOLD00*/
cout << "Top" << endl;
HSEM16 semHandle = 0;
APIRET16 rc = 0;
rc = DosOpenSem((PHSEM16)&semHandle, "\\Sem\\Squish\\Default");
if (rc & rc != 187) {
cerr << "DosOpenSem:" << endl << "
" << OS2MSG(rc) << endl;
return 1;
}
else if (rc==187) {
rc = DosCreateSem(CSEM_PUBLIC, (PHSEM16)&semHandle,
"\\Sem\\Squish\\Default");
if (rc) {
cerr << "DosCreateSem:" << endl <<
" " << OS2MSG(rc) << endl;
return 1;
}
}
rc = DosSemRequest(semHandle, SEM_INDEFINITE_WAIT);
if (rc) {
cerr << "DosSemRequest:" << endl <<
" " << OS2MSG(rc) << endl;
return 1;
}
cout << "Middle" << endl;
DosSleep(15000);
rc = DosSemClear(semHandle);
if (rc) {
cerr << "DosSemClear:" << endl << "
" << OS2MSG(rc) << endl;
return 1;
}
rc = DosCloseSem(semHandle);
if (rc) {
cerr << "DosCloseSem:" << endl << "
" << OS2MSG(rc) << endl;
return 1;
}
cout << "Bottom" << endl;
return 0;
} -- CUT --------- End test2.cpp --------- CUT --
DM> 'dontKnow' is a string delemitating the name of an environment variable
DM> that is permitted to override semaphoreName.
Well that helps :-) Actually, all this discussion brought to light that
override which helps here. I'm running two squish setups, one for the hub
& one for the bbs. The hub tosses to the bbs address & then I move
things over with a set of utils. This will allow me to run concurrently.
DM> I actually used this so much in my code that I have a seperate function
DM> that creates a 'String' object out of the msgBuf and returns it. It then
DM> allows a cerr << GetOSOErr(ulErrorNumber) << endl;.
DM> However, your class looks a little more useful. :-)
Actually, thinking about it, the 'proper' way to handle it would be a base
class where the constructer takes a msg filename and then derive an
OSOErrMsg class from that.
DM> What OS/2 editor do you use that has folding?
FTE. It's a great little editor. The only real complaint I had was it's
slow initialization because there where dozens of text config files but
version .38 uses a compiled config. Also has a PM version which is just an
AVIO (I believe).
The URL is http://ixtas.fri.uni-lj.si/~markom/fte
Doug
--- GoldED/2 2.50+
* Origin: Realm of the Dragons - `Where thy mind hath no limits' (1:250/516)SEEN-BY: 50/99 270/101 620/243 711/401 409 410 413 430 808 809 934 955 SEEN-BY: 712/407 515 517 628 713/888 800/1 @PATH: 250/516 101 99 3615/50 396/1 270/101 712/515 711/808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
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™.