• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ INIT函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中INIT函数的典型用法代码示例。如果您正苦于以下问题:C++ INIT函数的具体用法?C++ INIT怎么用?C++ INIT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了INIT函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: uv_fs_rmdir

int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
    INIT(RMDIR);
    PATH;
    POST;
}
开发者ID:ZTook,项目名称:node-v0.x-archive,代码行数:5,代码来源:fs.c


示例2: uv_fs_unlink

int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
    INIT(UNLINK);
    PATH;
    POST;
}
开发者ID:ZTook,项目名称:node-v0.x-archive,代码行数:5,代码来源:fs.c


示例3: test_atomic64

static __init int test_atomic64(void)
{
	long long v0 = 0xaaa31337c001d00dLL;
	long long v1 = 0xdeadbeefdeafcafeLL;
	long long v2 = 0xfaceabadf00df001LL;
	long long onestwos = 0x1111111122222222LL;
	long long one = 1LL;

	atomic64_t v = ATOMIC64_INIT(v0);
	long long r = v0;
	BUG_ON(v.counter != r);

	atomic64_set(&v, v1);
	r = v1;
	BUG_ON(v.counter != r);
	BUG_ON(atomic64_read(&v) != r);

	INIT(v0);
	atomic64_add(onestwos, &v);
	r += onestwos;
	BUG_ON(v.counter != r);

	INIT(v0);
	atomic64_add(-one, &v);
	r += -one;
	BUG_ON(v.counter != r);

	INIT(v0);
	r += onestwos;
	BUG_ON(atomic64_add_return(onestwos, &v) != r);
	BUG_ON(v.counter != r);

	INIT(v0);
	r += -one;
	BUG_ON(atomic64_add_return(-one, &v) != r);
	BUG_ON(v.counter != r);

	INIT(v0);
	atomic64_sub(onestwos, &v);
	r -= onestwos;
	BUG_ON(v.counter != r);

	INIT(v0);
	atomic64_sub(-one, &v);
	r -= -one;
	BUG_ON(v.counter != r);

	INIT(v0);
	r -= onestwos;
	BUG_ON(atomic64_sub_return(onestwos, &v) != r);
	BUG_ON(v.counter != r);

	INIT(v0);
	r -= -one;
	BUG_ON(atomic64_sub_return(-one, &v) != r);
	BUG_ON(v.counter != r);

	INIT(v0);
	atomic64_inc(&v);
	r += one;
	BUG_ON(v.counter != r);

	INIT(v0);
	r += one;
	BUG_ON(atomic64_inc_return(&v) != r);
	BUG_ON(v.counter != r);

	INIT(v0);
	atomic64_dec(&v);
	r -= one;
	BUG_ON(v.counter != r);

	INIT(v0);
	r -= one;
	BUG_ON(atomic64_dec_return(&v) != r);
	BUG_ON(v.counter != r);

	INIT(v0);
	BUG_ON(atomic64_xchg(&v, v1) != v0);
	r = v1;
	BUG_ON(v.counter != r);

	INIT(v0);
	BUG_ON(atomic64_cmpxchg(&v, v0, v1) != v0);
	r = v1;
	BUG_ON(v.counter != r);

	INIT(v0);
	BUG_ON(atomic64_cmpxchg(&v, v2, v1) != v0);
	BUG_ON(v.counter != r);

	INIT(v0);
	BUG_ON(atomic64_add_unless(&v, one, v0));
	BUG_ON(v.counter != r);

	INIT(v0);
	BUG_ON(!atomic64_add_unless(&v, one, v1));
	r += one;
	BUG_ON(v.counter != r);

//.........这里部分代码省略.........
开发者ID:0xroot,项目名称:Blackphone-BP1-Kernel,代码行数:101,代码来源:atomic64_test.c


示例4: apply_xslt_stylesheet

//!
//! Processes input XML file (e.g., instance metadata) into output XML file or string (e.g., for libvirt)
//! using XSL-T specification file (e.g., libvirt.xsl)
//!
//! @param[in]  xsltStylesheetPath a string containing the path to the XSLT Stylesheet
//! @param[in]  inputXmlPath a string containing the path of the input XML document
//! @param[in]  outputXmlPath a string containing the path of the output XML document
//! @param[out] outputXmlBuffer a string that will contain the output XML data if non NULL and non-0 length.
//! @param[in]  outputXmlBufferSize the length of outputXmlBuffer
//!
//! @return EUCA_OK on success or proper error code. Known error code returned include EUCA_ERROR and EUCA_IO_ERROR.
//!
static int apply_xslt_stylesheet(const char *xsltStylesheetPath, const char *inputXmlPath, const char *outputXmlPath, char *outputXmlBuffer, int outputXmlBufferSize)
{
    int err = EUCA_OK;
    int i = 0;
    int j = 0;
    int bytes = 0;
    int buf_size = 0;
    char c = '\0';
    FILE *fp = NULL;
    xmlChar *buf = NULL;
    boolean applied_ok = FALSE;
    xmlDocPtr doc = NULL;
    xsltStylesheetPtr cur = NULL;
    xsltTransformContextPtr ctxt = NULL;
    xmlDocPtr res = NULL;

    INIT();
    if ((cur = xsltParseStylesheetFile((const xmlChar *)xsltStylesheetPath)) != NULL) {
        if ((doc = xmlParseFile(inputXmlPath)) != NULL) {
            ctxt = xsltNewTransformContext(cur, doc);   // need context to get result
            xsltSetCtxtParseOptions(ctxt, 0);   //! @todo do we want any XSL-T parsing options?

            res = xsltApplyStylesheetUser(cur, doc, NULL, NULL, NULL, ctxt);    // applies XSLT to XML
            applied_ok = ((ctxt->state == XSLT_STATE_OK) ? TRUE : FALSE);   // errors are communicated via ctxt->state
            xsltFreeTransformContext(ctxt);

            if (res && applied_ok) {
                // save to a file, if path was provied
                if (outputXmlPath != NULL) {
                    if ((fp = fopen(outputXmlPath, "w")) != NULL) {
                        if ((bytes = xsltSaveResultToFile(fp, res, cur)) == -1) {
                            LOGERROR("failed to save XML document to %s\n", outputXmlPath);
                            err = EUCA_IO_ERROR;
                        }
                        fclose(fp);
                    } else {
                        LOGERROR("failed to create file %s\n", outputXmlPath);
                        err = EUCA_IO_ERROR;
                    }
                }
                // convert to an ASCII buffer, if such was provided
                if (err == EUCA_OK && outputXmlBuffer != NULL && outputXmlBufferSize > 0) {
                    if (xsltSaveResultToString(&buf, &buf_size, res, cur) == 0) {
                        // success
                        if (buf_size < outputXmlBufferSize) {
                            bzero(outputXmlBuffer, outputXmlBufferSize);
                            for (i = 0, j = 0; i < buf_size; i++) {
                                c = ((char)buf[i]);
                                if (c != '\n')  // remove newlines
                                    outputXmlBuffer[j++] = c;
                            }
                        } else {
                            LOGERROR("XML string buffer is too small (%d > %d)\n", buf_size, outputXmlBufferSize);
                            err = EUCA_ERROR;
                        }
                        xmlFree(buf);
                    } else {
                        LOGERROR("failed to save XML document to a string\n");
                        err = EUCA_ERROR;
                    }
                }
            } else {
                LOGERROR("failed to apply stylesheet %s to %s\n", xsltStylesheetPath, inputXmlPath);
                err = EUCA_ERROR;
            }
            if (res != NULL)
                xmlFreeDoc(res);
            xmlFreeDoc(doc);
        } else {
            LOGERROR("failed to parse XML document %s\n", inputXmlPath);
            err = EUCA_ERROR;
        }
        xsltFreeStylesheet(cur);
    } else {
        LOGERROR("failed to open and parse XSL-T stylesheet file %s\n", xsltStylesheetPath);
        err = EUCA_IO_ERROR;
    }

    return (err);
}
开发者ID:NalaGinrut,项目名称:eucalyptus,代码行数:92,代码来源:xml.c


示例5: step

/*
 * step - map set of states reachable before char to set reachable after
 */
static states
step(struct re_guts *g,
	sopno start,		/* start state within strip */
	sopno stop,		/* state after stop state within strip */
	states bef,		/* states reachable before */
	wint_t ch,		/* character or NONCHAR code */
	states aft)		/* states already known reachable after */
{
	cset *cs;
	sop s;
	sopno pc;
	onestate here;		/* note, macros know this name */
	sopno look;
	int i;

	for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) {
		s = g->strip[pc];
		switch (OP(s)) {
		case OEND:
			assert(pc == stop-1);
			break;
		case OCHAR:
			/* only characters can match */
			assert(!NONCHAR(ch) || ch != OPND(s));
			if (ch == OPND(s))
				FWD(aft, bef, 1);
			break;
		case OBOL:
			if (ch == BOL || ch == BOLEOL)
				FWD(aft, bef, 1);
			break;
		case OEOL:
			if (ch == EOL || ch == BOLEOL)
				FWD(aft, bef, 1);
			break;
		case OBOW:
			if (ch == BOW)
				FWD(aft, bef, 1);
			break;
		case OEOW:
			if (ch == EOW)
				FWD(aft, bef, 1);
			break;
		case OANY:
			if (!NONCHAR(ch))
				FWD(aft, bef, 1);
			break;
		case OANYOF:
			cs = &g->sets[OPND(s)];
			if (!NONCHAR(ch) && CHIN(cs, ch))
				FWD(aft, bef, 1);
			break;
		case OBACK_:		/* ignored here */
		case O_BACK:
			FWD(aft, aft, 1);
			break;
		case OPLUS_:		/* forward, this is just an empty */
			FWD(aft, aft, 1);
			break;
		case O_PLUS:		/* both forward and back */
			FWD(aft, aft, 1);
			i = ISSETBACK(aft, OPND(s));
			BACK(aft, aft, OPND(s));
			if (!i && ISSETBACK(aft, OPND(s))) {
				/* oho, must reconsider loop body */
				pc -= OPND(s) + 1;
				INIT(here, pc);
			}
			break;
		case OQUEST_:		/* two branches, both forward */
			FWD(aft, aft, 1);
			FWD(aft, aft, OPND(s));
			break;
		case O_QUEST:		/* just an empty */
			FWD(aft, aft, 1);
			break;
		case OLPAREN:		/* not significant here */
		case ORPAREN:
			FWD(aft, aft, 1);
			break;
		case OCH_:		/* mark the first two branches */
			FWD(aft, aft, 1);
			assert(OP(g->strip[pc+OPND(s)]) == OOR2);
			FWD(aft, aft, OPND(s));
			break;
		case OOR1:		/* done a branch, find the O_CH */
			if (ISSTATEIN(aft, here)) {
				for (look = 1;
				    OP(s = g->strip[pc+look]) != O_CH;
				    look += OPND(s))
					assert(OP(s) == OOR2);
				FWD(aft, aft, look + 1);
			}
			break;
		case OOR2:		/* propagate OCH_'s marking */
			FWD(aft, aft, 1);
			if (OP(g->strip[pc+OPND(s)]) != O_CH) {
//.........这里部分代码省略.........
开发者ID:jimklimov,项目名称:illumos-gate,代码行数:101,代码来源:engine.c


示例6: uv_fs_fstat

int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
  INIT(FSTAT);
  req->file = file;
  POST;
}
开发者ID:Mikhaska,项目名称:node,代码行数:5,代码来源:fs.c


示例7: main

int main(int argc, char *argv[])
{
    long portno;
    int i, con_count=1;
    time_t t1,t2,t3,t4;
    char wbuffer[256];
    int connlist[1024*65];
    int result[1024*65];
    struct hostent *server;
    struct sockaddr_in serv_addr;

    INIT();

    if (argc != 4) {
        fprintf(stderr,"Usage:\n\t%s hostname port clients\n\n", argv[0]);
        exit(0);
    }

    con_count = atol(argv[3]);
    if (con_count<1) con_count=1;
    if (con_count>1024*65) con_count=1024*65;

    portno = atol(argv[2]);
    if (portno<1l || portno>0xFFFFl) {
        fprintf(stderr, "ERROR, invalid port\n");
        exit(0);
    }

    server = gethostbyname(argv[1]);
    if (server == NULL) {
        fprintf(stderr, "ERROR, no such host\n");
        exit(0);
    }

    memset(&serv_addr, 0, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    memcpy(server->h_addr, &serv_addr.sin_addr.s_addr, server->h_length);
    serv_addr.sin_port = htons((short)portno);

    sprintf(wbuffer, "GET / HTTP/1.0\r\n\r\n");

    t1 = time(0);
    for (i=0;i<con_count;i++) {
        result[i] = connlist[i] = connect_to_server(&serv_addr);
    }
    t2 = time(0);
    for (i=0;i<con_count;i++) {
        if (result[i]>=0) {
            result[i] = send_to_server(connlist[i], wbuffer);
        }
    }
    t3 = time(0);
    for (i=0;i<con_count;i++) {
        if (result[i]>=0) {
            result[i] = read_from_server(connlist[i]);
        }
    }
    t4 = time(0);

    printf("\n");
    printf("conn:  %.0lf\n", difftime(t2,t1));
    printf("write: %.0lf\n", difftime(t3,t2));
    printf("read:  %.0lf\n", difftime(t4,t3));

    for (i=-10;i<1000;i++) {
        int j,cnt=0;
        for(j=0;j<con_count;j++) {
            if (result[j]==i) cnt++;
        }
        if (cnt>0) {
            printf("%5i\t%7u\n", i, cnt);
        }
    }

    return 0;
}
开发者ID:alemv,项目名称:civetweb,代码行数:76,代码来源:testclient.c


示例8: test_atomic64

static __init void test_atomic64(void)
{
	long long v0 = 0xaaa31337c001d00dLL;
	long long v1 = 0xdeadbeefdeafcafeLL;
	long long v2 = 0xfaceabadf00df001LL;
	long long onestwos = 0x1111111122222222LL;
	long long one = 1LL;

	atomic64_t v = ATOMIC64_INIT(v0);
	long long r = v0;
	BUG_ON(v.counter != r);

	atomic64_set(&v, v1);
	r = v1;
	BUG_ON(v.counter != r);
	BUG_ON(atomic64_read(&v) != r);

	TEST(64, add, +=, onestwos);
	TEST(64, add, +=, -one);
	TEST(64, sub, -=, onestwos);
	TEST(64, sub, -=, -one);
	TEST(64, or, |=, v1);
	TEST(64, and, &=, v1);
	TEST(64, xor, ^=, v1);
	TEST(64, andnot, &= ~, v1);

	RETURN_FAMILY_TEST(64, add_return, +=, onestwos);
	RETURN_FAMILY_TEST(64, add_return, +=, -one);
	RETURN_FAMILY_TEST(64, sub_return, -=, onestwos);
	RETURN_FAMILY_TEST(64, sub_return, -=, -one);

	INIT(v0);
	atomic64_inc(&v);
	r += one;
	BUG_ON(v.counter != r);

	INIT(v0);
	atomic64_dec(&v);
	r -= one;
	BUG_ON(v.counter != r);

	INC_RETURN_FAMILY_TEST(64, v0);
	DEC_RETURN_FAMILY_TEST(64, v0);

	XCHG_FAMILY_TEST(64, v0, v1);
	CMPXCHG_FAMILY_TEST(64, v0, v1, v2);

	INIT(v0);
	BUG_ON(atomic64_add_unless(&v, one, v0));
	BUG_ON(v.counter != r);

	INIT(v0);
	BUG_ON(!atomic64_add_unless(&v, one, v1));
	r += one;
	BUG_ON(v.counter != r);

#ifdef CONFIG_ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
	INIT(onestwos);
	BUG_ON(atomic64_dec_if_positive(&v) != (onestwos - 1));
	r -= one;
	BUG_ON(v.counter != r);

	INIT(0);
	BUG_ON(atomic64_dec_if_positive(&v) != -one);
	BUG_ON(v.counter != r);

	INIT(-one);
	BUG_ON(atomic64_dec_if_positive(&v) != (-one - one));
	BUG_ON(v.counter != r);
#else
#warning Please implement atomic64_dec_if_positive for your architecture and select the above Kconfig symbol
#endif

	INIT(onestwos);
	BUG_ON(!atomic64_inc_not_zero(&v));
	r += one;
	BUG_ON(v.counter != r);

	INIT(0);
	BUG_ON(atomic64_inc_not_zero(&v));
	BUG_ON(v.counter != r);

	INIT(-one);
	BUG_ON(!atomic64_inc_not_zero(&v));
	r += one;
	BUG_ON(v.counter != r);
}
开发者ID:a2hojsjsjs,项目名称:linux,代码行数:87,代码来源:atomic64_test.c


示例9: deliver

int deliver (FILE *f,unsigned long msglen,char *user)
{
  MAILSTREAM *ds = NIL;
  char *s,*mailbox,tmp[MAILTMPLEN],path[MAILTMPLEN];
  STRING st;
  struct stat sbuf;
				/* have a mailbox specifier? */
  if ((mailbox = strchr (user,'+')) != NULL) {
    *mailbox++ = '\0';		/* yes, tie off user name */
    if (!*mailbox || !compare_cstring ((unsigned char *) mailbox,"INBOX"))
      mailbox = NIL;		/* user+ and user+INBOX same as user */
  }
  if (!*user) user = myusername ();
  else if (strcmp (user,myusername ()))
    return fail ("can't deliver to other user",EX_CANTCREAT);
  sprintf (tmp,"delivering to %.80s+%.80s",user,mailbox ? mailbox : "INBOX");
  mm_dlog (tmp);
				/* prepare stringstruct */
  INIT (&st,file_string,(void *) f,msglen);
  if (mailbox) {		/* non-INBOX name */
    switch (mailbox[0]) {	/* make sure a valid name */
    default:			/* other names, try to deliver if not INBOX */
      if ((strlen (mailbox) <= NETMAXMBX) &&
	  !strstr (mailbox,"..") && !strstr (mailbox,"//") &&
	  !strstr (mailbox,"/~") && mailboxfile (path,mailbox) && path[0] &&
	  !deliver_safely (NIL,&st,mailbox,path,tmp)) return NIL;
    case '%': case '*':		/* wildcards not valid */
    case '/':			/* absolute path names not valid */
    case '~':			/* user names not valid */
      sprintf (tmp,"invalid mailbox name %.80s+%.80s",user,mailbox);
      mm_log (tmp,WARN);
      break;
    }
    mm_dlog ("retrying delivery to INBOX");
    SETPOS (&st,0);		/* rewind stringstruct just in case */
  }

				/* no -I, resolve "INBOX" into path */
  if (mailboxfile (path,mailbox = "INBOX") && !path[0]) {
				/* clear box, get generic INBOX prototype */
    if (!(ds = mail_open (NIL,"INBOX",OP_PROTOTYPE)))
      fatal ("no INBOX prototype");
				/* standard system driver? */
    if (!strcmp (ds->dtb->name,"unix") || !strcmp (ds->dtb->name,"mmdf")) {
      strcpy (path,sysinbox ());/* use system INBOX */
      if (!lstat (path,&sbuf))	/* deliver to existing system INBOX */
	return deliver_safely (ds,&st,mailbox,path,tmp);
    }
    else {			/* other driver, try ~/INBOX */
      if ((mailboxfile (path,"&&&&&") == path) &&
	  (s = strstr (path,"&&&&&")) && strcpy (s,"INBOX") &&
	  !lstat (path,&sbuf)){	/* deliver to existing ~/INBOX */
	sprintf (tmp,"#driver.%s/INBOX",ds->dtb->name);
	return deliver_safely (ds,&st,cpystr (tmp),path,tmp);
      }
    }
				/* not dummy, deliver to driver imputed path */
    if (strcmp (ds->dtb->name,"dummy"))
      return (ibxpath (ds,&mailbox,path) && !lstat (path,&sbuf)) ?
	deliver_safely (ds,&st,mailbox,path,tmp) :
	  fail ("unable to resolve INBOX path",EX_CANTCREAT);
				/* dummy, empty imputed append path exist? */
    if (ibxpath (ds = default_proto (T),&mailbox,path) &&
	!lstat (path,&sbuf) && !sbuf.st_size)
      return deliver_safely (ds,&st,mailbox,path,tmp);
				/* impute path that we will create */
    if (!ibxpath (ds = default_proto (NIL),&mailbox,path))
      return fail ("unable to resolve INBOX",EX_CANTCREAT);
  }
				/* black box, must create, get create proto */
  else if (lstat (path,&sbuf)) ds = default_proto (NIL);
  else {			/* black box, existing file */
				/* empty file, get append prototype */
    if (!sbuf.st_size) ds = default_proto (T);
				/* non-empty, get prototype from its data */
    else if (!(ds = mail_open (NIL,"INBOX",OP_PROTOTYPE)))
      fatal ("no INBOX prototype");
				/* error if unknown format */
    if (!strcmp (ds->dtb->name,"phile"))
      return fail ("unknown format INBOX",EX_UNAVAILABLE);
				/* otherwise can deliver to it */
    return deliver_safely (ds,&st,mailbox,path,tmp);
  }
  sprintf (tmp,"attempting to create mailbox %.80s path %.80s",mailbox,path);
  mm_dlog (tmp);
				/* supplicate to the Evil One */
  if (!path_create (ds,path)) return fail ("can't create INBOX",EX_CANTCREAT);
  sprintf (tmp,"created %.80s",path);
  mm_dlog (tmp);
				/* deliver the message */
  return deliver_safely (ds,&st,mailbox,path,tmp);
}
开发者ID:alpinemail,项目名称:alpine,代码行数:92,代码来源:dmail.c


示例10: test

static void test() {
    string x,y,xx,yy,tag,mess,en_mess,pri,m;
    INIT(x);
    INIT(y);
    INIT(xx);
    INIT(yy);
    INIT(tag);
    INIT(mess);
    INIT(en_mess);
    INIT(pri);
    INIT(m);

    mess.len = 10;
    mess.buf = "helloword";

    int res = crypto_ECIES_get_key(&pri,&x,&y);
    string_printf("p",&pri);
    string_printf("x",&x);
    string_printf("y",&y);
    printf("res :%d\n",res);

    FILE *fd;
    fd = fopen("./x","w");
    fwrite(x.buf,1,x.len,fd);
    fd = fopen("./y","w");
    fwrite(y.buf,1,y.len,fd);
    fd = fopen("./p","w");
    fwrite(pri.buf,1,pri.len,fd);



    res = crypto_ECIES_encrypto_message(&mess,&x,&y,&xx,&yy,&en_mess,&tag);
    // string_malloc(&xx,32);
    // string_malloc(&yy,32);
    // string_malloc(&tag,20);
    // string_malloc(&en_mess,20);
    //res = ECIES_encrypto_message(mess.buf,mess.len,x.buf,x.len,y.buf,y.len,xx.buf,&xx.len,yy.buf,&yy.len,en_mess.buf,&en_mess.len,tag.buf,&tag.len);
    string_printf("tag",&tag);
    string_printf("xx",&xx);
    string_printf("yy",&yy);
    string_printf("en_mess",&en_mess);
    printf("res :%d\n",res);


    fd = fopen("encrypted_mess","w");
    fwrite(en_mess.buf,1,en_mess.len,fd);
    fd = fopen("xx","w");
    fwrite(xx.buf,1,xx.len,fd);
    fd = fopen("yy","w");
    fwrite(yy.buf,1,yy.len,fd);
    fd = fopen("tag","w");
    fwrite(tag.buf,1,tag.len,fd);


    res = crypto_ECIES_decrypto_message(&en_mess,&xx,&yy,&tag,&pri,&m);
    //string_malloc(&m,11);
    //string_printf("m",&m);
    //res = ECIES_decrypto_message(en_mess.buf,en_mess.len,xx.buf,xx.len,yy.buf,yy.len,tag.buf,tag.len,pri.buf,pri.len,m.buf,&m.len);
    string_printf("m",&m);
    printf("%s\n",m.buf);
    printf("res :%d\n",res);

}
开发者ID:ploce,项目名称:bdfnjhmdfbgb,代码行数:63,代码来源:cert.c


示例11: main

int main(void) {
    check_offloading();

    double A[N], B[N], C[N], D[N], E[N];
    int fail = 0;

    INIT();

    // **************************
    // Series 1: no dist_schedule
    // **************************

    //
    // Test: #iterations == #teams
    //
    ZERO(A);
    for (int t = 0 ; t < TRIALS ; t++) {
        #pragma omp target teams distribute num_teams(512)
        for (int i = 0 ; i < 512 ; i++)
        {
            A[i] += C[i]; // += 1 per position
        }
    }
    for (int i = 0 ; i < 512 ; i++)
        if (A[i] != TRIALS) {
            printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]);
            fail = 1;
        }
    if(fail) printf("Failed\n");
    else printf("Succeeded\n");


    //
    // Test: #iterations > #teams
    //
    ZERO(A);
    for (int t = 0 ; t < TRIALS ; t++) {
        #pragma omp target teams distribute num_teams(256)
        for (int i = 0 ; i < 500 ; i++)
        {
            A[i] += C[i]; // += 1 per position
        }
    }
    for (int i = 0 ; i < 500 ; i++)
        if (A[i] != TRIALS) {
            printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]);
            fail = 1;
        }
    if(fail) printf("Failed\n");
    else printf("Succeeded\n");

    //
    // Test: #iterations < #teams
    //
    ZERO(A);
    for (int t = 0 ; t < TRIALS ; t++) {
        #pragma omp target teams distribute num_teams(256)
        for (int i = 0 ; i < 123 ; i++)
        {
            A[i] += C[i]; // += 1 per position
        }
    }
    for (int i = 0 ; i < 123 ; i++)
        if (A[i] != TRIALS) {
            printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]);
            fail = 1;
        }
    if(fail) printf("Failed\n");
    else printf("Succeeded\n");

    // ****************************
    // Series 2: with dist_schedule
    // ****************************

    //
    // Test: #iterations == #teams, dist_schedule(1)
    //
    ZERO(A);
    for (int t = 0 ; t < TRIALS ; t++) {
        #pragma omp target teams distribute dist_schedule(static,1) num_teams(512)
        for (int i = 0 ; i < 512 ; i++)
        {
            A[i] += C[i]; // += 1 per position
        }
    }
    for (int i = 0 ; i < 512 ; i++)
        if (A[i] != TRIALS) {
            printf("Error at %d, h = %lf, d = %lf\n", i, (double) TRIALS, A[i]);
            fail = 1;
        }
    if(fail) printf("Failed\n");
    else printf("Succeeded\n");

    //
    // Test: #iterations == #teams, dist_schedule(#iterations)
    //
    ZERO(A);
    for (int t = 0 ; t < TRIALS ; t++) {
        #pragma omp target teams distribute dist_schedule(static,512) num_teams(512)
        for (int i = 0 ; i < 512 ; i++)
//.........这里部分代码省略.........
开发者ID:clang-ykt,项目名称:openmp,代码行数:101,代码来源:test.c


示例12: main

int
main()
{
    HANDLE ht_selfsuspend, ht_exit, ht_window;
    DWORD tid, res;

    INIT();

    print("creating window\n");
    ht_window = CreateThread(NULL, 0, window_func, NULL, 0, &tid);
    if (ht_window == NULL) {
        print("Error creating window thread\n");
        return -1;
    }
    while (!thread_ready)
        Sleep(20);

    print("detach_callback start\n");

    ht_selfsuspend = CreateThread(NULL, 0, &ThreadProcSelfSuspend, NULL, 0, &tid);
    if (ht_selfsuspend == NULL) {
        print("Error creating self-suspend thread\n");
        return -1;
    }
    /* wait for thread to suspend itself */
    res = 0;
    while (res == 0) {
        res = SuspendThread(ht_selfsuspend);
        if (res == 0) {
            /* Thread might not yet have gotten around to suspending itself */
            ResumeThread(ht_selfsuspend);
            /* short sleep to wait */
            Sleep(20);
        }
    }

    do_test(2);
    print("finished first callback test\n");

    action_exit = TRUE;
    ht_exit = CreateThread(NULL, 0, &ThreadProcDoTest, (void *)2, 0, &tid);
    if (ht_exit == NULL) {
        print("Error creating exit thread\n");
        return -1;
    }
    WaitForSingleObject(ht_exit, INFINITE);
    CloseHandle(ht_exit);
    print("finished exit test\n");
    action_exit = FALSE;

    action_detach = TRUE;
    do_test(2);
    print("finished detach test\n");
    action_detach = FALSE;
    /* we are now detached */

    /* just a little extra work to make sure everything looks ok natively */
    do_test(1);
    print("finished second callback test\n");

    /* verify selfsuspended thread detached okay */
    ResumeThread(ht_selfsuspend);
    ResumeThread(ht_selfsuspend);
    WaitForSingleObject(ht_selfsuspend, INFINITE);
    CloseHandle(ht_selfsuspend);

    print("detach_callback done\n");
    return 0;
}
开发者ID:stoyannk,项目名称:dynamorio,代码行数:69,代码来源:detach_test.c


示例13: fuse_main

/*! Main
@param argc number of arguments
@param argv arguments
 @return fuse_main()s return value
*/
int main(int argc, char **argv)
{
    /* return value of fuse_main() */
    int ret;

    /* for signal handling */
    struct sigaction sig;

    /* argument handling */
    struct fuse_args args = FUSE_ARGS_INIT(argc, argv);

    /* file name for database */
    char *db_file;


    /*------------------------*
     * install signal handler *
     *------------------------*/

    /* set handling function */
    sig.sa_handler = sig_handler;

    /* set (no) flags */
    sig.sa_flags = 0;

    /* don't ignore any signal */
    sigemptyset(&sig.sa_mask);

    /* install signal handler for USR1 and USR2 */
    sigaction(SIGUSR1, &sig, NULL);
    sigaction(SIGUSR2, &sig, NULL);


    /*------------------*
     * handle arguments *
     *------------------*/

    if (fuse_opt_parse(&args, &discofs_options, discofs_opts, discofs_opt_proc) == -1)
        return EXIT_FAILURE;

    /* after option parsing, remote mount point must be set */
    if (!REMOTE_ROOT)
    {
        fprintf(stderr, "no remote filesystem given\n");
        return EXIT_FAILURE;
    }

    /* a mount point for discofs must also be set */
    if (!discofs_options.discofs_mp)
    {
        fprintf(stderr, "no mount point given\n");
        return EXIT_FAILURE;
    }

    /* add "use_ino" to display inodes in stat(1)*/
    fuse_opt_add_arg(&args, "-ouse_ino");


    /*---------------*
     * set UID / GID *
     *---------------*/

    /* set GID first since permissions might not be
       sufficient if UID was set beforehand */
    if (discofs_options.gid)
    {
        VERBOSE("setting gid to %d\n", discofs_options.gid);
        if (setgid(discofs_options.gid))
        {
            perror("setting gid");
            return EXIT_FAILURE;
        }
    }
    if (discofs_options.uid)
    {
        VERBOSE("setting uid to %d\n", discofs_options.uid);
        if (setuid(discofs_options.uid))
        {
            perror("setting uid");
            return EXIT_FAILURE;
        }
    }


    /*--------------------*
     * initialize logging *
     *--------------------*/

    /* if -d is specified, override logging settings */
    if (discofs_options.debug)
        log_init(LOG_DEBUG, NULL);
    else
        log_init(discofs_options.loglevel, discofs_options.logfile);


//.........这里部分代码省略.........
开发者ID:laevar,项目名称:discofs,代码行数:101,代码来源:discofs.c


示例14: SEGGER_RTT_TerminalOut

/*********************************************************************
*
*       SEGGER_RTT_TerminalOut
*
*  Function description
*    Writes a string to the given terminal
*     without changing the terminal for channel 0.
*
*  Parameters
*    TerminalId   Index of the terminal.
*    s            String to be printed on the terminal.
*
*  Return value
*    >= 0 - Number of bytes written.
*     < 0 - Error.
*
*/
int SEGGER_RTT_TerminalOut (char TerminalId, const char* s) {
  int                   Status;
  unsigned              FragLen;
  unsigned              Avail;
  SEGGER_RTT_BUFFER_UP* pRing;
  //
  INIT();
  //
  // Validate terminal ID.
  //
  if (TerminalId < (char)sizeof(_aTerminalId)) { // We only support a certain number of channels
    //
    // Get "to-host" ring buffer.
    //
    pRing = &_SEGGER_RTT.aUp[0];
    //
    // Need to be able to change terminal, write data, change back.
    // Compute the fixed and variable sizes.
    //
    FragLen = strlen(s);
    //
    // How we output depends upon the mode...
    //
    SEGGER_RTT_LOCK();
    Avail = _GetAvailWriteSpace(pRing);
    switch (pRing->Flags & SEGGER_RTT_MODE_MASK) {
    case SEGGER_RTT_MODE_NO_BLOCK_SKIP:
      //
      // If we are in skip mode and there is no space for the whole
      // of this output, don't bother switching terminals at all.
      //
      if (Avail < (FragLen + 4u)) {
        Status = 0;
      } else {
        _PostTerminalSwitch(pRing, TerminalId);
        Status = (int)_WriteBlocking(pRing, s, FragLen);
        _PostTerminalSwitch(pRing, _ActiveTerminal);
      }
      break;
    case SEGGER_RTT_MODE_NO_BLOCK_TRIM:
      //
      // If we are in trim mode and there is not enough space for everything,
      // trim the output but always include the terminal switch.  If no room
      // for terminal switch, skip that totally.
      //
      if (Avail < 4u) {
        Status = -1;
      } else {
        _PostTerminalSwitch(pRing, TerminalId);
        Status = (int)_WriteBlocking(pRing, s, (FragLen < (Avail - 4u)) ? FragLen : (Avail - 4u));
        _PostTerminalSwitch(pRing, _ActiveTerminal);
      }
      break;
    case SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL:
      //
      // If we are in blocking mode, output everything.
      //
      _PostTerminalSwitch(pRing, TerminalId);
      Status = (int)_WriteBlocking(pRing, s, FragLen);
      _PostTerminalSwitch(pRing, _ActiveTerminal);
      break;
    default:
      Status = -1;
      break;
    }
    //
    // Finish up.
    //
    SEGGER_RTT_UNLOCK();
  } else {
    Status = -1;
  }
  return Status;
}
开发者ID:01org,项目名称:zephyr,代码行数:91,代码来源:SEGGER_RTT.c


示例15: main

int main(void)
{
	INIT();
	
	long int i;
	int l = 10, r = 5;
	Object list = List_Create();
	Object list2 = List_Create();
	Object temp_list;
	Object front, back;
	
	
	// list2 = (0 1 2 3 4 5 6 ... 148 149)
	for(i = 0; i < l + r; i++)
	{
		List_PushBack(list2, INT_AS_OBJECT(i));
	};
	
	// list = (99998 99996 ... 8 6 4 2 0 1 3 5 7 9 ... 99997 99999 )
	for(i = 0; i < NODES; i++)
	{
		if(i & 1)
		{
			List_PushBack(list, INT_AS_OBJECT(i));
		} else {
			List_PushFront(list, INT_AS_OBJECT(i));
		};
	};

	for(front = List_First(list), i = 0; i < NODES / 2; ListIterator_Next(front), i++)
	{
		List_AddAfterPosition(list2, INT_AS_OBJECT(l - 1 + i), ListIterator_ThisData(front));
	};

	for(back = List_Last(list), i = 0; i < NODES / 2; ListIterator_Prev(back), i++)
	{
		List_AddAfterPosition(list2, INT_AS_OBJECT(l + NODES / 2 - 1), ListIterator_ThisData(back));
	};

	front = List_IteratorFromPosition(list2, INT_AS_OBJECT(l));
	TEST("Checking for correctness of IteratorFromPosition after AddList{Before|After}", 
		OBJECT_AS_INT(ListIterator_ThisData(front)) == (NODES & (~1)) - ((!(NODES & 1)) * 2));
	back = List_IteratorFromPosition(list2, INT_AS_OBJECT(l + NODES - 1));
	TEST("Checking for correctness of IteratorFromPosition after AddList{Before|After}", 
		OBJECT_AS_INT(ListIterator_ThisData(back)) == (NODES & (~1)) - 1 + ((NODES & 1) * 2));
	temp_list = List_SublistBetweenIterators(list2, front, back);
	front = List_First(temp_list);
	back = List_Last(temp_list);
	
	for(i = 1; i < NODES / 2; i++)
	{
		if(OBJECT_AS_INT(ListIterator_ThisData(front)) != OBJECT_AS_INT(ListIterator_ThisData(back)) + 1)
		{
			DEBUG("Got %li and %li.\n", OBJECT_AS_INT(ListIterator_ThisData(front)), OBJECT_AS_INT(ListIterator_ThisData(back)));
			return 1;
		};
		ListIterator_Next(front);
		ListIterator_Prev(back);
	};
	
	Object_Release(list);
	Object_Release(list2);
	Object_Release(temp_list);
	return 0;
};
开发者ID:VsevolodSauta,项目名称:SvvLang,代码行数:65,代码来源:test6.c


示例16: uv_fs_fsync

int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
  INIT(FSYNC);
  req->file = file;
  POST;
}
开发者ID:Mikhaska,项目名称:node,代码行数:5,代码来源:fs.c


示例17: main

int main(void){
  #if CHECK
    check_offloading();
  #endif

  /*
   * Default device
   */
  printf("Is%s initial device\n", omp_is_initial_device() ? "" : " not");
  printf("Initial device: %d\n", omp_get_initial_device());
  omp_set_default_device(1);
  printf("Default device before task: %d\n", omp_get_default_device());
  #pragma omp task
  {
    printf("Default device inside task: %d\n", omp_get_default_device());
    omp_set_default_device(2);
    printf("Default device inside task after resetting: %d\n",
        omp_get_default_device());
  }
  #pragma omp taskwait
  printf("Default device outside task: %d\n", omp_get_default_device());

  // default device can set to whatever, if target fails, it goes to the host
  const int default_device = 0;
  omp_set_default_device(default_device);

  // default device for omp target call MUST be >= 0 and <omp_get_num_devices() or
  // the initial device. So when there are no devices, it must be the initial device
  int default_device_omp_target_call = default_device;
  if (omp_get_num_devices() == 0) {
    default_device_omp_target_call = omp_get_initial_device();
  } 
  #if DEBUG
    printf("test on machine with %d devices\n", omp_get_num_devices());
  #endif
  /*
   * Target alloc & target memcpy
   */
  double A[N], B[N], C[N], D[N], E[N];
  double *pA, *pB, *pC, *pD, *pE;
  // map ptrs
  pA = &A[0];
  pB = &B[0];
  pC = &C[0];
  pD = &D[0];
  pE = &E[0];

  INIT();

  pA = pA - 10;
  pC = pC - 20;
  pD = pD - 30;
  void *device_A = omp_target_alloc(N*sizeof(double), default_device_omp_target_call);
  void *device_C = omp_target_alloc(N*sizeof(double), default_device_omp_target_call);
  void *device_D = omp_target_alloc(N*sizeof(double), default_device_omp_target_call);
  double *dpA = (double *) device_A - 100;
  double *dpC = (double *) device_C - 200;
  double *dpD = (double *) device_D - 300;
  printf("omp_target_alloc %s\n", device_A && device_C && device_D ?
      "succeeded" : "failed");

  omp_target_memcpy(dpC, pC, N*sizeof(double), 200*sizeof(double),
      20*sizeof(double), default_device_omp_target_call, omp_get_initial_device());
  omp_target_memcpy(dpD, pD, N*sizeof(double), 300*sizeof(double),
      30*sizeof(double), default_device_omp_target_call, omp_get_initial_device());

  #pragma omp target is_device_ptr(dpA, dpC, dpD) device(default_device)
  {
    #pragma omp parallel for schedule(static,1)
    for (int i = 0; i < 992; i++)
      dpA[i+100] = dpC[i+200] + dpD[i+300] + 1;
  }

  omp_target_memcpy(pA, dpA, N*sizeof(double), 10*sizeof(double),
      100*sizeof(double), omp_get_initial_device(), default_device_omp_target_call);

  int fail = 0;
  VERIFY(0, N, A[i], (double)(i+2));
  if (fail) {
    printf ("Test omp_target_memcpy: Failed\n");
  } else {
    printf ("Test omp_target_memcpy: Succeeded\n");
  }

  /*
   * target_is_present and target_associate/disassociate_ptr
   */
  INIT();
  if (offloading_disabled()) {
    // If offloading is disabled just recreate the messages so that this can
    // also be tested with no device.
    printf("C is not present, associating it...\n");
    printf("omp_target_associate_ptr C %s\n", 1 ? "succeeded" : "failed");
  } else if (!omp_target_is_present(C, default_device_omp_target_call)) {
    printf("C is not present, associating it...\n");
    int rc = omp_target_associate_ptr(C, dpC, N*sizeof(double),
        200*sizeof(double), default_device_omp_target_call);
    printf("omp_target_associate_ptr C %s\n", !rc ? "succeeded" : "failed");
  }
  if (offloading_disabled()) {
//.........这里部分代码省略.........
开发者ID:hashimSharif,项目名称:openmp,代码行数:101,代码来源:test.c


示例18: gen_instance_xml

//!
//! Encodes instance metadata (contained in ncInstance struct) in XML
//! and writes it to file instance->xmlFilePath (/path/to/instance/instance.xml)
//! That file gets processed through tools/libvirt.xsl (/etc/eucalyptus/libvirt.xsl)
//! to produce /path/to/instance/libvirt.xml file that is passed to libvirt create.
//!
//! @param[in] instance a pointer to the instance to generate XML from
//!
//! @return EUCA_OK if the operation is successful. Known error code returned include EUCA_ERROR.
//!
//! @see write_xml_file()
//!
int gen_instance_xml(const ncInstance * instance)
{
    int ret = EUCA_ERROR;
    int i = 0;
    int j = 0;
    char *path = NULL;
    char cores_s[10] = "";
    char memory_s[10] = "";
    char bitness[4] = "";
    char root_uuid[64] = "";
    char devstr[SMALL_CHAR_BUFFER_SIZE] = "";
    xmlNodePtr disk = NULL;
    xmlDocPtr doc = NULL;
    xmlNodePtr instanceNode = NULL;
    xmlNodePtr hypervisor = NULL;
    xmlNodePtr backing = NULL;
    xmlNodePtr root = NULL;
    xmlNodePtr key = NULL;
    xmlNodePtr os = NULL;
    xmlNodePtr disks = NULL;
    xmlNodePtr rootNode = NULL;
    xmlNodePtr nics = NULL;
    xmlNodePtr nic = NULL;
    const virtualBootRecord *vbr = NULL;

    INIT();

    pthread_mutex_lock(&xml_mutex);
    {
        doc = xmlNewDoc(BAD_CAST "1.0");
        instanceNode = xmlNewNode(NULL, BAD_CAST "instance");
        xmlDocSetRootElement(doc, instanceNode);

        // hypervisor-related specs
        hypervisor = xmlNewChild(instanceNode, NULL, BAD_CAST "hypervisor", NULL);
        _ATTRIBUTE(hypervisor, "type", instance->hypervisorType);
        _ATTRIBUTE(hypervisor, "capability", hypervsorCapabilityTypeNames[instance->hypervisorCapability]);
        snprintf(bitness, 4, "%d", instance->hypervisorBitness);
        _ATTRIBUTE(hypervisor, "bitness", bitness);

        //! backing specification (@todo maybe expand this with device maps or whatnot?)
        backing = xmlNewChild(instanceNode, NULL, BAD_CAST "backing", NULL);
        root = xmlNewChild(backing, NULL, BAD_CAST "root", NULL);
        assert(instance->params.root);
        _ATTRIBUTE(root, "type", ncResourceTypeName[instance->params.root->type]);

        _ELEMENT(instanceNode, "name", instance->instanceId);
        _ELEMENT(instanceNode, "uuid", instance->uuid);
        _ELEMENT(instanceNode, "reservation", instance->reservationId);
        _ELEMENT(instanceNode, "user", instance->userId);
        _ELEMENT(instanceNode, "dnsName", instance->dnsName);
        _ELEMENT(instanceNode, "privateDnsName", instance->privateDnsName);
        _ELEMENT(instanceNode, "instancePath", instance->instancePath);

        if (instance->params.kernel) {
            path = instance->params.kernel->backingPath;
            if (path_check(path, "kernel"))
                goto free;             // sanity check
            _ELEMENT(instanceNode, "kernel", path);
        }

        if (instance->params.ramdisk) {
            path = instance->params.ramdisk->backingPath;
            if (path_check(path, "ramdisk"))
                goto free;             // sanity check
            _ELEMENT(instanceNode, "ramdisk", path);
        }

        _ELEMENT(instanceNode, "consoleLogPath", instance->consoleFilePath);
        _ELEMENT(instanceNode, "userData", instance->userData);
        _ELEMENT(instanceNode, "launchIndex", instance->launchIndex);

        snprintf(cores_s, sizeof(cores_s), "%d", instance->params.cores);
        _ELEMENT(instanceNode, "cores", cores_s);
        snprintf(memor 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ INITIALIZE_PATH函数代码示例发布时间:2022-05-30
下一篇:
C++ INFRA_ON函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap