コード例 #1
0
ファイル: StorageSharing.cpp プロジェクト: RichieMay/pytorch
static PyObject * THPStorage_(shareCuda)(THPStorage *self)
{
  HANDLE_TH_ERRORS
  THStorage *storage = self->cdata;
  AutoGPU gpu_guard(storage->device);
  THPObjectPtr tuple(PyTuple_New(5));
  THPObjectPtr device(PyLong_FromLong(storage->device));
  THPObjectPtr _handle(Py_None);
  Py_INCREF(Py_None);
  THPObjectPtr size(PyLong_FromLong(storage->size));
  THPObjectPtr _offset(PyLong_FromLong(0));
  THPObjectPtr view_size(PyLong_FromLong(storage->size));
  if (storage->data) {
    size_t base_size;
    void *base_ptr = THCCachingAllocator_getBaseAllocation(storage->data, &base_size);
    ptrdiff_t offset = (char*)storage->data - (char*)base_ptr;

    cudaIpcMemHandle_t handle;
    THCudaCheck(cudaIpcGetMemHandle(&handle, base_ptr));

    _handle = PyBytes_FromStringAndSize((char *)&handle, CUDA_IPC_HANDLE_SIZE);
    _offset = PyLong_FromSsize_t((Py_ssize_t)offset);
    size = PyLong_FromSize_t(base_size / sizeof(real));
  }
  if (!tuple || !device || !_handle || !size || !_offset || !view_size) {
    return NULL;
  }
  PyTuple_SET_ITEM(tuple.get(), 0, device.release());
  PyTuple_SET_ITEM(tuple.get(), 1, _handle.release());
  PyTuple_SET_ITEM(tuple.get(), 2, size.release());
  PyTuple_SET_ITEM(tuple.get(), 3, _offset.release());
  PyTuple_SET_ITEM(tuple.get(), 4, view_size.release());
  return tuple.release();
  END_HANDLE_TH_ERRORS
}
コード例 #2
0
ファイル: dh__list_int32_t.cpp プロジェクト: trafi/djinni
djinni::Handle<DjinniObjectHandle> DjinniListInt32T::fromCpp(const std::vector<int32_t> & dc) {
    djinni::Handle<DjinniObjectHandle> _handle(s_py_callback_list_int32_t__python_create(), & list_int32_t___delete);
    size_t size = dc.size();
    for (int i = 0; i < size; i++) {
        s_py_callback_list_int32_t__python_add(_handle.get(), dc[i]);
    }

    return _handle;
}
コード例 #3
0
ファイル: dh__set_string.cpp プロジェクト: trafi/djinni
djinni::Handle<DjinniObjectHandle> DjinniSetString::fromCpp(const std::unordered_set<std::string> & dc) {
    djinni::Handle<DjinniObjectHandle> _handle(s_py_callback_set_string__python_create(), & set_string___delete);
    for (const auto & it : dc) {
        auto _key_val = DjinniString::fromCpp(it);
        s_py_callback_set_string__python_add(_handle.get(), _key_val.release());
    }

    return _handle;
}
コード例 #4
0
djinni::Handle<DjinniObjectHandle> DjinniMapInt8TSetString::fromCpp(const std::unordered_map<int8_t, std::unordered_set<std::string>> & dc) {
    djinni::Handle<DjinniObjectHandle> _handle(s_py_callback_map_int8_t_set_string__python_create(), & map_int8_t_set_string___delete);
    for (const auto & it : dc) {
        auto _val = DjinniSetString::fromCpp(it.second);
        s_py_callback_map_int8_t_set_string__python_add(_handle.get(), it.first, _val.release());
    }

    return _handle;
}
コード例 #5
0
djinni::Handle<DjinniObjectHandle> DjinniListMapStringInt64T::fromCpp(const std::vector<std::unordered_map<std::string, int64_t>> & dc) {
    djinni::Handle<DjinniObjectHandle> _handle(s_py_callback_list_map_string_int64_t__python_create(), & list_map_string_int64_t___delete);
    size_t size = dc.size();
    for (int i = 0; i < size; i++) {
        auto _el = DjinniMapStringInt64T::fromCpp(dc[i]);
        s_py_callback_list_map_string_int64_t__python_add(_handle.get(), _el.release());
    }

    return _handle;
}
コード例 #6
0
ファイル: strace.c プロジェクト: khorben/DeforaOS
static int _strace_parent(pid_t pid)
{
	int status;

	for(;;)
	{
		waitpid(pid, &status, 0);
		if(_handle(pid, status) != 0)
			return 0;
	}
}
コード例 #7
0
ファイル: mirco_active.cpp プロジェクト: vipyami/angelica
void mirco_active::run(){
	event_handle _handle;

	while(1){
		if (event_que.pop(_handle)){
			_handle();
		}else{
			break;
		}
	}
}
コード例 #8
0
ファイル: mirco_active.cpp プロジェクト: vipyami/angelica
bool mirco_active::do_one(){
	event_handle _handle;

	if (!event_que.pop(_handle)){
		return false;
	}

	_handle();

	return true;
}
コード例 #9
0
ファイル: event.c プロジェクト: comick/finalcm
/* This implements something like an Xlib.
 * do{
 *   threat_event(e);
 * } while (!Qlength);
 * It is a good way to optimize compositing performance.
 */
static int _handle_until_empty_queue(void *data, xcb_connection_t *conn, xcb_generic_event_t *e) {
    do {
        _handle(e);
        e = xcb_poll_for_event(gd.conn);
    } while (e != NULL);
    /* To be something hookable.. */
    fwm_composite_finalize();
    /* stop */
    xcb_flush(gd.conn);
    return 1;
}
コード例 #10
0
ファイル: FmMsg.cpp プロジェクト: Null-Pointer-Software/FmMsg
bool FmMsg::insert(FmMsgEntry * src) {
	if (_cnt == _max) {
		_handle(src);
		return false;
	}

	while(!lock_data());
	_buf.push(*src);
	unlock_data();

	++_cnt;

	return true;
}
コード例 #11
0
ファイル: FmMsg.cpp プロジェクト: Null-Pointer-Software/FmMsg
bool FmMsg::insert(int size, void * content, FmMsgEntry_type type) {
	FmMsgEntry dst(size, type);
	dst.populate(content, size, type);

	if (_cnt == _max) {
		_handle(&dst);
		return false;
	}

	while (!lock_data()); // wait for the lock.
	_buf.push(dst);
	unlock_data();

	++_cnt;

	return true;
}
コード例 #12
0
ファイル: FmMsg.cpp プロジェクト: Null-Pointer-Software/FmMsg
bool FmMsg::insert(FmMsgQ_entry * src) {
	if (!strcmp(_name, src->dst)) {
		FmMsgEntry dst(*(src->data), OWNERSHIP);

		if (_cnt == _max) {
			_handle(src->data);
			return false;
		}

		while (!lock_data()); // wait for the lock.
		_buf.push(dst);
		unlock_data();

		++_cnt;

		_flag = true;
	} else {
		_flag = false;
	}

	return _flag;
}
コード例 #13
0
ファイル: pluginscan.cpp プロジェクト: blue-shell/folderview
static int tryCheck(int write_fd, const QString &absFile)
{
    KLibrary _handle(absFile);
    if (!_handle.load()) {
        kDebug(1433) << " - open failed with message " <<
		         _handle.errorString() << ", skipping " << endl;
        return 1;
    }

    // ask for name and description
    QString name = i18n("Unnamed plugin");
    QString description;

    NPError (*func_GetValue)(void *, NPPVariable, void *) =
        (NPError(*)(void *, NPPVariable, void *))
        _handle.resolveFunction("NP_GetValue");
    if ( func_GetValue ) {

        // get name
        char *buf = 0;
        NPError err = func_GetValue( 0, NPPVpluginNameString,
                                     (void*)&buf );
        if ( err==NPERR_NO_ERROR )
            name = QString::fromLatin1( buf );
        kDebug() << "name = " << name;

        // get name
        NPError nperr = func_GetValue( 0, NPPVpluginDescriptionString,
                                     (void*)&buf );
        if ( nperr==NPERR_NO_ERROR )
            description = QString::fromLatin1( buf );
        kDebug() << "description = " << description;
    }
    else
        kWarning() << "Plugin doesn't implement NP_GetValue"  ;

    // get mime description function pointer
    char* (*func_GetMIMEDescription)() =
        (char *(*)())_handle.resolveFunction("NP_GetMIMEDescription");
    if ( !func_GetMIMEDescription ) {
        kDebug(1433) << " - no GetMIMEDescription, skipping";
        _handle.unload();
        return 1;
    }

    // ask for mime information
    QString mimeInfo = func_GetMIMEDescription();
    if ( mimeInfo.isEmpty() ) {
        kDebug(1433) << " - no mime info returned, skipping";
        _handle.unload();
        return 1;
    }

    // remove version info, as it is not used at the moment
    QRegExp versionRegExp(";version=[^:]*:");
    mimeInfo.replace( versionRegExp, ":");
    if (!mimeInfo.isEmpty() && !mimeInfo.endsWith(';')) {
        mimeInfo += ';'; // XDG compliance
    }

    // unload plugin lib
    kDebug(1433) << " - unloading plugin";
    _handle.unload();

    // create a QDataStream for our IPC pipe (to send plugin info back to the parent)
    QFile stream_file;
    stream_file.open(write_fd, QIODevice::WriteOnly);
    QDataStream stream(&stream_file);

    // return the gathered info to the parent
    stream << name;
    stream << description;
    stream << mimeInfo;

    return 0;
}