示例#1
0
void RedisDBSlice::CloseConnPool()
{
    {
        XLOCK(mSliceConn.MasterLock);
        RedisConnIter master_iter = mSliceConn.RedisMasterConn.begin();
        for (; master_iter != mSliceConn.RedisMasterConn.end(); ++master_iter) {
            redisFree((*master_iter)->getCtx());
            delete *master_iter;
        }
    }

    {
        XLOCK(mSliceConn.SlaveLock);
        RedisSlaveGroupIter slave_iter = mSliceConn.RedisSlaveConn.begin();
        for (; slave_iter != mSliceConn.RedisSlaveConn.end(); ++slave_iter) {
            RedisConnPool* pConnPool = (*slave_iter);
            RedisConnIter iter = pConnPool->begin();
            for (; iter != pConnPool->end(); ++iter) {
                redisFree((*iter)->getCtx());
                delete *iter;
            }
            delete pConnPool;
        }
    }

    mStatus = REDISDB_DEAD;
}
示例#2
0
void RedisDBSlice::ConnPoolPing()
{
    {
        XLOCK(mSliceConn.MasterLock);
        RedisConnIter master_iter = mSliceConn.RedisMasterConn.begin();
        for (; master_iter != mSliceConn.RedisMasterConn.end(); ++master_iter) {
            bool bRet = (*master_iter)->Ping();
            if (!bRet) {
                (*master_iter)->RedisReConnect();
            } else {
                
            }
        }
    }

    {
        XLOCK(mSliceConn.SlaveLock);
        RedisSlaveGroupIter slave_iter = mSliceConn.RedisSlaveConn.begin();
        for (; slave_iter != mSliceConn.RedisSlaveConn.end(); ++slave_iter) {
            RedisConnPool* pConnPool = (*slave_iter);
            RedisConnIter iter = pConnPool->begin();
            for (; iter != pConnPool->end(); ++iter) {
                bool bRet = (*iter)->Ping();
                if (!bRet) {
                    (*iter)->RedisReConnect();
                } else {
                    
                }
            }
        }
    }
}
示例#3
0
bool RedisDBSlice::ConnectRedisNodes(unsigned int cahcetype, unsigned int dbindex, const std::string& host, unsigned int port, const std::string& passwd, unsigned int poolsize, unsigned int timeout, int role)
{
    bool bRet = false;
    if ((host.empty())
        || (cahcetype > MAX_REDIS_CACHE_TYPE)
        || (dbindex > MAX_REDIS_DB_HASHBASE)
        || (poolsize > MAX_REDIS_CONN_POOLSIZE)) {
        return false;
    }

    try {
        if (MASTER == role) {
            XLOCK(mSliceConn.MasterLock);
            for (unsigned int i = 0; i < poolsize; ++i) {
                RedisConn *pRedisconn = new RedisConn;
                if (NULL == pRedisconn) {
                    continue;
                }

                pRedisconn->Init(cahcetype, dbindex, host.c_str(), port, passwd.c_str(), poolsize, timeout, role, 0);
                if (pRedisconn->RedisConnect()) {
                    mSliceConn.RedisMasterConn.push_back(pRedisconn);
                    mStatus = REDISDB_WORKING;
                } else {
                    delete pRedisconn;
                }
            }
            bRet = true;
        } else if (SLAVE == role) {
            XLOCK(mSliceConn.SlaveLock);
            RedisConnPool *pSlaveNode = new RedisConnPool;
            int slave_idx = mSliceConn.RedisSlaveConn.size();
            for (unsigned int i = 0; i < poolsize; ++i) {
                RedisConn *pRedisconn = new RedisConn;
                if (NULL == pRedisconn) {
                    continue;
                }

                pRedisconn->Init(cahcetype, dbindex, host.c_str(), port, passwd.c_str(), poolsize, timeout, role, slave_idx);
                if (pRedisconn->RedisConnect()) {
                    pSlaveNode->push_back(pRedisconn);
                } else {
                    delete pRedisconn;
                }
            }
            mSliceConn.RedisSlaveConn.push_back(pSlaveNode);
            bRet = true;
            mHaveSlave = true;
        } else {
            bRet = false;
        }

    } catch (...) {
        return false;
    }

    return bRet;
}
示例#4
0
文件: load.c 项目: OSLL/vboxhsm
static bool stubSystemWindowExist(WindowInfo *pWindow)
{
#ifdef WINDOWS
    if (pWindow->hWnd!=WindowFromDC(pWindow->drawable))
    {
        return false;
    }
#else
    Window root;
    int x, y;
    unsigned int border, depth, w, h;
    Display *dpy;

    dpy = stubGetWindowDisplay(pWindow);

    XLOCK(dpy);
    if (!XGetGeometry(dpy, pWindow->drawable, &root, &x, &y, &w, &h, &border, &depth))
    {
        XUNLOCK(dpy);
        return false;
    }
    XUNLOCK(dpy);
#endif

    return true;
}
示例#5
0
void RedisDBSlice::FreeConn(RedisConn *redisconn)
{
    if (NULL != redisconn) {
        unsigned int role = redisconn->GetRole();
        if (MASTER == role) {
            XLOCK(mSliceConn.MasterLock);
            mSliceConn.RedisMasterConn.push_back(redisconn);
        } else if (SLAVE == role) {
            XLOCK(mSliceConn.SlaveLock);
            RedisConnPool *pSlave = mSliceConn.RedisSlaveConn[redisconn->GetSlaveIdx()];
            pSlave->push_back(redisconn);
        } else {

        }
    }
}
示例#6
0
/* _xdga2_scroll_screen:
 *  Scrolls DGA viewport.
 */
static int _xdga2_scroll_screen(int x, int y)
{
   if (x < 0) x = 0;
   else if (x > dga_device->mode.maxViewportX)
      x = dga_device->mode.maxViewportX;
   if (y < 0) y = 0;
   else if (y > dga_device->mode.maxViewportY)
      y = dga_device->mode.maxViewportY;
   if ((_xwin.scroll_x == x) && (_xwin.scroll_y == y))
      return 0;

   XLOCK();

   _xwin.scroll_x = x;
   _xwin.scroll_y = y;

   if (_wait_for_vsync)
      while (XDGAGetViewportStatus(_xwin.display, _xwin.screen))
         ;

   XDGASetViewport(_xwin.display, _xwin.screen, x, y, XDGAFlipRetrace);

   XUNLOCK();
   
   return 0;
}
示例#7
0
/* _xwin_select_system_cursor:
 *  Select an OS native cursor 
 */
static int _xwin_select_system_cursor(AL_CONST int cursor)
{
   switch(cursor) {
      case MOUSE_CURSOR_ARROW:
         _xwin.cursor_shape = XC_left_ptr;
         break;
      case MOUSE_CURSOR_BUSY:
         _xwin.cursor_shape = XC_watch;
         break;
      case MOUSE_CURSOR_QUESTION:
         _xwin.cursor_shape = XC_question_arrow;
         break;
      case MOUSE_CURSOR_EDIT:
         _xwin.cursor_shape = XC_xterm;
         break;
      default:
         return 0;
   }

   XLOCK();

   if (_xwin.cursor != None) {
      XUndefineCursor(_xwin.display, _xwin.window);
      XFreeCursor(_xwin.display, _xwin.cursor);
   }

   _xwin.cursor = XCreateFontCursor(_xwin.display, _xwin.cursor_shape);
   XDefineCursor(_xwin.display, _xwin.window, _xwin.cursor);

   XUNLOCK();

   return cursor;
}
示例#8
0
/* _xdga2_lock:
 *  Synchronizes with framebuffer.
 */
void _xdga2_lock(BITMAP *bmp)
{
   XLOCK();
   RESYNC();
   XUNLOCK();
   bmp->id |= BMP_ID_LOCKED;
}
示例#9
0
/* x_keyboard_exit
 *  Shut down the X11 keyboard driver.
 */
static void x_keyboard_exit(void)
{
   if (!xkeyboard_installed)
      return;
   xkeyboard_installed = 0;

   XLOCK();

#ifdef ALLEGRO_XWINDOWS_WITH_XIM

   if (xic) {
      XDestroyIC(xic);
      xic = NULL;
   }

   if (xim) {
      XCloseIM(xim);
      xim = NULL;
   }

#endif

   if (xmodmap) {
      XFreeModifiermap(xmodmap);
      xmodmap = NULL;
   }

   if (keysyms) {
      XFree(keysyms);
      keysyms = NULL;
   }

   XUNLOCK();
}
void
stubGetWindowGeometry(WindowInfo *window, int *x, int *y, unsigned int *w, unsigned int *h)
{
    Window root, child;
    unsigned int border, depth;
    Display *dpy;

    dpy = stubGetWindowDisplay(window);

    //@todo: Performing those checks is expensive operation, especially for simple apps with high FPS.
    //       Disabling those triples glxgears fps, thus using xevents instead of per frame polling is much more preferred.
    //@todo: Check similar on windows guests, though doubtful as there're no XSync like calls on windows.
    if (window && dpy)
    {
        XLOCK(dpy);
    }

    if (!window
        || !dpy
        || !window->drawable
        || !XGetGeometry(dpy, window->drawable, &root, x, y, w, h, &border, &depth)
        || !XTranslateCoordinates(dpy, window->drawable, root, 0, 0, x, y, &child)) 
    {
        crWarning("Failed to get windows geometry for %p, try xwininfo", window);
        *x = *y = 0;
        *w = *h = 0;
    }

    if (window && dpy)
    {
        XUNLOCK(dpy);
    }
}
示例#11
0
/* _xdga2_set_palette_range:
 *  Sets palette entries.
 */
static void _xdga2_set_palette_range(AL_CONST PALETTE p, int from, int to, int vsync)
{
   int i;
   static XColor color[256];

   XLOCK();
   
   if (vsync) {
      XSync(_xwin.display, False);
   }

   if (dga_device->mode.depth == 8) {
      for (i = from; i <= to; i++) {
         color[i].flags = DoRed | DoGreen | DoBlue;
         color[i].pixel = i;
         color[i].red = ((p[i].r & 0x3F) * 65535L) / 0x3F;
         color[i].green = ((p[i].g & 0x3F) * 65535L) / 0x3F;
         color[i].blue = ((p[i].b & 0x3F) * 65535L) / 0x3F;
      }
      XStoreColors(_xwin.display, _dga_cmap, color + from, to - from + 1);
      XSync(_xwin.display, False);
   }

   XUNLOCK();
}
示例#12
0
/* _xwin_set_mouse_speed:
 *  The actual function that sets the speed of the mouse cursor.
 *  Each step slows down or speeds the mouse up by 0.5x.
 */
static void _xwin_set_mouse_speed(int xspeed, int yspeed)
{
   int speed;
   int hundredths;

   XLOCK();

   if (mouse_mult < 0)
      XGetPointerControl(_xwin.display, &mouse_mult, &mouse_div,
         &mouse_threshold);

   speed = MAX(1, (xspeed + yspeed) / 2);

   if (mouse_div == 0)
      hundredths = mouse_mult * 100;
   else
      hundredths = (mouse_mult * 100 / mouse_div);
   hundredths -= (speed - 2) * 50;
   if (hundredths < 0)
      hundredths = 0;

   XChangePointerControl(_xwin.display, 1, 1, hundredths,
      100, mouse_threshold);

   XUNLOCK();
}
示例#13
0
/* Direct X11 version of the function. */
static inline int _xwin_direct_clear_to_color(BITMAP *dst, int color)
{
   int dx1, dy1, dx2, dy2;
   if (!_xwin.drawing_mode_ok)
      return 0;

   dx1 = dst->cl + dst->x_ofs - _xwin.scroll_x;
   dx2 = dst->cr + dst->x_ofs - 1 - _xwin.scroll_x;
   dy1 = dst->ct + dst->y_ofs - _xwin.scroll_y;
   dy2 = dst->cb + dst->y_ofs - 1 - _xwin.scroll_y;

   if (dx1 < 0)
      dx1 = 0;
   if (dx2 >= _xwin.screen_width)
      dx2 = _xwin.screen_width - 1;
   if (dx1 > dx2)
      return 1;

   if (dy1 < 0)
      dy1 = 0;
   if (dy2 >= _xwin.screen_height)
      dy2 = _xwin.screen_height - 1;
   if (dy1 > dy2)
      return 1;

   XLOCK();
   XSetForeground(_xwin.display, _xwin.gc, color);
   XFillRectangle(_xwin.display, _xwin.window, _xwin.gc, dx1, dy1, dx2-dx1+1, dy2-dy1+1);
   XUNLOCK();

   return 1;
}
示例#14
0
/* _xdga2_request_video_bitmap:
 *  Page flips to display specified bitmap, but doesn't wait for retrace.
 */
static int _xdga2_request_video_bitmap(BITMAP *bmp)
{
   XLOCK();
   XDGASetViewport(_xwin.display, _xwin.screen, bmp->x_ofs, bmp->y_ofs, XDGAFlipRetrace);
   XUNLOCK();
   return 0;
}
示例#15
0
void MythXDisplay::StartLog(void)
{
    if (!m_disp || xerror_handlers.count(m_disp))
        return;

    Sync();
    XLOCK(this, xerror_handlers[m_disp] = XSetErrorHandler(ErrorHandler));
}
示例#16
0
/* _xwin_sysdrv_get_desktop_resolution:
 *  Returns the current desktop resolution.
 */
static int _xwin_sysdrv_get_desktop_resolution(int *width, int *height)
{
   XLOCK();
   *width = DisplayWidth(_xwin.display, _xwin.screen);
   *height = DisplayHeight(_xwin.display, _xwin.screen);
   XUNLOCK();
   return 0;
}
示例#17
0
void MythXDisplay::FillRectangle(Window win, const QRect &rect)
{
    if (!m_gc)
        return;
    XLOCK(this, XFillRectangle(m_disp, win, m_gc,
                              rect.left(), rect.top(),
                              rect.width(), rect.height()));
}
示例#18
0
static GFX_MODE_LIST *_xdga2_fetch_mode_list(void)
{
   GFX_MODE_LIST *list;
   XLOCK ();
   list = _xdga2_private_fetch_mode_list();
   XUNLOCK ();
   return list;
}
示例#19
0
/* _xdga2_poll_scroll:
 *  Returns true if there are pending scrolling requests left.
 */
static int _xdga2_poll_scroll(void)
{
   int result;

   XLOCK();
   result = XDGAGetViewportStatus(_xwin.display, _xwin.screen);
   XUNLOCK();
   return result;
}
示例#20
0
/* _xwin_mouse_leave_notify:
 *  Reset the mouse speed to its original value when the cursor leave the
 *  Allegro window.
 */
void _xwin_mouse_leave_notify(void)
{
   if (mouse_mult >= 0) {
      XLOCK();
      XChangePointerControl(_xwin.display, 1, 1, mouse_mult,
         mouse_div, mouse_threshold);
      XUNLOCK();
   }
}
示例#21
0
bool MythXDisplay::StopLog(void)
{
    if (!(m_disp && xerror_handlers.count(m_disp)))
        return false;

    Sync();
    XErrorCallbackType old_handler = xerror_handlers[m_disp];
    XLOCK(this, XSetErrorHandler(old_handler));
    xerror_handlers.erase(m_disp);
    return CheckErrors();
}
示例#22
0
static BITMAP *_xdga2_gfxdrv_init_drv(GFX_DRIVER *drv, int w, int h, int vw, int vh, int depth, int accel)
{
   BITMAP *bmp;
   XLOCK();
   bmp = _xdga2_private_gfxdrv_init_drv(drv, w, h, vw, vh, depth, accel);
   XUNLOCK();
   if (!bmp)
      _xdga2_gfxdrv_exit(bmp);
   else
      _xwin_input_handler = _xdga2_handle_input;
   return bmp;
}
示例#23
0
/* _xaccel_blit_to_self:
 *  Accelerated vram -> vram blit.
 */
static void _xaccel_blit_to_self(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height)
{
   source_x += source->x_ofs;
   source_y += source->y_ofs;
   dest_x += dest->x_ofs;
   dest_y += dest->y_ofs;

   XLOCK();
   XDGACopyArea(_xwin.display, _xwin.screen, source_x, source_y, width, height, dest_x, dest_y);
   XUNLOCK();
   dest->id &= ~BMP_ID_LOCKED;
}
示例#24
0
RedisConn * RedisDBSlice::GetMasterConn()
{
    RedisConn *pRedisConn = NULL;
    XLOCK(mSliceConn.MasterLock);
    if (!mSliceConn.RedisMasterConn.empty()) {
        pRedisConn = mSliceConn.RedisMasterConn.front();
        mSliceConn.RedisMasterConn.pop_front();
    } else {
        mStatus = REDISDB_DEAD;
    }
    return pRedisConn;
}
示例#25
0
/* _xwin_mousedrv_exit:
 *  Shuts down the mickey-mode driver.
 */
static void _xwin_mousedrv_exit(void)
{
   XLOCK();

   if (mouse_mult >= 0)
      XChangePointerControl(_xwin.display, 1, 1, mouse_mult,
         mouse_div, mouse_threshold);

   _xwin_mouse_interrupt = 0;

   XUNLOCK();
}
示例#26
0
/* _xaccel_rectfill:
 *  Accelerated rectfill.
 */
static void _xaccel_rectfill(BITMAP *bmp, int x1, int y1, int x2, int y2, int color)
{
   int tmp;

   if (_drawing_mode != DRAW_MODE_SOLID) {
      _orig_rectfill(bmp, x1, y1, x2, y2, color);
      return;
   }

   if (x2 < x1) {
      tmp = x1;
      x1 = x2;
      x2 = tmp;
   }

   if (y2 < y1) {
      tmp = y1;
      y1 = y2;
      y2 = tmp;
   }

   if (bmp->clip) {
      if (x1 < bmp->cl)
         x1 = bmp->cl;

      if (x2 >= bmp->cr)
         x2 = bmp->cr-1;

      if (x2 < x1)
         return;

      if (y1 < bmp->ct)
         y1 = bmp->ct;

      if (y2 >= bmp->cb)
         y2 = bmp->cb-1;

      if (y2 < y1)
         return;
   }

   x1 += bmp->x_ofs;
   y1 += bmp->y_ofs;
   x2 += bmp->x_ofs;
   y2 += bmp->y_ofs;

   XLOCK();
   XDGAFillRectangle(_xwin.display, _xwin.screen, x1, y1, (x2 - x1) + 1, (y2 - y1) + 1, color);
   XUNLOCK();
   bmp->id &= ~BMP_ID_LOCKED;
}
示例#27
0
 ~VAAPIDisplay()
  {
      if (m_va_disp)
      {
          INIT_ST;
          XLOCK(m_x_disp, va_status = vaTerminate(m_va_disp));
          CHECK_ST;
      }
      if (m_x_disp)
      {
          m_x_disp->Sync(true);
          delete m_x_disp;
      }
  }
示例#28
0
/* _xaccel_clear_to_color:
 *  Accelerated clear_to_color.
 */
static void _xaccel_clear_to_color(BITMAP *bmp, int color)
{
   int x1, y1, x2, y2;

   x1 = bmp->cl + bmp->x_ofs;
   y1 = bmp->ct + bmp->y_ofs;
   x2 = bmp->cr + bmp->x_ofs;
   y2 = bmp->cb + bmp->y_ofs;
   
   XLOCK();
   XDGAFillRectangle(_xwin.display, _xwin.screen, x1, y1, x2 - x1, y2 - y1, color);
   XUNLOCK();
   bmp->id &= ~BMP_ID_LOCKED;
}
示例#29
0
/* _xaccel_draw_sprite:
 *  Accelerated draw_sprite.
 */
static void _xaccel_draw_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y)
{
   int sx, sy, w, h;

   if (is_video_bitmap(sprite)) {
      sx = 0;
      sy = 0;
      w = sprite->w;
      h = sprite->h;

      if (bmp->clip) {
         if (x < bmp->cl) {
            sx += bmp->cl - x;
            w -= bmp->cl - x;
            x = bmp->cl;
         }

         if (y < bmp->ct) {
            sy += bmp->ct - y;
            h -= bmp->ct - y;
            y = bmp->ct;
         }

         if (x + w > bmp->cr)
            w = bmp->cr - x;

         if (w <= 0)
            return;

         if (y + h > bmp->cb)
            h = bmp->cb - y;

         if (h <= 0)
            return;
      }

      sx += sprite->x_ofs;
      sy += sprite->y_ofs;
      x += bmp->x_ofs;
      y += bmp->y_ofs;

      XLOCK();
      XDGACopyTransparentArea(_xwin.display, _xwin.screen, sx, sy, w, h, x, y, sprite->vtable->mask_color);
      XUNLOCK();
      bmp->id &= ~BMP_ID_LOCKED;
   }
   else
      _orig_draw_sprite(bmp, sprite, x, y);
}
示例#30
0
RedisConn * RedisDBSlice::GetSlaveConn()
{
    RedisConn *pRedisConn = NULL;
    XLOCK(mSliceConn.SlaveLock);
    if (!mSliceConn.RedisSlaveConn.empty()) {
        size_t slave_cnt = mSliceConn.RedisSlaveConn.size();
        unsigned int idx = rand() % slave_cnt;
        RedisConnPool *pSlave = mSliceConn.RedisSlaveConn[idx];
        pRedisConn = pSlave->front();
        pSlave->pop_front();
        //if (idx != pRedisConn->GetSlaveIdx()) {
        //}
    }
    return pRedisConn;
}