コード例 #1
0
ファイル: dvinit.c プロジェクト: OS2World/DRV-PPtP
int ptc_init(RP rp)
{
	int i;
	TTY tp;
	char far *ptr = buf1;

	if (init_once(rp) == 2)
	  return RP_EGEN;
	
	constty = 0;
	
	for (i=0; i<NPTY; i++)
	{
		ptr = i<16 ? buf1 : buf2;
		tp = (TTY) (ptr + ( (i%16) * sizeof(struct tty) ));
		ttys[i]   = tp;
		tp->state = 0;
		tp->send  = tp->ucntl = 0;
		qinit(&tp->inq);
		qinit(&tp->outq);
		tp->dev = i;
		tp->pgrp = tp->pid = 0;
		tp->ccnt = tp->scnt = 0;
		tp->ocol = 0;
		rpqinit(&tp->crq);
		rpqinit(&tp->cwq);
		rpqinit(&tp->srq);
		rpqinit(&tp->swq);
		tp->crsel = tp->srsel = tp->cxsel = 0;
	}
#ifdef INTRO
	DosPutMessage(1,sizeof(pty_msg)-1,pty_msg);
#endif
	return RPDONE;
}
コード例 #2
0
ファイル: winsnd2.c プロジェクト: nightfly19/renyang-learn
static void winsnd_init(MSFilter *f){
	WinSnd *d=(WinSnd *)ms_new0(WinSnd,1);
	d->wfx.wFormatTag = WAVE_FORMAT_PCM;
	d->wfx.cbSize = 0;
	d->wfx.nAvgBytesPerSec = 16000;
	d->wfx.nBlockAlign = 2;
	d->wfx.nChannels = 1;
	d->wfx.nSamplesPerSec = 8000;
	d->wfx.wBitsPerSample = 16;
	qinit(&d->rq);
	qinit(&d->write_rq);
#ifndef DISABLE_SPEEX
	d->pst=NULL;
	d->pst_frame_size=0;
#endif
	d->ready=0;
	d->workaround=0;
	ms_mutex_init(&d->mutex,NULL);
	f->data=d;

	d->stat_input=0;
	d->stat_output=0;
	d->stat_notplayed=0;
	d->stat_minimumbuffer=WINSND_MINIMUMBUFFER;
}
コード例 #3
0
ファイル: netsim.c プロジェクト: VTCSecureLLC/ortp
static OrtpNetworkSimulatorCtx* simulator_ctx_new(void){
	OrtpNetworkSimulatorCtx *ctx=(OrtpNetworkSimulatorCtx*)ortp_malloc0(sizeof(OrtpNetworkSimulatorCtx));
	qinit(&ctx->latency_q);
	qinit(&ctx->q);
	qinit(&ctx->send_q);
	ortp_mutex_init(&ctx->mutex,NULL);
	return ctx;
}
コード例 #4
0
ファイル: madns.c プロジェクト: mischasan/madns
MADNS  *
madns_create(char const *resolv_conf, int query_time, int server_reqs)
{
    int     i, rcvbufsiz = 128 * 1024;
    MADNS  *mp = calloc(1, sizeof(MADNS));
    char    line[512];

    start = tick();
    mp->sock = -1;              // for destroy, called inside "create".
    mp->query_time = OPT(query_time, MADNS_QUERY_TIME);
    mp->limit = MIN_CACHE;

    FILE   *fp = fopen(OPT(resolv_conf, MADNS_RESOLV_CONF), "r");

    if (fp && (mp->serv = malloc(sizeof *mp->serv * fseek(fp, 0L, 2)))) {
        for (rewind(fp); fgets(line, sizeof line, fp);)
            if (1 == sscanf(line, "nameserver %s", line)) {
                mp->serv[mp->nservs].ip = inet_addr(line);
                if (mp->serv[mp->nservs].ip != INADDR_NONE)
                    mp->serv[mp->nservs++].nreqs = 0;
            }
        fclose(fp);
    }

    if (!mp->nservs)
        return madns_destroy(mp), NULL;

    mp->server_reqs = MIN(OPT(server_reqs, MADNS_SERVER_REQS),
                          MAX_TIDS / mp->nservs);
    mp->qsize = mp->nfree = mp->nservs * mp->server_reqs;
    if (mp->qsize > MAX_TIDS || mp->qsize < 2)
        return madns_destroy(mp), NULL;

    mp->serv = realloc(mp->serv, sizeof(SERVER) * mp->nservs);
    mp->cachev = calloc(mp->limit, sizeof(CACHE_INFO *));
    mp->queries = malloc(mp->qsize * sizeof(*mp->queries));

    qinit(&mp->active);
    qinit(&mp->unused);
    for (i = 0; i < mp->qsize; ++i)
        qpush(&mp->unused, &mp->queries[i].link);

    mp->sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if (mp->sock == -1)
        return madns_destroy(mp), NULL;

    fcntl(mp->sock, F_SETFD, FD_CLOEXEC);
    fcntl(mp->sock, F_SETFL, O_NONBLOCK | fcntl(mp->sock, F_GETFL, 0));
    setsockopt(mp->sock, SOL_SOCKET, SO_RCVBUF,
               (char *)&rcvbufsiz, sizeof rcvbufsiz);
    return mp;
}
コード例 #5
0
ファイル: gethost2.c プロジェクト: Azarien/open-watcom-v2
int resolve_ip (DWORD ip, char *result)
{
  question_t q;
  WORD       oldhndlcbrk;
  int        i;

  if (dns_timeout == 0)
      dns_timeout = sock_delay << 2;

  resolve_timeout = set_timeout (100 * dns_timeout);
  oldhndlcbrk   = wathndlcbrk;
  wathndlcbrk   = 1;        /* enable special interrupt mode */
  watcbroke     = 0;
  *result       = 0;
  _resolve_exit = 0;

  qinit (&q,ip);

  for (i = 0; i < last_nameserver; ++i)
  {
    if (!reverse_lookup(&q,result,def_nameservers[i]));
       break;
  }
  watcbroke   = 0;          /* always clean up */
  wathndlcbrk = oldhndlcbrk;
  return (*result != 0);
}
コード例 #6
0
ファイル: a2.c プロジェクト: JianchengZh/RingQueue
int
main(void)
{
    struct queue *q = qinit();
    int i;
    pthread_t kids[POP_CNT + PUSH_CNT];

    setaffinity(0);

    msgs = calloc(MSG_CNT, sizeof(struct msg));
    for (i = 0; i < POP_CNT; i++)
        start_thread(i, pop_task, q, &kids[i]);
    for (; i < POP_CNT + PUSH_CNT; i++)
        start_thread(i, push_task, q, &kids[i]);
    for (i = 0; i < POP_CNT + PUSH_CNT; i++)
        pthread_join(kids[i], NULL);

    quit = 0;

    if (pop_total < MSG_CNT) {
        printf("flushing: %d\n", MSG_CNT - pop_total);
        for (i = 0; i < POP_CNT; i++)
            start_thread(i, pop_flush_task, q, &kids[i]);
        for (i = 0; i < POP_CNT; i++)
            pthread_join(kids[i], NULL);
    }

    printf("pop total: %d\n", pop_total);
    printf("pop cycles/msg: %lu\n", pop_cycles / pop_total);
    printf("push cycles/msg: %lu\n", push_cycles / MSG_CNT);

    return 0;
}
コード例 #7
0
ファイル: mutex.c プロジェクト: MaxRzv/VP2motion-2
//----------------------------------------------------------------------------------------------------//
//  @func - sys_pthread_mutex_init
//! @desc
//!   Initialize a pthread mutex
//!   - Allocate a pthread mutex structure.
//!   - Initialize the pthread mutex structure
//! @param
//!   - mutex is the location to store mutex identifier in
//!   - attr is the mutex creation attributes. Unused currently.
//! @return
//!   - Returns 0 on success and mutex identifier in *mutex.
//!   - Returns EAGAIN if no more mutex structures can be allocated.
//!   - Returns EINVAL if attr is invalid
//! @note
//!   - None
//----------------------------------------------------------------------------------------------------//
int sys_pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
{
    int i;

    if (mutex == NULL) 
	return -1;
    
    if (attr == NULL)
        attr = &default_mutex_attr;

    if (attr->type != PTHREAD_MUTEX_DEFAULT && attr->type != PTHREAD_MUTEX_RECURSIVE) {
        kerrno = EINVAL;
        return -1;
    }

    for (i=0; i < MAX_PTHREAD_MUTEX; i++) {
	if (pthread_mutex_heap[i].is_allocated == 0) 
	    break;
    }
    
    if (i == MAX_PTHREAD_MUTEX)
	return EAGAIN;

    *mutex = (pthread_mutex_t)i;
    pthread_mutex_heap[i].is_allocated = 1;
    pthread_mutex_heap[i].locked = 0;    // Unlocked
    pthread_mutex_heap[i].owner = -1;
    pthread_mutex_heap[i].attr.type = attr->type;

    qinit (&(pthread_mutex_heap[i].mutex_wait_q));
    return 0;
}
コード例 #8
0
static void au_init(MSSndCard *card){
	ms_debug("au_init");
	AUData *d=ms_new(AUData,1);
	//OSStatus auresult;
	d->bits=16;
	d->rate=PREFERRED_HW_SAMPLE_RATE;
	d->nchannels=1;
	
	d->read_started=FALSE;
	d->write_started=FALSE;
	d->bufferizer=ms_bufferizer_new();
	d->n_lost_frame=0;
	d->started=FALSE;
	d->io_unit_must_be_started=FALSE;
	qinit(&d->rq);
	d->readTimeStamp.mSampleTime=-1;
	ms_mutex_init(&d->mutex,NULL);
	
	if (strcmp(card->name,AU_CARD_SPEAKER)==0) {
		d->is_ringer=TRUE;
	} else {
		d->is_ringer=FALSE;
	}
	card->data=d;
}
コード例 #9
0
ファイル: ttypty.c プロジェクト: OS2World/DRV-PPtP
void ttinit(TTY tp)
{
	bmove(tp->t_cc, ttydefchars, sizeof(ttydefchars));
/*
	tp->t_iflag = TTYDEF_IFLAG;
	tp->t_oflag = TTYDEF_OFLAG;
	tp->t_lflag = TTYDEF_LFLAG;
*/
  tp->t_iflag = 0;
  tp->t_oflag = 0;
  tp->t_lflag = 0;
	tp->t_cflag = TTYDEF_CFLAG;
	bset((char far*)&tp->winsize, 0, sizeof(struct pt_winsize));
	qinit(&tp->inq);
	qinit(&tp->outq);
}
コード例 #10
0
ファイル: wincevideods.c プロジェクト: hunghtbk/LinphoneV1
static void v4w_init(MSFilter *f){
	V4wState *s=(V4wState *)ms_new0(V4wState,1);
	int idx;
	s->vsize.width=MS_VIDEO_SIZE_CIF_W;
	s->vsize.height=MS_VIDEO_SIZE_CIF_H;
	//s->pix_fmt=MS_RGB24;
	s->pix_fmt=MS_YUV420P;

	s->rotregvalue = 0;
	s->m_pGraph=NULL;
	s->m_pBuilder=NULL;
	s->m_pControl=NULL;
	s->m_pDXFilter=NULL;
	s->m_pIDXFilter=NULL;
	s->m_pDeviceFilter=NULL;

	qinit(&s->rq);
	for (idx=0;idx<10;idx++)
	{
		s->mire[idx]=NULL;
	}
	ms_mutex_init(&s->mutex,NULL);
	s->start_time=0;
	s->frame_count=-1;
	s->fps=15;

	f->data=s;
}
コード例 #11
0
ファイル: malloc.c プロジェクト: enricmcalvo/virtexsquared
static void _malloc_init()
{
	if (_arena_initialized)
		return;
	
	_arena_initialized = 1;
	_arena = qinit(&_end, TOP_OF_MEMORY - (unsigned int)&_end);
}
コード例 #12
0
ファイル: runsys.c プロジェクト: loglan/loglan
void runsys()
{
    word apt, i;
    procaddr father;

    for (i = 0;  i < MAXPROCESS;  i++ ) /* initialize process descriptors */
    {
        process[ i ].used = FALSE;     /* not used */
        process[ i ].mark = -1;               /* initial mark for processes */
        process[ i ].M = NULL;         /* memory not allocated */
        process[ i ].hash = NULL;
    }
    process[ 0 ].M = M;                /* always contains code */
    dispoff = VIRTSC-(lastprot+1);      /* DISPLAY offset in process object */
    disp2off = dispoff-(lastprot+1);    /* indirect DISPLAY offset */
    ready = qinit();         /* initialize Round-Robin queue */
    ranset();              /* init pseudo-random no. generator */

#if OS2
    {
        SEL gsel, lsel;
        DosGetInfoSeg(&gsel, &lsel);
        ginf = MAKEPGINFOSEG(gsel);
    }
#endif

    if (!remote)                     /* create main process */
    {
        father.node = 0;     /* dummy DL for generated process */
        father.pix  = 0;
        father.mark = 0;
        thispix = 0;                       /* current process index */
        thisp = &process[ thispix ];       /* current process descr pointer */
        initprocess((word) 0, (word) MAINBLOCK, &father);
        mainprog = thisp->prochead;        /* am of main */
        c1 = thisp->c1;            /* pointers to current object */
        c2 = thisp->c2;
        ic = thisp->ic;         /* instruction counter */
        param = thisp->param;           /* parameter vector */
        apt = mainprog+M[ mainprog ];      /* LWA+1 of main */
        display = apt+dispoff;         /* DISPLAY in main */
        display2 = apt+disp2off;   /* indirect DISPLAY in main */
        mnoff = 2;                /* offset of variable mainprog */
        storevirt(thisp->procref, mainprog+mnoff);  /* init variable main */
        M[ apt+STATSL ]++;         /* flag main included in SL chain */
        thisp->status = STOPPED;
        activate(thispix);         /* activate main process */
    }
    else  /* remote */
    {
        thispix = 1;                  /* a dirty trick: set junk current */
        thisp = &process[ thispix ];       /* process for first transfer() */
    }                     /* (must save 'context' somewhere) */
#if DLINK
    net_attention();
#endif
}
コード例 #13
0
ファイル: msv4l2.c プロジェクト: dmonakhov/mediastreamer2
static void msv4l2_init(MSFilter *f){
	V4l2State *s=ms_new0(V4l2State,1);
	s->dev=ms_strdup("/dev/video0");
	s->fd=-1;
	s->vsize=MS_VIDEO_SIZE_CIF;
	s->fps=15;
	s->configured=FALSE;
	f->data=s;
	qinit(&s->rq);
}
コード例 #14
0
ファイル: winvideo2.c プロジェクト: github188/Sip-MCU
static void vfw_init(MSFilter *f){
	VfwState *s=(VfwState *)ms_new0(VfwState,1);
	s->vsize.width=MS_VIDEO_SIZE_CIF_W;
	s->vsize.height=MS_VIDEO_SIZE_CIF_H;
	qinit(&s->rq);
	ms_mutex_init(&s->mutex,NULL);
	s->start_time=0;
	s->frame_count=-1;
	s->fps=15;
	f->data=s;
}
コード例 #15
0
ファイル: macsnd.c プロジェクト: biddyweb/mediastream-plus
static void ca_init(MSFilter *f){
	CAData *d = ms_new0(CAData, 1);
	d->read_started=FALSE;
	d->write_started=FALSE;
	d->bits=16;
	d->rate=8000;
	d->stereo=FALSE;
	qinit(&d->rq);
	d->bufferizer=ms_bufferizer_new();
	ms_mutex_init(&d->mutex,NULL);
	f->data=d;
}	
コード例 #16
0
ファイル: mkhedra.cpp プロジェクト: DimondTheCat/xray
static void traverse(STri *t, int op) {
	STri tnew,tr;
	qinit();
	qput(t,op);
	while(qany()) {
		op = qget(&tr);
		if (!reg_stri(&tr)) continue;
		if (op!=Q_OP) { Q_refl(&tr,&tnew);  qput(&tnew,Q_OP);	}
		if (op!=P_OP) { P_refl(&tr,&tnew);  qput(&tnew,P_OP);	}
		if (op!=R_OP) { R_refl(&tr,&tnew);  qput(&tnew,R_OP);	}
		}
	}
コード例 #17
0
ファイル: msv4l2.c プロジェクト: fremaks/linphone_sdk
static void msv4l2_init(MSFilter *f){
	V4l2State *s=ms_new0(V4l2State,1);
	s->dev=ms_strdup("/dev/video0");
	s->fd=-1;
	s->vsize=MS_VIDEO_SIZE_CIF;
	s->fps=15;
	s->configured=FALSE;
	f->data=s;
#ifdef V4L2_THREADED
	s->thread_run = TRUE;
	qinit(&s->rq);
#endif
}
コード例 #18
0
ファイル: sizeconv.c プロジェクト: biddyweb/mediastream-plus
static void size_conv_init(MSFilter *f){
	SizeConvState *s=(SizeConvState *)ms_new(SizeConvState,1);
	s->target_vsize.width = MS_VIDEO_SIZE_CIF_W;
	s->target_vsize.height = MS_VIDEO_SIZE_CIF_H;
	s->in_vsize.width=0;
	s->in_vsize.height=0;
	s->sws_ctx=NULL;
	s->om=NULL;
	s->start_time=0;
	s->frame_count=-1;
	s->fps=-1; /* default to process ALL frames */
	qinit(&s->rq);
	f->data=s;
}
コード例 #19
0
ファイル: qmatch.c プロジェクト: aquila62/ekiss
void enque(qfmt *tail, unsigned int outpt)
   {
   qfmt *newnode;
   /* Allocate memory and initialize a new node */
   newnode = (qfmt *) qinit();
   /* Place the new node at the tail of the FIFO queue */
   newnode->next = tail->next;
   tail->next = newnode;
   newnode->next->prev = newnode;
   newnode->prev = tail;
   /* The outpt parameter is the output of an ekiss random number */
   /* generator cycle */
   newnode->outpt = outpt;
   } /* enque */
コード例 #20
0
ファイル: oss.c プロジェクト: LaughingAngus/linphone-vs2008
static void oss_init(MSSndCard *card){
	OssData *d=ms_new(OssData,1);
	d->pcmdev=NULL;
	d->mixdev=NULL;
	d->pcmfd=-1;
	d->read_started=FALSE;
	d->write_started=FALSE;
	d->bits=16;
	d->rate=8000;
	d->stereo=FALSE;
	qinit(&d->rq);
	d->bufferizer=ms_bufferizer_new();
	ms_mutex_init(&d->mutex,NULL);
	card->data=d;
}
コード例 #21
0
ファイル: 15.01.c プロジェクト: walrus7521/code
int is_bst2(tree *T) // level traverse
{
    tree *t = NULL;
    qinit();
    my_enqueue(T);
    while (qcount > 0) {
        t = my_dequeue();
        if (t) {
            if ((t->left && t->value < t->left->value) || (t->right && t->value > t->right->value)) {
                return 0;
            }
            if (t->left) my_enqueue(t->left);
            if (t->right) my_enqueue(t->right);
        }
    }
    return 1;
}
コード例 #22
0
ファイル: console.c プロジェクト: 8l/inferno
void
consinit(char* name, char* speed)
{
	int baud, port;

	if(name == nil || cistrcmp(name, "cga") == 0)
		return;
	port = strtoul(name, 0, 0);
	if(port < 0 || port > 1)
		return;
	if(speed == nil || (baud = strtoul(speed, 0, 0)) == 0)
		baud = 9600;

	qinit(&consoq);

	uartspecial(port, kbdchar, consputc, baud);
	useuart = 1;
	uartputs(&consoq, "\n", 1);
}
コード例 #23
0
static void v4l_init(MSFilter *f){
	V4lState *s=ms_new0(V4lState,1);
	s->fd=-1;
	s->run=FALSE;
	s->v4lv2=FALSE;
	s->mmapdbuf=NULL;
	s->vsize.width=MS_VIDEO_SIZE_CIF_W;
	s->vsize.height=MS_VIDEO_SIZE_CIF_H;
	s->pix_fmt=MS_RGB24;
	s->dev=ms_strdup("/dev/video0");
	qinit(&s->rq);
	s->mire=NULL;
	ms_mutex_init(&s->mutex,NULL);
	s->start_time=0;
	s->frame_count=-1;
	s->fps=15;
	s->usemire=(getenv("DEBUG")!=NULL);
	s->queued=0;
	f->data=s;
}
コード例 #24
0
ファイル: pthread.c プロジェクト: BBBSnowball/reconos
void invalidate_thread_info (pthread_info_t *thread)
{
    thread->is_allocated = 0;
    thread->join_thread = NULL;
    thread->start_func = NULL;
    thread->param = NULL;
    thread->retval = NULL;
    thread->parent = NULL;
    thread->state = PTHREAD_STATE_DETACHED;
    alloc_q (&(thread->joinq),1,PTHREAD_JOIN_Q,sizeof(char),0);         // Realloc Q afresh
    qinit (&(thread->joinq));
    thread->joinq.items = &(thread->joinq_mem);

    if( thread->mem_id != -1 ) {
        free_bss_mem (thread->mem_id) ;
        thread->mem_id = -1;                                            // BSS memory unallocated.
    }

    thread->thread_attr = default_attr;
}
コード例 #25
0
ファイル: code.c プロジェクト: varunpatil12/libmanagement
void norecur(tree t, int i)
{	
	stack s;
	nodestore *p;
	p = t;
	qinit(&s);
	while(1)
	{
		if(p){	
	 		 fwrite(p, sizeof(nodestore), 1, datafile[i]);
			 if(p->right)
				 push(&s , p->right);
		 	 p = p->left;
		}
		else if(!empty(&s)) {
			p = pop(&s);
		}
		else
			break;
	}		
}
コード例 #26
0
static void v4m_init(MSFilter *f){
	V4lState *s=ms_new0(V4lState,1);
	s->seqgrab=NULL;
	s->sgchanvideo=NULL;
	s->pgworld=NULL;
	s->decomseq=0;

	s->run=FALSE;
	s->mmapdbuf=NULL;
	s->vsize.width=MS_VIDEO_SIZE_CIF_W;
	s->vsize.height=MS_VIDEO_SIZE_CIF_H;
	s->pix_fmt=MS_RGB24;
	qinit(&s->rq);
	s->mire=NULL;
	ms_mutex_init(&s->mutex,NULL);
	s->start_time=0;
	s->frame_count=-1;
	s->fps=15;
	s->usemire=(getenv("DEBUG")!=NULL);
	s->queued=0;
	f->data=s;
}
コード例 #27
0
ファイル: winsnd.c プロジェクト: Accontech/mediastreamer2
static void winsnd_init(MSSndCard *card){
	WinSndData *d=(WinSndData*)ms_new(WinSndData,1);
    memset(d, 0, sizeof(WinSndData));
	d->bytes_read=0;
	d->pcmdev=NULL;
	d->mixdev=NULL;
    d->sound_err=-1; /* not opened */
	d->read_started=FALSE;
	d->write_started=FALSE;
	d->bits=16;
	d->rate=8000;
	d->stereo=FALSE;
	qinit(&d->rq);
	d->bufferizer=ms_bufferizer_new();
	ms_mutex_init(&d->mutex,NULL);
	card->data=d;
#ifndef DISABLE_SPEEX
	d->pst=0;
#endif
	d->stat_input=0;
	d->stat_output=0;
	d->stat_notplayed=0;
}
コード例 #28
0
ファイル: semaphore.c プロジェクト: BBBSnowball/reconos
//----------------------------------------------------------------------------------------------------//
//  @func - sys_sem_init
//! @desc
//!   Create a semaphore
//!   - Allocate a semaphore structure
//!   - Initialize semaphore value
//! @param
//!   - sem is the location to store the created semaphore identifier
//!   - pshared indicates sharing semantics of this semaphore. Unused right now.
//!   - value is the initial value of the semaphore
//! @return
//!   - Returns 0 on success and created semaphore identifier in *sem
//!   - Returns -1 on error
//!     errno set to,
//!     ENOSPC - If the system is out of resources to allocate another semaphore
//! @note
//!   - None
//----------------------------------------------------------------------------------------------------//
int sys_sem_init (sem_t* sem, int pshared, unsigned value)
{
    signed char i = 0 ;

    for (; i < MAX_SEM; i++) {
	if (sem_heap[i].sem_id == -1) {
	    sem_heap[i].sem_id = i;
	    sem_heap[i].sem_value = value;
	    sem_heap[i].unlink = 0;
	    qinit (&sem_heap[i].sem_wait_q);
	    if (pshared == 0)
		sem_heap[i].owner = current_pid;
	    else
		sem_heap[i].owner = -1;                                 // Any process context can access the semaphore

	    *sem = (sem_t)i;
	    return 0 ;
	}
    }

    kerrno = ENOSPC;
    return -1;
}
コード例 #29
0
ファイル: eval.c プロジェクト: kevinshah96/calculator
token *bracket(node **x) {
	int open = 0, close = 0;
	token *t1;
	t1 = (token *)malloc(sizeof(token));
	if(t1 == NULL) {
		return NULL;
	}
	queue temp;
	qinit(&temp);	
	open++;
	while(open != close) {
		if((*x)->a.type == OPERAND) {
			enqueue(&temp, &((*x)->a));
		}
		if((*x)->a.type == OPERATOR) {
			enqueue(&temp, &((*x)->a));
		}
		if((*x)->a.type == BRACKETO) {
			enqueue(&temp, &((*x)->a));
			open++;
		}
		if((*x)->a.type == BRACKETC) {
			if(open != close + 1) {
				enqueue(&temp, &((*x)->a));
			}
			close++;
		}
		
		(*x) = (*x)->next;
	}
	t1->type = ENDT;
	t1->d.op = '\0';
	enqueue(&temp, t1);
	t1->type = OPERAND;
	t1->d.num = eval(&temp);
	return t1;
}
コード例 #30
0
ファイル: semaphore.c プロジェクト: BBBSnowball/reconos
//----------------------------------------------------------------------------------------------------//
//  @func - sys_sem_open
//! @desc
//!   Creates a mapping between a name and a semaphore
//!   - Check whether named semaphore already exists, if so return a pointer to corresponding sem_t.
//!   - If the semaphore exists and O_EXCL also specified, return error.
//!   - If the semaphore does not exist, create it and map name to the semaphore, return sem_t*.
//! @param
//!   - name is the name of the semaphore
//!   - oflag is the flag specifying open characteristics
//!   - mode is unused
//!   - value is the initial value of the semaphore
//! @return
//!   - Returns a pointer to a sem_t corresponding to newly created or previously existing semaphore
//!   - Returns SEM_FAILED on errors
//!     errno set to,
//!     ENOSPC - If the system is out of resources to create a new semaphore (or mapping)
//!     EEXIST if O_EXCL has been requested and the named semaphore already exists.
//!     EINVAL if the parameters are invalid.
//! @note
//!   - POSIX is vague about the behaviour of sem_open without O_CREAT in the flag. Therefore
//!     such oflags are not supported and SEM_FAILED returned.
//!   - Defined only if named semaphores are configured.
//----------------------------------------------------------------------------------------------------//
sem_t* sys_sem_open (const char* name, int oflag, mode_t mode, unsigned value)
{
    sem_t *sem;
    signed char i;

    if (name == NULL || oflag != O_CREAT) {
        kerrno = EINVAL;
	return (sem_t*)SEM_FAILED;
    }

    sem = get_semt_by_name ((char*)name);

    if (sem != NULL) {
	if (oflag & O_EXCL) {
            kerrno = EEXIST;
	    return (sem_t*)SEM_FAILED;
        }
	return sem;
    }

    for (i=0; i<MAX_SEM; i++) {                                         // No such named semaphore exists. Create one.
	if (sem_heap[i].sem_id == -1) {
	    sem_heap[i].sem_id = i;
	    sem_heap[i].sem_value = value;
	    sem_heap[i].unlink = 0;
	    qinit( &sem_heap[i].sem_wait_q);
	    sem_heap[i].owner = -1;                                     // Any process context can access the semaphore
	    strcpy (sem_map[i].name, name);                             // Setup the name mapping
	    sem_map[i].sem = (sem_t)i;
	    return &(sem_map[i].sem) ;
	}
    }

    kerrno = ENOSPC;
    return (sem_t*)SEM_FAILED;
}