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 }
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; }
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; }
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; }
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; }
static int _strace_parent(pid_t pid) { int status; for(;;) { waitpid(pid, &status, 0); if(_handle(pid, status) != 0) return 0; } }
void mirco_active::run(){ event_handle _handle; while(1){ if (event_que.pop(_handle)){ _handle(); }else{ break; } } }
bool mirco_active::do_one(){ event_handle _handle; if (!event_que.pop(_handle)){ return false; } _handle(); return true; }
/* 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; }
bool FmMsg::insert(FmMsgEntry * src) { if (_cnt == _max) { _handle(src); return false; } while(!lock_data()); _buf.push(*src); unlock_data(); ++_cnt; return true; }
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; }
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; }
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; }