void DistributedLock::do_open() { /* If there is no persistence, then there is no contention for distributed locks and we can just return immediately. */ if (!object_.get_persistence_enabled()) return; #ifdef P4P_CLUSTER std::string lockfile = object_.get_file().string() + ".lock"; /* open the file */ fd_ = open(lockfile.c_str(), get_open_flags(), 0600); if (fd_ < 0) throw bfs::filesystem_error("open failed", lockfile, bs::error_code(errno, boost::system::posix_category)); /* acquire the lock */ struct flock lock; memset(&lock, 0, sizeof(lock)); lock.l_type = get_lock_type(); lock.l_whence = SEEK_SET; if (fcntl(fd_, F_SETLKW, &lock) < 0) throw bfs::filesystem_error("lock failed", lockfile, bs::error_code(errno, boost::system::posix_category)); /* ensure the local object is up to date */ try { UpgradableReadLock local_lock(object_); object_.update(*this, local_lock); } catch (distributed_object_error& e) { /* ignore exceptions */ } #else throw std::runtime_error("Persistence support not enabled"); #endif }
void render::VCWnd::LocalFrameRenderer() { VideoRenderer* local_renderer = UI_->local_renderer_.get(); if (local_renderer) { AutoLock<VideoRenderer> local_lock(local_renderer); const BITMAPINFO& bmi = local_renderer->bmi(); int height = abs(bmi.bmiHeader.biHeight); int width = bmi.bmiHeader.biWidth; const uint8* image = local_renderer->image(); if (image != NULL) { QImage *local_video = new QImage(image, bmi.bmiHeader.biWidth, abs(bmi.bmiHeader.biHeight), QImage::Format_RGB32); QPainter painter(this); QRect rect = this->rect(); painter.drawImage(rect, *local_video); } else { QImage img(600, 400, QImage::Format_RGB32); img.fill(QColor(0, 0, 0, 255)); QPainter painter(this); painter.drawImage(this->rect(), img); } } }
int hieth_mdio_read(struct hieth_mdio_local *ld, int phy_addr, int regnum) { int val = 0; hieth_assert((!(phy_addr & (~0x1F))) && (!(regnum & (~0x1F)))); local_lock(ld); if (!wait_mdio_ready(ld)) { hieth_error("mdio busy"); goto error_exit; } mdio_start_phyread(ld, phy_addr, regnum); if (wait_mdio_ready(ld)) val = mdio_get_phyread_val(ld); else hieth_error("read timeout"); error_exit: local_unlock(ld); hieth_trace(4, "phy_addr = %d, regnum = %d, val = 0x%04x", phy_addr, regnum, val); return val; }
void condition_variable::wait( boost::unique_lock< mutex >& lock ) { assert( lock.owns_lock( ) ); boost::unique_lock< mutex > local_lock( *lock.release( ), boost::adopt_lock ); better_lock lock_std( mt ); global_thr_pool.yield( [&]( coroutine running ) { lock_unlocker< better_lock > l_unlock_std_mt( lock_std ); lock_unlocker< boost::unique_lock< mutex > > l_unlock_co_mt( local_lock ); waiting_cors.emplace_back( std::move( running ) ); } ); // If this coroutine is resumed by a thread different from the one that // yielded, // then it is possible that the changes to internal state of the 'lock' // variable will // not have been yet acknowledged by the resuming thread. // This special case will lead to a difficult to debug race condition // involving // the owns_lock member variable. // This is why we use local_lock. assert( !local_lock.owns_lock( ) ); lock = boost::unique_lock< mutex >( *local_lock.release( ) ); }
int hieth_mdio_write( struct hieth_mdio_local *ld, int phy_addr, int regnum, int val) { int ret = 0; hieth_assert((!(phy_addr & (~0x1F))) && (!(regnum & (~0x1F)))); hieth_trace(4, "phy_addr = %d, regnum = %d", phy_addr, regnum); local_lock(ld); if (!wait_mdio_ready(ld)) { hieth_error("mdio busy"); ret = -1; goto error_exit; } mdio_phywrite(ld, phy_addr, regnum, val); error_exit: local_unlock(ld); return val; }
static int hieth_net_set_mac_address(struct net_device *dev, void *p) { struct hieth_netdev_local *ld = netdev_priv(dev); struct sockaddr *skaddr = p; if (netif_running(dev)) return -EBUSY; if (!is_valid_ether_addr(skaddr->sa_data)) return -EADDRNOTAVAIL; local_lock(ld); if (hieth_devs_save[UP_PORT]) memcpy(hieth_devs_save[UP_PORT]->dev_addr, skaddr->sa_data, dev->addr_len); if (hieth_devs_save[DOWN_PORT]) memcpy(hieth_devs_save[DOWN_PORT]->dev_addr, skaddr->sa_data, dev->addr_len); local_unlock(ld); hieth_hw_set_macaddress(ld, 1, dev->dev_addr); return 0; }
void DistributedObject::after_construct() { #ifdef P4P_CLUSTER if (persistence_enabled_ && !file_.string().empty()) { /* * Initialize from file if one was specified */ try { DistributedReadLock dist_lock(*this); UpgradableReadLock local_lock(*this); if (!update(dist_lock, local_lock)) init_default(); } catch (distributed_object_error& e) { init_default(); } /* FIXME: Temporarily disabled */ /* DistributedObjectWatcher::Instance().add_object(this); */ } else #endif { init_default(); } }
int hieth_get_linkstat(struct hieth_netdev_local *ld) { unsigned long old; local_lock(ld); old = hieth_readl_bits(ld, UD_REG_NAME(MAC_RO_STAT), BITS_MACSTAT); local_unlock(ld); return old; }
int hieth_set_linkstat(struct hieth_netdev_local *ld, int mode) { unsigned long old; local_lock(ld); old = _set_linkstat(ld, mode); local_unlock(ld); return old; }
int hieth_get_negmode(struct hieth_netdev_local *ld) { int old; local_lock(ld); old = _get_negmode(ld); local_unlock(ld); return old; }
int hieth_set_negmode(struct hieth_netdev_local *ld, int mode) { int old; local_lock(ld); old = _set_negmode(ld, mode); local_unlock(ld); return old; }
void SystemCallApplication::__callMain(SystemCallApplication* app) { app->registerApplication(); std::unique_lock<std::mutex> local_lock(app->initial_barrier_mutex); app->initial_barrier_cond.notify_all(); local_lock.unlock(); local_lock.release(); app->E_Main(); app->unregisterApplication(); }
int hieth_irq_disable(struct hieth_netdev_local *ld, int irqs) { int old; local_lock(ld); old = _hieth_irq_disable(ld, irqs); local_unlock(ld); return old; }
int hieth_read_raw_irqstatus(struct hieth_netdev_local *ld) { int status; local_lock(ld); status = hieth_readl(ld, GLB_RO_IRQ_STAT); local_unlock(ld); return status; }
int hieth_read_irqstatus(struct hieth_netdev_local *ld) { int status; local_lock(ld); status = _hieth_read_irqstatus(ld); local_unlock(ld); return status; }
int hieth_set_mac_fc_interval(struct hieth_netdev_local *ld, int para) { int old; local_lock(ld); old = hieth_readl_bits(ld, UD_REG_NAME(MAC_TX_IPGCTRL), BITS_FC_INTER); hieth_writel_bits(ld, para, UD_REG_NAME(MAC_TX_IPGCTRL), BITS_FC_INTER); local_unlock(ld); return old; }
shared_ptr<void> get_blocker() { unique_lock<connection_body_base> local_lock(*this); shared_ptr<void> blocker = _weak_blocker.lock(); if(blocker == shared_ptr<void>()) { blocker.reset(this, &null_deleter); _weak_blocker = blocker; } return blocker; }
int hieth_set_mii_mode(struct hieth_netdev_local *ld, int mode) { int old; local_lock(ld); old = hieth_readl_bits(ld, UD_REG_NAME(MAC_PORTSEL), BITS_MII_MODE); hieth_writel_bits(ld, mode, UD_REG_NAME(MAC_PORTSEL), BITS_MII_MODE); local_unlock(ld); return old; }
int hieth_clear_irqstatus(struct hieth_netdev_local *ld, int irqs) { int status; local_lock(ld); hieth_writel(ld, irqs, GLB_RW_IRQ_RAW); status = _hieth_read_irqstatus(ld); local_unlock(ld); return status; }
int hieth_set_endian_mode(struct hieth_netdev_local *ld, int mode) { int old; local_lock(ld); old = hieth_readl_bits(ld, GLB_ENDIAN_MOD, BITS_ENDIAN); hieth_writel_bits(ld, mode, GLB_ENDIAN_MOD, BITS_ENDIAN); local_unlock(ld); return old; }
PHPAPI char *php_asctime_r(const struct tm *tm, char *buf) { char *tmp; local_lock(ASCTIME_R); tmp = asctime(tm); strcpy(buf, tmp); local_unlock(ASCTIME_R); return buf; }
PHPAPI char *php_ctime_r(const time_t *clock, char *buf) { char *tmp; local_lock(CTIME_R); tmp = ctime(clock); strcpy(buf, tmp); local_unlock(CTIME_R); return buf; }
int hieth_set_mac_leadcode_cnt_limit(struct hieth_netdev_local *ld, int cnt) { int old; local_lock(ld); old = hieth_readl_bits(ld, UD_REG_NAME(MAC_TX_IPGCTRL), BITS_PRE_CNT_LIMIT); hieth_writel_bits(ld, cnt, UD_REG_NAME(MAC_TX_IPGCTRL), BITS_PRE_CNT_LIMIT); local_unlock(ld); return old; }
PHPAPI struct tm *php_gmtime_r(const time_t *const timep, struct tm *p_tm) { struct tm *tmp; local_lock(GMTIME_R); tmp = gmtime(timep); if (tmp) { memcpy(p_tm, tmp, sizeof(struct tm)); tmp = p_tm; } local_unlock(GMTIME_R); return tmp; }
void StreamingUIWidget::paintEvent(QPaintEvent *event) { // RECT rc; // ::GetClientRect(handle(), &rc); QPainter painter(this); QRect tmpRect = this->rect(); VideoRenderer* local_renderer = local_renderer_.get(); VideoRenderer* remote_renderer = remote_renderer_.get(); if (remote_renderer && local_renderer) { AutoLock<VideoRenderer> local_lock(local_renderer); AutoLock<VideoRenderer> remote_lock(remote_renderer); const BITMAPINFO& bmi = remote_renderer->bmi(); int height = abs(bmi.bmiHeader.biHeight); int width = bmi.bmiHeader.biWidth; //this->resize(width,height); const uint8* image = remote_renderer->image(); if (image != NULL) { QByteArray bmpData; //make bmp BITMAPFILEHEADER fileHead; fileHead.bfType = 0x4D42;//bmp类型 fileHead.bfSize= sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFO) + bmi.bmiHeader.biSizeImage; fileHead.bfOffBits=sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFO); bmpData.append((char *)&fileHead,sizeof(BITMAPFILEHEADER)); bmpData.append((char *)&bmi,sizeof(BITMAPINFO)); bmpData.append((char *)image,bmi.bmiHeader.biSizeImage); QImage tmpImage = QImage::fromData(bmpData,"BMP"); painter.drawPixmap(0,0,width,height,QPixmap::fromImage(tmpImage)); } else { QString text(kConnecting); if (!local_renderer->image()) { text += kNoVideoStreams; } else { text += kNoIncomingStream; } painter.drawText(10,10,text); } } }
PHPAPI int php_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) { #if defined(HAVE_OLD_READDIR_R) int ret = 0; /* We cannot rely on the return value of readdir_r as it differs between various platforms (HPUX returns 0 on success whereas Solaris returns non-zero) */ entry->d_name[0] = '\0'; readdir_r(dirp, entry); if (entry->d_name[0] == '\0') { *result = NULL; ret = errno; } else { *result = entry; } return ret; #else struct dirent *ptr; int ret = 0; local_lock(READDIR_R); errno = 0; ptr = readdir(dirp); if (!ptr && errno != 0) ret = errno; if (ptr) memcpy(entry, ptr, sizeof(*ptr)); *result = ptr; local_unlock(READDIR_R); return ret; #endif }
static int hieth_net_set_mac_address(struct net_device *dev, void *p) { struct hieth_netdev_local *ld = netdev_priv(dev); struct sockaddr *skaddr = p; local_lock(ld); if (hieth_devs_save[UP_PORT]) memcpy(hieth_devs_save[UP_PORT]->dev_addr, skaddr->sa_data, dev->addr_len); if (hieth_devs_save[DOWN_PORT]) memcpy(hieth_devs_save[DOWN_PORT]->dev_addr, skaddr->sa_data, dev->addr_len); local_unlock(ld); hieth_hw_set_macaddress(ld, 1, dev->dev_addr); return 0; }
int hieth_set_mac_trans_interval_bits(struct hieth_netdev_local *ld, int nbits) { int old; int linkstat, negmode; local_lock(ld); negmode = _set_negmode(ld, HIETH_NEGMODE_CPUSET); linkstat = _set_linkstat(ld, 0); udelay(1000); old = hieth_readl_bits(ld, UD_REG_NAME(MAC_TX_IPGCTRL), BITS_IPG); hieth_writel_bits(ld, nbits, UD_REG_NAME(MAC_TX_IPGCTRL), BITS_IPG); udelay(100); _set_negmode(ld, negmode); _set_linkstat(ld, linkstat); local_unlock(ld); return old; }
virtual bool connected() const { unique_lock<mutex_type> local_lock(_mutex); nolock_grab_tracked_objects(detail::null_output_iterator()); return nolock_nograb_connected(); }
void disconnect() { unique_lock<connection_body_base> local_lock(*this); nolock_disconnect(); }