Exemple #1
0
bool zmq::thread_t::is_current_thread () const
{
    return taskIdSelf () == descriptor;
}
Exemple #2
0
int devRead(myDev * dev, char * data, size_t dataSize)
{
	int taskId;
	fifo * i;
	msg * buff = (msg*)data;
	int buffSize = dataSize/sizeof(msg); //I can't see any reason why sizeof(msg)
										//should change, but let's not take any chances
	int msgsRead = 0;
	printf("1\n");
	taskId = taskIdSelf();
	printf("2\n");
	if (dev==NULL)
	{
		errnoSet(NOT_OPEN);
		return -1;
	}
	//we'll only send whole messages, thus if dataSize<sizeof(msg),
	//we can't send anything :
	if (dataSize<sizeof(msg))
	{
		errnoSet(SHORT_BUFF);
		return -1;
	}
	printf("3\n");
	if(semTake(dev->semMData,WAIT_FOREVER)==-1)
	{
		errnoSet(SEM_ERR);
		return -1;
	}
	printf("4\n");
	//find out wich fifo is our own:
	for (i=dev->firstFifo; i!=NULL && i->taskId!=taskId; i=i->nextFifo);
	if (i==NULL)
	{
		errnoSet(NOT_OPEN);
		return -1;
	}
	printf("5\n");
	semGive(dev->semMData);
	printf("6\n");
	if (i==NULL)
	{
		//We have nothing to write on? This shouldn't happen either...
		errnoSet(NOT_REGISTERED);
		return -1;
	}
	printf("7\n");
	readFifo(i,&(buff[0]), WAIT_FOREVER); //First call block if fifo empty, cf specs.
	printf("8\n");
	msgsRead++;
	printf("9, bufferSize=%d, msgsRead=%d\n",buffSize,msgsRead);
	while (msgsRead<buffSize && readFifo(i,&(buff[msgsRead]),NO_WAIT)==0)
	{
		//Let's read messages until fifo is empty or until the data buffer is 
		//to full to take whole messages
		msgsRead++;
		printf("9.1\n");
	}
	printf("10\n");
	return msgsRead*sizeof(msg);
	
}
Exemple #3
0
/*
 *  Launch the CGI process and return a handle to it. Process spawning
 *  is not supported in VxWorks.  Instead, we spawn a "task".  A major
 *  difference is that we have to know the entry point for the taskSpawn
 *  API.  Also the module may have to be loaded before being executed;
 *  it may also be part of the OS image, in which case it cannot be
 *  loaded or unloaded.  The following sequence is used:
 *  1. If the module is already loaded, unload it from memory.
 *  2. Search for a query string keyword=value pair in the environment
 *      variables where the keyword is cgientry.  If found use its value
 *      as the the entry point name.  If there is no such pair set
 *      the entry point name to the default: basename_cgientry, where
 *      basename is the name of the cgi file without the extension.  Use
 *      the entry point name in a symbol table search for that name to
 *      use as the entry point address.  If successful go to step 5.
 *  3. Try to load the module into memory.  If not successful error out.
 *  4. If step 3 is successful repeat the entry point search from step
 *      2.  If the entry point exists, go to step 5.  If it does not,
 *      error out.
 *  5. Use taskSpawn to start a new task which uses vxWebsCgiEntry
 *      as its starting point.  The five arguments to vxWebsCgiEntry
 *      will be the user entry point address, argp, envp, stdIn
 *      and stdOut.  vxWebsCgiEntry will convert argp to an argc
 *      argv pair to pass to the user entry, it will initialize the
 *      task environment with envp, it will open and redirect stdin
 *      and stdout to stdIn and stdOut, and then it will call the
 *      user entry.
 *  6.  Return the taskSpawn return value.
 */
int websLaunchCgiProc(char_t *cgiPath, char_t **argp, char_t **envp,
						char_t *stdIn, char_t *stdOut)
{
	SYM_TYPE    ptype;
	char_t      *p, *basename, *pEntry, *pname, *entryAddr, **pp;
	int         priority, rc, fd;

/*
 *  Determine the basename, which is without path or the extension.
 */
	if ((int)(p = gstrrchr(cgiPath, '/') + 1) == 1) {
		p = cgiPath;
	}
	basename = bstrdup(B_L, p);
	if ((p = gstrrchr(basename, '.')) != NULL) {
		*p = '\0';
	}

/*
 *  Unload the module, if it is already loaded.  Get the current task
 *  priority.
 */
	unld(cgiPath, 0);
	taskPriorityGet(taskIdSelf(), &priority);
	rc = fd = -1;

/*
 *  Set the entry point symbol name as described above.  Look for an already
 *  loaded entry point; if it exists, spawn the task accordingly.
 */
	for (pp = envp, pEntry = NULL; pp != NULL && *pp != NULL; pp++) {
		if (gstrncmp(*pp, T("cgientry="), 9) == 0) {
			pEntry = bstrdup(B_L, *pp + 9);
			break;
		}
	}
	if (pEntry == NULL) {
		fmtAlloc(&pEntry, LF_PATHSIZE, T("%s_%s"), basename, T("cgientry"));
	}
	entryAddr = 0;
	if (symFindByName(sysSymTbl, pEntry, &entryAddr, &ptype) == -1) {
		fmtAlloc(&pname, VALUE_MAX_STRING, T("_%s"), pEntry);
		symFindByName(sysSymTbl, pname, &entryAddr, &ptype);
		bfreeSafe(B_L, pname);
	}
	if (entryAddr != 0) {
		rc = taskSpawn(pEntry, priority, 0, 20000, (void *)vxWebsCgiEntry,
			(int)entryAddr, (int)argp, (int)envp, (int)stdIn, (int)stdOut,
			0, 0, 0, 0, 0);
		goto DONE;
	}

/*
 *  Try to load the module.
 */
	if ((fd = gopen(cgiPath, O_RDONLY | O_BINARY, 0666)) < 0 ||
		loadModule(fd, LOAD_GLOBAL_SYMBOLS) == NULL) {
		goto DONE;
	}
	if ((symFindByName(sysSymTbl, pEntry, &entryAddr, &ptype)) == -1) {
		fmtAlloc(&pname, VALUE_MAX_STRING, T("_%s"), pEntry);
		symFindByName(sysSymTbl, pname, &entryAddr, &ptype);
		bfreeSafe(B_L, pname);
	}
	if (entryAddr != 0) {
		rc = taskSpawn(pEntry, priority, 0, 20000, (void *)vxWebsCgiEntry,
			(int)entryAddr, (int)argp, (int)envp, (int)stdIn, (int)stdOut,
			0, 0, 0, 0, 0);
	}

DONE:
	if (fd != -1) {
		gclose(fd);
	}
	bfree(B_L, basename);
	bfree(B_L, pEntry);
	return rc;
}
Exemple #4
0
/*
 * main - parse arguments and handle options
 */
int
ntpdcmain(
	int argc,
	char *argv[]
	)
{
	extern int ntp_optind;

	delay_time.l_ui = 0;
	delay_time.l_uf = DEFDELAY;

#ifdef SYS_VXWORKS
	clear_globals();
	taskPrioritySet(taskIdSelf(), 100 );
#endif

	init_lib();	/* sets up ipv4_works, ipv6_works */
	ssl_applink();

	/* Check to see if we have IPv6. Otherwise default to IPv4 */
	if (!ipv6_works)
		ai_fam_default = AF_INET;

	progname = argv[0];

	{
		int optct = optionProcess(&ntpdcOptions, argc, argv);
		argc -= optct;
		argv += optct;
	}

	if (HAVE_OPT(IPV4))
		ai_fam_templ = AF_INET;
	else if (HAVE_OPT(IPV6))
		ai_fam_templ = AF_INET6;
	else
		ai_fam_templ = ai_fam_default;

	if (HAVE_OPT(COMMAND)) {
		int		cmdct = STACKCT_OPT( COMMAND );
		const char**	cmds  = STACKLST_OPT( COMMAND );

		while (cmdct-- > 0) {
			ADDCMD(*cmds++);
		}
	}

	debug = DESC(DEBUG_LEVEL).optOccCt;

	if (HAVE_OPT(INTERACTIVE)) {
		interactive = 1;
	}

	if (HAVE_OPT(NUMERIC)) {
		showhostnames = 0;
	}

	if (HAVE_OPT(LISTPEERS)) {
		ADDCMD("listpeers");
	}

	if (HAVE_OPT(PEERS)) {
		ADDCMD("peers");
	}

	if (HAVE_OPT(SHOWPEERS)) {
		ADDCMD("dmpeers");
	}

	if (ntp_optind == argc) {
		ADDHOST(DEFHOST);
	} else {
		for (; ntp_optind < argc; ntp_optind++)
		    ADDHOST(argv[ntp_optind]);
	}

	if (numcmds == 0 && interactive == 0
	    && isatty(fileno(stdin)) && isatty(fileno(stderr))) {
		interactive = 1;
	}

#if 0
	ai_fam_templ = ai_fam_default;
	while ((c = ntp_getopt(argc, argv, "46c:dilnps")) != EOF)
	    switch (c) {
		case '4':
		    ai_fam_templ = AF_INET;
		    break;
		case '6':
		    ai_fam_templ = AF_INET6;
		    break;
		case 'c':
		    ADDCMD(ntp_optarg);
		    break;
		case 'd':
		    ++debug;
		    break;
		case 'i':
		    interactive = 1;
		    break;
		case 'l':
		    ADDCMD("listpeers");
		    break;
		case 'n':
		    showhostnames = 0;
		    break;
		case 'p':
		    ADDCMD("peers");
		    break;
		case 's':
		    ADDCMD("dmpeers");
		    break;
		default:
		    errflg++;
		    break;
	    }

	if (errflg) {
		(void) fprintf(stderr,
			       "usage: %s [-46dilnps] [-c cmd] host ...\n",
			       progname);
		exit(2);
	}

	if (ntp_optind == argc) {
		ADDHOST(DEFHOST);
	} else {
		for (; ntp_optind < argc; ntp_optind++)
		    ADDHOST(argv[ntp_optind]);
	}

	if (numcmds == 0 && interactive == 0
	    && isatty(fileno(stdin)) && isatty(fileno(stderr))) {
		interactive = 1;
	}
#endif

#ifndef SYS_WINNT /* Under NT cannot handle SIGINT, WIN32 spawns a handler */
	if (interactive)
	    (void) signal_no_reset(SIGINT, abortcmd);
#endif /* SYS_WINNT */

	/*
	 * Initialize the packet data buffer
	 */
	pktdatasize = INITDATASIZE;
	pktdata = emalloc(INITDATASIZE);

	if (numcmds == 0) {
		(void) openhost(chosts[0]);
		getcmds();
	} else {
		int ihost;
		int icmd;

		for (ihost = 0; ihost < numhosts; ihost++) {
			if (openhost(chosts[ihost]))
			    for (icmd = 0; icmd < numcmds; icmd++) {
				    if (numhosts > 1) 
					printf ("--- %s ---\n",chosts[ihost]);
				    docmd(ccmds[icmd]);
			    }
		}
	}
#ifdef SYS_WINNT
	WSACleanup();
#endif
	return(0);
} /* main end */
Exemple #5
0
int setTaskID(TaskExecutor* te) {
    te->id = (void*)taskIdSelf();
}
static inline void regulator_pm_om_log(struct regulator *regulator, int opsid)
{
	struct regulator_pm_om_log regu_log = {(unsigned int)opsid, (unsigned int)regulator->id, (unsigned int)regulator->use_count, 0};
	regu_log.task_id = (unsigned int)taskIdSelf();
	bsp_pm_log_type(PM_OM_REGU, REGULATOR_TYPE, sizeof(struct regulator_pm_om_log), &regu_log);
}
Exemple #7
0
/* N.B.!! We do *not* execute in the context of the dying task here,
   but rather that of tExcTask - we do get a pointer to the task's
   TCB though - this pointer is in fact also the task's ID.     */
static void save_reclaim(WIND_TCB *tcbp)
{
  int i, var, oldfd;
  struct task_data *tdp;
  struct mall_data *mdp, *mdnextp;

  if ((var = taskVarGet((int)tcbp, (int *)&task_data)) != ERROR &&
      var != 0) {
    tdp = (struct task_data *)var;
    if (tdp->version == (FUNCPTR)save_reclaim) { /* Only handle our own */
#ifdef DEBUG
      fdprintf(2, "Reclaiming for task id 0x%x:\nFiles: ", (int)tcbp);
#endif
      /* Ugh! VxWorks doesn't even flush stdout/err - we need to
	 get at those (which are task-private of course, i.e. we
	 can't just do fflush(stdout) here) - we could be really
	 pedantic and try to redefine stdout/err (which "are"
	 function calls) too, snarfing the values when they are
	 used - but besides the overhead this is problematic since
	 they are actually #defines already... We'll peek in the
	 TCB instead (no documentation of course). And of course,
	 we must also meddle with the *file descriptor* indirections,
	 or we'll just flush out on tExcTask's descriptors...   */
      for (i = 1; i <= 2; i++) {
	if (tcbp->taskStdFp[i] != NULL) {
#ifdef DEBUG
	  fdprintf(2, "fflush(%s) ", i == 1 ? "stdout" : "stderr");
#endif
	  oldfd = ioTaskStdGet(0, i);
	  ioTaskStdSet(0, i, tcbp->taskStd[i]);
	  fflush(tcbp->taskStdFp[i]);
	  ioTaskStdSet(0, i, oldfd);
	}
      }
      for (i = 3; i < tdp->max_files; i++) {
	if (FD_ISSET(i, &tdp->open_fds)) {
#ifdef DEBUG
	  fdprintf(2, "close(%d) ", i);
#endif
	  (void) close(i);
	}
	if (tdp->open_fps[i] != NULL) {
#ifdef DEBUG
	  fdprintf(2, "fclose(%0x%x) ", (int)tdp->open_fps[i]);
#endif
	  (void) fclose(tdp->open_fps[i]);
	}
      }
      i = 0;
      mdp = tdp->mall_data;
      while (mdp != NULL) {
	mdnextp = mdp->next;
	if(reclaim_free_function != NULL)
	    (*reclaim_free_function)(mdp->self);
	else
	    free(mdp->self);
	i++;
	mdp = mdnextp;
      }
#ifdef DEBUG
      fdprintf(2, "\nFreeing memory: total %d mallocs\n", i);
#endif
      
      if (tdp->delete_hook != NULL) {
#ifdef DEBUG
	  fdprintf(2, "Calling delete hook at 0x%08x\n", tdp->delete_hook);
#endif
	  (*tdp->delete_hook)(tdp->hook_data);
#ifdef DEBUG
	  fdprintf(2, "Called delete hook at 0x%08x\n", tdp->delete_hook);
#endif
      }
#ifdef DEBUG
      fdprintf(2, "Freeing own mem at 0x%08x\n", tdp);
#endif
      (void) free((char *)tdp);
#ifdef DEBUG
      fdprintf(2, "Freed own mem at 0x%08x, done (0x%08x)\n**********\n", tdp,
	       taskIdSelf());
      checkStack(0);
#endif
    }
  }
#ifdef DEBUG
  else
    fdprintf(2, "No task data found for id 0x%x, var = %d\n", (int)tcbp, var);
#endif
}
Exemple #8
0
ThreadImpl::TIDImpl ThreadImpl::currentTidImpl()
{
    return taskIdSelf();
}
Exemple #9
0
static void rootTask(long a0, long a1, long a2, long a3, long a4,
		     long a5, long a6, long a7, long a8, long a9)
{
	int ret;

	traceobj_enter(&trobj);

	traceobj_mark(&trobj, 6);

	ret = taskPrioritySet(taskIdSelf(), 11);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 7);

	sem_id = semMCreate(0xffffffff);
	traceobj_assert(&trobj, sem_id == 0 && errno == S_semLib_INVALID_OPTION);

	traceobj_mark(&trobj, 8);

	sem_id = semMCreate(SEM_Q_PRIORITY|SEM_DELETE_SAFE|SEM_INVERSION_SAFE);
	traceobj_assert(&trobj, sem_id != 0);

	traceobj_mark(&trobj, 9);

	ret = semTake(sem_id, WAIT_FOREVER);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 10);

	ret = semTake(sem_id, WAIT_FOREVER);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 11);

	ret = semGive(sem_id);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 12);

	ret = semGive(sem_id);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 13);

	ret = semGive(sem_id);
	traceobj_assert(&trobj, ret == ERROR && errno == S_semLib_INVALID_OPERATION);

	traceobj_mark(&trobj, 14);

	ret = semTake(sem_id, WAIT_FOREVER);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 15);

	ret = taskSuspend(taskIdSelf());
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 16);

	ret = semGive(sem_id);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 17);

	traceobj_exit(&trobj);
}