コード例 #1
0
static APIRET CreateSem(void)
{
#ifdef __os2_16__
  char SemName[32];
  sprintf(SemName, "\\SEM\\jed\\%u", getpid());
  return ( DosCreateSem (0, &Hmtx, SemName) );
#else
  return ( DosCreateMutexSem (NULL, &Hmtx, 0, 0) );
#endif
}
コード例 #2
0
ファイル: netasync.c プロジェクト: mingpen/OpenNT
/*
* netinitancbs - init async ncbs
*
*       inits semaphores etc in async ncb pool
*
*/
void
netinitancbs(void)
{
  register struct ncb_a *ncbp;  /* pointer to each ncb */
  register int i;               /* temp index */
#ifndef NT
  int rc;                       /* return code */
  union farptr global_seg;      /* pointer to GDT info segment */
  union farptr local_seg;       /* pointer to LDT info segment */
  char NEAR *sem_mask = "\\SEM\\NCB%05x.%03x";
#include "..\h\packon.h"
  struct ldt_info_seg
    {
      int ldti_pid;             /* current process id */
      int ldti_ppid;            /* parrent process id */
      int ldti_priority;        /* priority of current thread */
      int ldti_thread;          /* current thread id */
      int ldti_screengrp;       /* current screengroup */
      int ldti_subscreengrp;    /* current subscreengroup */
      int ldti_forground;       /* current process is in forground */
    };
#include "..\h\packoff.h"
  struct ldt_info_seg FAR *ldt_info_p;

  char sem_name[20];

  lockncbpool();
  if (async_ncbs_inited)
    {
      unlockncbpool();
      return;
    }

  rc = DosGetInfoSeg(
    (PSEL) &global_seg.lp.lp_seg, /* addr to return segment value */
    (PSEL) &local_seg.lp.lp_seg); /* addr to return segment value */
  if (rc)
    {
      fprintf(stderr, "GETINFOSEG failed (%d)\n", rc);
      exit ( rc );
    }
  local_seg.lp.lp_offset = 0;

  ldt_info_p = (struct ldt_info_seg FAR *) local_seg.fp;

  for (ncbp=&asyncncbs[0], i=0; ncbp < &asyncncbs[num_async_ncbs]; ncbp++, i++)
    {
      ncbp->ncb_status = NCB_FREE;     /* starts out free  */
      sprintf(sem_name, sem_mask, ldt_info_p->ldti_pid, i);
#ifdef DEBUG1
      printf("creating semaphore %s\n", sem_name);
#endif

      rc = DosCreateSem(
        (unsigned int) 1,           /* non exclusive ownership of semaphore */
      (PHSYSSEM)     &ncbp->ncb_sem,   /* place to return sem handle */
      (char FAR *) &sem_name[0]);     /* name for semaphore */

      if (rc)
        {
          fprintf(stderr, "CREATESEM \"%s\" failed (%d)\n", sem_name, rc);
          exit ( rc );
        }

      ncbp->ncb_sem_a = ncbp->ncb_sem; /* save away semaphore */
      ncbp->ncb_seqno = 0L;            /* none as yet */

#ifdef DEBUG1
      printf("ncbp is 0x%x, semaphore handle is 0x%lx, saved handle is 0x%lx\n",
        ncbp, ncbp->ncb_sem, ncbp->ncb_sem_a);
#endif
    }
  async_ncbs_inited = 1;
  unlockncbpool();
#else

    //
    // NT Pool Initialization - Create pool locking semaphore
    //

    if (NULL == (async_ncb_pool_sem = CreateSemaphore ( NULL, 1, 1, NULL ) ) )	{
	fprintf(stderr, "Semaphore create failed (%d)\n", GetLastError());
	exit (GetLastError());
    }
    lockncbpool();
    if (async_ncbs_inited)  {
	unlockncbpool();
	return;
    }

    //
    // Create an event for each NCB
    //

    for (ncbp=&asyncncbs[0], i=0; ncbp < &asyncncbs[num_async_ncbs]; ncbp++, i++)  {
	ncbp->ncb_status = NCB_FREE;	/* starts out free  */

	if ( NULL == (ncbp->ncb_event = CreateEvent ( NULL,
			    TRUE,	// manual reset
			    FALSE,	// initially not signalled
			    NULL ) ) )	{
	    fprintf(stderr, "Create NCB event failed (%d)\n", GetLastError ());
	    exit ( GetLastError() );
        }
	ncbp->ncb_sem_a = ncbp->ncb_event; /* save away event handle */
	ncbp->ncb_seqno = 0L;		/* none as yet */
    }
    async_ncbs_inited = 1;
    unlockncbpool();

#endif
}