当前位置: 首页>>代码示例>>C++>>正文


C++ posix_error函数代码示例

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


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

示例1: set_thread_affinity

void set_thread_affinity(int cpu_number)
{
	int ret = 0;
	cpu_set_t mask;
	CPU_ZERO(&mask);
	CPU_SET(cpu_number%cpu_online, &mask);
	if ((ret = pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask)) != 0)
	{
		posix_error(ret, "set thread affinity failed");
	}
}
开发者ID:Jingtian1989,项目名称:matrix,代码行数:11,代码来源:matrix.c

示例2: _uptime_secs

static PyObject *
_uptime_secs(PyObject *self, PyObject *args)
{
    int iRslt = -1;
    double cur_uptime = 0.0;
    struct sysinfo si;

	// Make sure that no arguments were specified
    if(!PyArg_ParseTuple(args, ":secs"))
        return NULL;
    errno = 0;
    iRslt = sysinfo(&si);
    if(iRslt < 0)
        return posix_error();
    cur_uptime = (double)(si.uptime);

#ifdef DEBUG
	// If we are in debug mode, check to see if the uptime has
	// been overriden.
    if (override_secs != 0.0)
 	    cur_uptime = override_secs;
#endif

	// Now check for a wrap.
	if (cur_uptime < (last_uptime - 1.0)) {
#ifdef VERBOSE
 	        printf("Detected a wrap! (%lf and %lf).\n", cur_uptime, last_uptime);
#endif
	        // OK, we've got a wrap.
     	        if (last_uptime > max_uptime) {
		      max_uptime = last_uptime;
#ifdef VERBOSE
		      printf("max_uptime is now set to %lf.\n", max_uptime);
#endif
		}
		uptime_offset += (unsigned long) max_uptime;
#ifdef VERBOSE
		printf("uptime_offset is now %ld.\n", uptime_offset);
#endif
	}
	
	last_uptime = cur_uptime;
   
	// If we've had a wrap, add the uptime_offset to the current uptime
	if (uptime_offset != 0) {
   	        cur_uptime += (double) uptime_offset;
	}
#ifdef EXTRA_VERBOSE
	printf("uptime_secs: Returning %lf.\n", cur_uptime);
#endif
        return Py_BuildValue("d", cur_uptime);
}
开发者ID:mcruse,项目名称:monotone,代码行数:52,代码来源:_uptime.c

示例3: subterfugue_atcallstop

static PyObject *
subterfugue_atcallstop(PyObject *self, PyObject *args)
{
  int pid, stopsig, result;

  if (!PyArg_Parse(args, "(ii)", &pid, &stopsig))
    return NULL;

  result = atcallstop(pid, stopsig);
  if (result == -1)
    return posix_error();
  return Py_BuildValue("i", result);
}
开发者ID:pombredanne,项目名称:subterfugue,代码行数:13,代码来源:_subterfuguemodule.c

示例4: _uptime_raw_secs

static PyObject *
_uptime_raw_secs(PyObject *self, PyObject *args)
{
    int iRslt = -1;
    double cur_uptime = 0.0;
    struct sysinfo si;
    // Make sure that no arguments were specified:
    if (!PyArg_ParseTuple(args, ":secs"))
        return NULL;
    errno = 0;
    iRslt = sysinfo(&si);
    if(iRslt < 0)
        return posix_error();
    cur_uptime = (double)(si.uptime);
    return Py_BuildValue("d", cur_uptime);
}
开发者ID:mcruse,项目名称:monotone,代码行数:16,代码来源:_uptime.c

示例5: Pthread_mutex_init

void Pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *attr) {
	int rc;

	if ((rc = pthread_mutex_init(mutex, attr)) != 0)
		posix_error(rc, "Pthread_mutex_init error");
}
开发者ID:ZxMYS,项目名称:Xiaos-IPv4-IPv6-Transmit-Toolkit,代码行数:6,代码来源:csapp.c

示例6: Pthread_mutex_unlock

void Pthread_mutex_unlock(pthread_mutex_t *mutex) {
	int rc;

	if ((rc = pthread_mutex_unlock(mutex)) != 0)
		posix_error(rc, "Pthread_mutex_unlock error");
}
开发者ID:ZxMYS,项目名称:Xiaos-IPv4-IPv6-Transmit-Toolkit,代码行数:6,代码来源:csapp.c

示例7: Pthread_join

void Pthread_join(pthread_t tid, void **thread_return) {
	int rc;

	if ((rc = pthread_join(tid, thread_return)) != 0)
		posix_error(rc, "Pthread_join error");
}
开发者ID:ZxMYS,项目名称:Xiaos-IPv4-IPv6-Transmit-Toolkit,代码行数:6,代码来源:csapp.c

示例8: Pthread_detach

/* $begin detach */
void Pthread_detach(pthread_t tid) {
	int rc;

	if ((rc = pthread_detach(tid)) != 0)
		posix_error(rc, "Pthread_detach error");
}
开发者ID:ZxMYS,项目名称:Xiaos-IPv4-IPv6-Transmit-Toolkit,代码行数:7,代码来源:csapp.c

示例9: Pthread_detach

void Pthread_detach(pthread_t tid)
{
	int rt = pthread_detach(tid);
	if( rt != 0)
		posix_error(rt, "pthread_detach error");
}
开发者ID:jack-lijing,项目名称:unix,代码行数:6,代码来源:csapp.c

示例10: Pthread_cancel

void Pthread_cancel(pthread_t tid) {
	int rc;

	if ((rc = pthread_cancel(tid)) != 0)
		posix_error(rc, "Pthread_cancel error");
}
开发者ID:ZxMYS,项目名称:Xiaos-IPv4-IPv6-Transmit-Toolkit,代码行数:6,代码来源:csapp.c

示例11: main

int main(int argc, char *argv[])
{
	struct thread_data *threads;
	struct thread_data *thread;
	int i, ret, ch;

	if (argc > 1)
	{
		if (strcmp(argv[1], "--help") == 0)
		{
			usage_error(argv[0]);
		}
		init_program_parameter(argc, argv);
	}

	program_parameter(argv[0]);

	create_matrix(&matrix_a);
	create_matrix(&matrix_b);
	create_matrix(&matrix_c);
	create_matrix(&matrix_d);
	random_matrix(matrix_a);
	random_matrix(matrix_b);

	nonmal_matrix_multipy(matrix_a, matrix_b, matrix_d);

	threads = (struct thread_data *)malloc(pthread_max * sizeof(struct thread_data));
	if (threads == NULL)
	{
		unix_error("malloc threads failed");
	}

	cpu_online = sysconf(_SC_NPROCESSORS_CONF);

	for(i = 0; i < pthread_max; i++)
	{
		thread = threads + i;
		thread->index = i;
		if ((ret = pthread_create(&thread->thread_id, NULL, thread_func, thread)) != 0)
		{
			posix_error(ret, "pthread_create failed");
		}
	}

	for(i = 0; i < pthread_max; i++)
	{
		thread = threads + i;
		if ((ret = pthread_join(thread->thread_id, NULL)) != 0)
		{
			posix_error(ret, "pthread_join failed");
		}
	}

	if (matrix_equal(matrix_c, matrix_d) == 0)
	{
		unix_error("runtime error");
	}
	if (dump)
	{
		dump_matrix("matrix A", matrix_a);
		dump_matrix("matrix B", matrix_b);
		dump_matrix("matrix C", matrix_c);
		dump_matrix("matrix D", matrix_d);
	}
	statistics(threads);

	free_matrix(matrix_a);
	free_matrix(matrix_b);
	free_matrix(matrix_c);
	free_matrix(matrix_d);
	free(threads);
	return 0;
}
开发者ID:Jingtian1989,项目名称:matrix,代码行数:73,代码来源:matrix.c

示例12: Pthread_cond_destroy

void Pthread_cond_destroy(pthread_cond_t *cond) {
	int rc;

	if ((rc = pthread_cond_destroy(cond)) != 0)
		posix_error(rc, "Pthread_cond_destroy");
}
开发者ID:PajamaCat,项目名称:proxy,代码行数:6,代码来源:csapp.c

示例13: mem

bool MemFile::open (const std::string &path_, bool uncompress)
{
	MEMORY mem(MAX_IMAGE_SIZE + 1);
	size_t uRead = 0;

	// Check if zlib is available
#ifdef HAVE_ZLIBSTAT
	bool have_zlib = true;
#elif defined(HAVE_ZLIB)
	bool have_zlib = CheckLibrary("zlib", "zlibVersion") && zlibVersion()[0] == ZLIB_VERSION[0];
#else
	bool have_zlib = false;
#endif

#ifdef HAVE_ZLIB
	// Try opening as a zip file
	if (uncompress && have_zlib)
	{
		unzFile hfZip = unzOpen(path_.c_str());
		if (hfZip)
		{
			int nRet;
			unz_file_info sInfo;
			uLong ulMaxSize = 0;

			// Iterate through the contents of the zip looking for a file with a suitable size
			for (nRet = unzGoToFirstFile(hfZip); nRet == UNZ_OK; nRet = unzGoToNextFile(hfZip))
			{
				char szFile[MAX_PATH];

				// Get details of the current file
				unzGetCurrentFileInfo(hfZip, &sInfo, szFile, MAX_PATH, nullptr, 0, nullptr, 0);

				// Ignore directories and empty files
				if (!sInfo.uncompressed_size)
					continue;

				// If the file extension is recognised, read the file contents
				// ToDo: GetFileType doesn't really belong here?
				if (GetFileType(szFile) != ftUnknown && unzOpenCurrentFile(hfZip) == UNZ_OK)
				{
					nRet = unzReadCurrentFile(hfZip, mem, static_cast<unsigned int>(mem.size));
					unzCloseCurrentFile(hfZip);
					break;
				}

				// Rememeber the largest uncompressed file size
				if (sInfo.uncompressed_size > ulMaxSize)
					ulMaxSize = sInfo.uncompressed_size;
			}

			// Did we fail to find a matching extension?
			if (nRet == UNZ_END_OF_LIST_OF_FILE)
			{
				// Loop back over the archive
				for (nRet = unzGoToFirstFile(hfZip); nRet == UNZ_OK; nRet = unzGoToNextFile(hfZip))
				{
					// Get details of the current file
					unzGetCurrentFileInfo(hfZip, &sInfo, nullptr, 0, nullptr, 0, nullptr, 0);

					// Open the largest file found about
					if (sInfo.uncompressed_size == ulMaxSize && unzOpenCurrentFile(hfZip) == UNZ_OK)
					{
						nRet = unzReadCurrentFile(hfZip, mem, static_cast<unsigned int>(mem.size));
						unzCloseCurrentFile(hfZip);
						break;
					}
				}
			}

			// Close the zip archive
			unzClose(hfZip);

			// Stop if something went wrong
			if (nRet < 0)
				throw util::exception("zip extraction failed (", nRet, ")");

			uRead = nRet;
			m_compress = Compress::Zip;
		}
		else
		{
			// Open as gzipped or uncompressed
			gzFile gf = gzopen(path_.c_str(), "rb");
			if (gf == Z_NULL)
				throw posix_error(errno, path_.c_str());

			uRead = gzread(gf, mem, static_cast<unsigned>(mem.size));
			m_compress = (gztell(gf) != FileSize(path_)) ? Compress::Gzip : Compress::None;
			gzclose(gf);
		}
	}
	else
#endif // HAVE_ZLIB
	{
		// Open as normal file if we couldn't use zlib above
		FILE *f = fopen(path_.c_str(), "rb");
		if (!f)
			throw posix_error(errno, path_.c_str());

//.........这里部分代码省略.........
开发者ID:d235j,项目名称:samdisk,代码行数:101,代码来源:MemFile.cpp

示例14: Pthread_cond_broadcast

void Pthread_cond_broadcast(pthread_cond_t *cond) {
	int rc;

	if ((rc = pthread_cond_broadcast(cond)) != 0)
		posix_error(rc, "Pthread_cond_broadcast error");
}
开发者ID:ZxMYS,项目名称:Xiaos-IPv4-IPv6-Transmit-Toolkit,代码行数:6,代码来源:csapp.c

示例15: subterfugue_mainloop

static PyObject *
subterfugue_mainloop(PyObject *self, PyObject *args)
{
  int pid, wpid, status, scno, eax, waitchannelhack;
  int beforecall = -1;

  if (!PyArg_Parse(args, "(ii)", &pid, &waitchannelhack))
    return NULL;

  numtraced++;

  while (1) {
    int result;

#ifndef __WALL
#define __WALL 0x40000000
#endif
    wpid = wait4(-1, &status, WUNTRACED | __WALL, NULL);
    if (wpid == -1)
      return posix_error();

    DBG("Checking pids: %d, %d\n", pid, wpid);
    if (pid != wpid)		/* XXX: could maybe be handled w/o giving up */
      goto giveup;
    DBG("This looks good\n");
    if (!WIFSTOPPED(status)) 
      goto giveup;
    DBG("checking SIGTRAP\n");
    if (!waitchannelhack) {
      if (WSTOPSIG(status) != (SIGTRAP | 0x80))
	goto giveup;
    } else {
      int r = atcallstop(pid, WSTOPSIG(status));
      if (r == -1)
	return posix_error();	/* shouldn't happen, but tell the caller */
      if (!r)
	goto giveup;
    }
      
    /* Only check the system call number on the before stop, because some
       calls (e.g., sigreturn) stomp that number.  On the after stop, by the
       time we get here it "must" be okay to ignore this stop.  (Skipping
       these checks also speeds things up a bit.)
    */
    if (beforecall) {
      DBG("getting scno\n");
      scno = ptrace(PTRACE_PEEKUSER, wpid, 4*ORIG_EAX, PTRACE_ARGTYPE &scno);
      DBG("scno is %d (%m)\n", scno);
      if (scno < 0 || scno >= MAXCALLNUMBER)
	goto giveup;

      DBG("looking if call_ignored\n");
      if (!call_ignored[scno])
	goto giveup;

      eax = ptrace(PTRACE_PEEKUSER, wpid, 4*EAX, 0);
      if ((eax != -ENOSYS) /* && beforecall */)
	goto giveup;
    }

    DBG("ok, this call is ignored here\n" );
    beforecall = !beforecall;

    result = ptrace(PTRACE_SYSCALL, pid, 0, 0);
    if (result == -1)
      return posix_error();	/* shouldn't happen, but tell the caller */
      
    numignored++;
    if (!(numignored % 1000))
      DBG("numignored = %d, numtraced = %d\n", numignored, numtraced);
  }

giveup:  
  /* if beforecall is nonzero, change 'insyscall' status of _pid_ to that returned */

  //  fprintf( stderr, "Returning %d, %d, %d\n", wpid, status, beforecall );
  return Py_BuildValue("(iii)", wpid, status, beforecall);
}
开发者ID:pombredanne,项目名称:subterfugue,代码行数:78,代码来源:_subterfuguemodule.c


注:本文中的posix_error函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。