コード例 #1
0
fluent::Sender::Sender(
                const std::string& h, int p,
                size_t b, float _timeout, bool v)
    :  host(h), port(p), bufmax(b), timeout(_timeout), verbose(v),
        buf(nullptr), sock(Socket::INET, Socket::STREAM)
{
#ifdef FLUENT_MT
    int retval = pthread_mutex_init(&mutex, NULL);
    switch(retval)
    {
        case 0:
            /* success! */
            break;
        case EAGAIN:
            throw NoResources(EAGAIN);
            break;
        case EINVAL:
            throw InvalidAttributes();
            break;
        case ENOMEM:
            throw NoMemory();
            break;
        default:
            throw UnknownError(retval);
    }
#endif
    try {
        reconnect();
    }
    catch(...) {
        close();
    }
}
コード例 #2
0
void *FEF_malloc(int num_bytes,const char *comment)
{
void *ptr;
if(lefDebug[1])
	printf("%s malloc -> %d bytes",comment,num_bytes);
if(num_bytes<1) lefiNerr(115);
ptr =  lefMalloc(num_bytes);
if( ! ptr ) NoMemory();
return ptr;
}
コード例 #3
0
char *memory_malloc(unsigned n)
{
if (array_size == 0) {  /* first time */
    array_size = 64;
    what = (char **)lefMalloc(array_size * sizeof(char *));
    if (what == NULL)
	NoMemory();
    }
nout++;
if (nout > array_size) {
    array_size <<= 1;
    what = (char **)lefRealloc((char *)what, array_size*sizeof(char *));
    if (what == NULL)
	NoMemory();
    }
what[nout-1] = (char *)lefMalloc(n);
if (what[nout-1] == NULL)
    NoMemory();
return what[nout-1];
}
コード例 #4
0
ファイル: pipe.c プロジェクト: berkus/nemesis
Rd_clp CreatePipe(Heap_clp heap, uint32_t bufsize, uint32_t trigger,
		  Wr_clp *wr)
{
    Pipe_st *st;

    st=Heap$Malloc(heap, sizeof(*st));
    if (!st) {
	RAISE_Heap$NoMemory();
    }

    st->buffer=Heap$Malloc(heap, bufsize);
    if (!st->buffer) {
	FREE(st);
	RAISE_Heap$NoMemory();
    }

    CL_INIT(st->rd, &rd_ms, st);
    CL_INIT(st->wr, &wr_ms, st);

    if (bufsize<2) bufsize=2;
    if (trigger>=bufsize) trigger=(bufsize>>1); /* If the trigger value
						   is invalid then fix it */

    st->bufsize=bufsize;
    st->trigger=trigger;
    st->wrp=0;
    st->rdp=0;

    st->ungetc=False;
    st->lastc=-1; /* No character is ungetted */
    MU_INIT(&st->mu);
    CV_INIT(&st->cv);
    MU_INIT(&st->wr_mu);
    MU_INIT(&st->rd_mu);

    st->rd_open=True;
    st->wr_open=True;

    *wr=&st->wr;
    return &st->rd;
}
コード例 #5
0
void *FEF_realloc(void *ptr,int num_bytes,const char *comment)
{
if(lefDebug[1])
	printf("%s realloc -> %d bytes",comment,num_bytes);
if(num_bytes<1) lefiNerr(117);
if(ptr)
	ptr = lefRealloc((char*)ptr,num_bytes);
else
	ptr = lefMalloc(num_bytes);
if( ! ptr ) NoMemory();
return ptr;
}
コード例 #6
0
void *FEF_calloc(int num_elem,int elem_size,const char *comment)
{
int n = num_elem*elem_size;
void *ptr;
if(lefDebug[1])
	printf("%s calloc -> %d * %d = %d bytes"
		,comment,num_elem,elem_size,n);
if(num_elem<1) lefiNerr(169);
if(elem_size<1) lefiNerr(169);
ptr =  calloc(num_elem,elem_size);
if( ! ptr ) NoMemory();
return ptr;
}
コード例 #7
0
void *FEF_free_then_malloc(void *ptr,int num_bytes,const char *comment)
{
if(lefDebug[1])
	printf("%s free, then malloc -> %d bytes",comment,num_bytes);
if(num_bytes<1) lefiNerr(116);
if(ptr)
	{
	free((char*)ptr);
/*
#	ifdef WIN32
	_heapmin();
#	endif
*/
	}
ptr =  lefMalloc(num_bytes);
if( ! ptr ) NoMemory();
return ptr;
}
コード例 #8
0
ファイル: main.c プロジェクト: berkus/nemesis
void Main (Closure_clp self)
{
    FB_st *st;
    IOEntryMod_clp emod;

    int i;
    
    TRC(printf("FB/MGA: entered\n"));
 
    st = (FB_st *)Heap$Malloc(Pvs(heap), 
			      sizeof(FB_st));
    if (st == NULL) 
	RAISE_Heap$NoMemory();

    memset(st, 0, sizeof(FB_st));

    CL_INIT(st->cl, &fb_ms, st);


    /* Before we do anything, see if we can find a framebuffer device
       that we understand. */

    st->cardbase = (Pixel_t *) MGAInit(FB_WIDTH, FB_HEIGHT, FB_DEPTH, FB_MODE);

    TRC(printf("st->cardbase = %p\n", st->cardbase));

    if(!st->cardbase) {
	fprintf(stderr, "Failed to initialise MGA device\n");

	Heap$Free(Pvs(heap), st);

	return;
    }

#ifdef TEST_CARD
    test_card16a( (uint16_t *) st->cardbase );
#else
    memset((uchar_t *) st->cardbase, 0, 
	   FB_WIDTH * FB_HEIGHT * (FB_DEPTH/8) );
#endif	

    /* Init state */
    st->qosleft = 100;
    st->cursched = 0;
    st->schedndx = 0;
    for (i = 0; i < FB_SCHEDLEN; i++) {
	st->sched[0][i] = st->sched[1][i] = 0;
    }
    
    /* Initialise window DS */
    for (i = 0 ; i < FB_MAX_WINDOWS; i++) {
	FB_Window *w = &st->window[i];
	w->wid  = i;
	w->free = True;
	w->tagword = w->tag  = w->wid;

	/* extend the tag to be a full word (32 or 64 bits) wide */
	w->tagword |= (w->tagword<<8);
	w->tagword |= (w->tagword<<16);
	/* Generates harmless overflow warning on 32bit architectures */
	w->tagword |= (w->tagword<<32);

    }
    
    /* Initialise stream DS */
    for (i = 0 ; i < FB_MAX_STREAMS; i++) {
	FB_Stream *s = &st->stream[i];
	s->sid  = i;
	s->free = True;
	s->qos  = 0;
    }

    TRC(printf("About to create an entry...\n"));

    /* Create an entry*/
    emod = NAME_FIND ("modules>IOEntryMod", IOEntryMod_clp);
    st->fbentry = IOEntryMod$New (emod, Pvs(actf), Pvs(vp),
				  VP$NumChannels (Pvs(vp)));    
    

    TRC(printf("About to grab stretches for FB and CLIP\n"));

    /* Grab stretches for FB and CLIP */
    {

	Stretch_clp           str;
	Stretch_Size          size;

	/* Get a stretch for clip RAM. Allocate a spare line of tiles
           at the start and end in case we need to blit over the edges */

	str    = STR_NEW(sizeof(tag_t)*FB_WIDTH*(FB_HEIGHT+16));
	if (!str) {
	    fprintf(stderr,"Couldn't get stretch");
	}
	st->clipstr = str;
	st->clipbase = (tag_t *) STR_RANGE(str, &size);
	st->clip = st->clipbase + (FB_WIDTH * 8);

	if (!st->clip || size < (FB_WIDTH*(FB_HEIGHT+16))) {
	    fprintf(stderr,"Stretch bogus\n");
	}
	TRC(fprintf(stderr,"FB: Clip RAM at %p size %lx\n", st->clip, size));	
    }
    TRC(printf("About to init clip RAM\n"));

    /* Initialise the clip RAM */
    InitClipRAM(&st->cl);

    TRC(printf("About to add dev>fblite to namespace\n"));
    CX_ADD("dev>fblite", st->cardbase, addr_t);

    TRC(printf("About to init blitting code\n"));
    /* Init the blitting code */
    blit_init(st);

    /* Turn on cursor */
    TRC(printf("About to turn on cursor\n"));
    MGALoadCursor(st->cardbase, CURSOR_IDX, CURSOR_BITS);
    MGAMoveCursor(st->cardbase, CURSOR_IDX, CURSOR_INITX, CURSOR_INITY);

    /* Export management interface */
    TRC(printf("About to export management interface\n"));
    IDC_EXPORT ("dev>FB", FB_clp, &st->cl);
    /* Go into a loop to service all the clients */


    /* Launch WSSvr */

    TRC(printf("Trying to launch wssvr\n"));
    TRY {
	Closure_clp wssvr;

	wssvr = NAME_FIND("modules>WSSvr", Closure_clp);
	
	Threads$Fork(Pvs(thds), wssvr->op->Apply, wssvr->st, 0);

	st->wssvr_shares_domain = True;
    } CATCH_ALL {
	printf("Couldn't launch WSSvr - exception %s\n",
	       exn_ctx.cur_exception);
    } ENDTRY;

    TRC(printf("FB/MGA: Init Done. (%ix%i %ibpp mode %i)\n",
	       FB_WIDTH,FB_HEIGHT,FB_DEPTH,FB_MODE));
    blit_loop(st);
}