예제 #1
0
static void add_en_passant_captures(list_t * list, const board_t * board) {

   int from, to;
   int me;
   int inc;
   int pawn;

   ASSERT(list!=NULL);
   ASSERT(board!=NULL);

   to = board->ep_square;

   if (to != SquareNone) {

      me = board->turn;

      inc = PAWN_MOVE_INC(me);
      pawn = PAWN_MAKE(me);

      from = to - (inc-1);
      if (board->square[from] == pawn) {
         ASSERT(!SQUARE_IS_PROMOTE(to));
         LIST_ADD(list,MOVE_MAKE_FLAGS(from,to,MoveEnPassant));
      }

      from = to - (inc+1);
      if (board->square[from] == pawn) {
         ASSERT(!SQUARE_IS_PROMOTE(to));
         LIST_ADD(list,MOVE_MAKE_FLAGS(from,to,MoveEnPassant));
      }
   }
}
예제 #2
0
파일: plghost.cpp 프로젝트: strogo/Isotoxin
 void kill(ipcw *w)
 {
     if (w >= (data+0) && w < (data + preallocated_bitems))
     {
         LIST_ADD((ipcwspace *)w, first, last, prev, next );
     } else
     {
         LIST_ADD((ipcwspace *)w, first_a, last_a, prev, next);
     }
 }
예제 #3
0
void add_promote(list_t * list, int move) {

   ASSERT(list!=NULL);
   ASSERT(move_is_ok(move));

   ASSERT((move&~07777)==0); // HACK
   ASSERT(SQUARE_IS_PROMOTE(MOVE_TO(move)));

   LIST_ADD(list,move|MovePromoteQueen);
   LIST_ADD(list,move|MovePromoteKnight);
   LIST_ADD(list,move|MovePromoteRook);
   LIST_ADD(list,move|MovePromoteBishop);
}
예제 #4
0
static void
_fill_zone_config(E_Zone               *zone,
                  E_Config_Dialog_Data *cfdata)
{
   E_Radio_Group *rg;
   Evas *evas = cfdata->evas;
   int i;

   /* Clear old entries first */
   evas_object_del(cfdata->o_desklist);
   cfdata->o_desklist = e_widget_list_add(evas, 1, 0);
   e_scrollframe_child_set(e_widget_scrollframe_object_get(cfdata->o_deskscroll), cfdata->o_desklist);
   e_widget_sub_object_add(cfdata->o_deskscroll, cfdata->o_desklist);

   for (i = 0; i < zone->desk_y_count * zone->desk_x_count; i++)
     {
        E_Desk *desk = zone->desks[i];
        if (!desk) continue;

        struct _E_Config_vdesk *vd = get_vdesk(cfdata, desk->x, desk->y, zone->num);
        if (!vd)
          {
             vd = malloc(sizeof(struct _E_Config_vdesk));
             vd->x = desk->x;
             vd->y = desk->y;
             vd->zone_num = zone->num;
             vd->layout = TILE_NONE;
             cfdata->vdesks = eina_list_append(cfdata->vdesks, vd);
          }

        rg = e_widget_radio_group_new(&(vd->layout));
        Evas_Object *radiolist = e_widget_list_add(evas, 0, 1);

        LIST_ADD(radiolist, e_widget_label_add(evas, desk->name));
        LIST_ADD(radiolist, RADIO("None", TILE_NONE, rg));
        LIST_ADD(radiolist, RADIO("Bigmain", TILE_BIGMAIN, rg));
        LIST_ADD(radiolist, RADIO("Grid", TILE_GRID, rg));
        LIST_ADD(cfdata->o_desklist, radiolist);
     }

   /* Get the correct sizes of desklist and scrollframe */
   int mw, mh;
   e_widget_size_min_get(cfdata->o_desklist, &mw, &mh);
   evas_object_resize(cfdata->o_desklist, mw, mh);
   if (mh > 150)
     mh = 150;
   mw += 32;
   mh += 32;
   e_widget_size_min_set(cfdata->o_deskscroll, mw, mh);
}
예제 #5
0
/* Log a fork system call.
 *
 * This will log the return value, but only if it's not 0 (i.e., is in
 * the parent). */
static void
handle_fork(struct filemon *fm, char op,
	    is_at_enum is_at __maybe_unused, struct pt_regs *regs)
{
#ifndef FILEMON_PERFORMANCE_NO_FORK_FM
	struct pid *pid;
#endif
	int scrv;
	scrv = syscall_get_return_value(current, regs);
	if (scrv == 0)		/* The < 0 case was already handled. */
		return;
	filemon_log(fm, op, "%i", scrv);

#ifndef FILEMON_PERFORMANCE_NO_FORK_FM
	/* List is already locked */
	pid = find_get_pid(scrv);
	if (pid >= 0) {
		struct fm_pids *s;
		s = kmalloc(sizeof(struct fm_pids), GFP_KERNEL);
		if (s) {
			s->pid = pid;
			LIST_ADD(&s->list, &fm->shead->list);
		}
	}
#endif
}
예제 #6
0
파일: dfile.c 프로젝트: dhanks/jcd
int dfile_create(char const *name, char const *path, int const flags, int const system)
{
	DFILE *df = dfile_malloc();

	if(!df)
		return (-1);

	dfile_init(df);
	LIST_ADD(l_dfile, df, sizeof(DFILE));
	df->state = dfsVirgin;
	strncpy(df->name, name, MAX_STRING-1);
	strncpy(df->path, path, 79);

	if(load_dfile(df, path, flags) != 0)
	{
		vmlog(8, "dfile_create: bad load on `%s', aborting.\n", path);
		LIST_REMOVE(l_dfile, df);
		FREE(df);
		return (-1);
	}

	if(system)
		df->flags |= DFS_SYSTEM;

	return (0);
}
예제 #7
0
파일: port.c 프로젝트: 1tgr/mobius
status_t PortCreateFile(fsd_t *fsd, vnode_id_t dir, const wchar_t *name, 
                        void **cookie)
{
    port_fsd_t *pfsd;
    port_t *server;

    pfsd = (port_fsd_t*) fsd;
    assert(dir == VNODE_ROOT);

    //wprintf(L"PortCreateFile(%s)\n", name);

    server = malloc(sizeof(port_t));
    if (server == NULL)
        return errno;

    memset(server, 0, sizeof(port_t));
    server->is_server = true;
    server->u.server.name = _wcsdup(name);
    *cookie = server;

    SpinAcquire(&pfsd->sem);
    LIST_ADD(pfsd->server, server);
    SpinRelease(&pfsd->sem);

    return 0;
}
예제 #8
0
int Sched::addtoactive(Task &task)
{
	Task *pos;
	uint8_t task_priority;
	task_priority = task.Task_GetSchedPriority();
	DEBUG_PRINT("addtoactive:task_priority:%d\n",task_priority);
	task.Task_SetState(TSTATE_TASK_READYTORUN);

	if (LIST_EMPTY(task_active)) {			// furtherm
		LIST_ADD(task_active, task);
		DEBUG_PRINT("LIST_EMPTY:LIST_ADD to task_active OK\n");
		Sched_SetCurrentTask(task);
		DEBUG_PRINT("It's the first task.\n");
		return OK;
	}else {

		if (LIST_LAST_ENTRY(task_active).Task_GetSchedPriority() > task_priority) {
			LIST_ADD_TAIL(task_active, task);
		}else {	
			LIST_FOR_EACH_ENTRY(task_active, pos) {
				if (pos->Task_GetSchedPriority() <= task_priority) {
					LIST_ADD_BEFORE(task_active, task, (*pos));
				}
			}
			if (!Sched_locked() && IS_LIST_FIRST_ENTRY(task_active, task)) {
				return OK;
			}
		}
	}
	return NO;
}
예제 #9
0
static bool add_piece_moves(list_t * list, const board_t * board, int to, bool legal, bool stop) {

   int me;
   const sq_t * ptr;
   int from, piece;

   ASSERT(list!=NULL);
   ASSERT(board!=NULL);
   ASSERT(SQUARE_IS_OK(to));
   ASSERT(legal==true||legal==false);
   ASSERT(stop==true||stop==false);

   me = board->turn;

   for (ptr = &board->piece[me][1]; (from=*ptr) != SquareNone; ptr++) { // HACK: no king

      piece = board->square[from];

      if (PIECE_ATTACK(board,piece,from,to)) {
         if (!legal || !is_pinned(board,from,me)) {
            if (stop) return true;
            LIST_ADD(list,MOVE_MAKE(from,to));
         }
      }
   }

   return false;
}
예제 #10
0
/**
 * Create a session and its associated queues.
 * @param   nsid        namespace id
 * @param   qcount      queue count
 * @param   qsize       queue size
 * @return  newly created session.
 */
static unvme_session_t* unvme_session_create(int nsid, int qcount, int qsize)
{
    DEBUG_FN("%x: nsid=%d qc=%d qs=%d",
             unvme_dev.vfiodev->pci, nsid, qcount, qsize);
    if ((nsid == 0 && (unvme_dev.ses || qcount != 1)) ||
        (nsid != 0 && !unvme_dev.ses)) FATAL("nsid %d", nsid);

    // allocate a session with its queue array
    unvme_session_t* ses = zalloc(sizeof(unvme_session_t) +
                                  sizeof(unvme_queue_t) * qcount);
    ses->queues = (unvme_queue_t*)(ses + 1);
    ses->qcount = qcount;
    ses->qsize = qsize;
    ses->masksize = ((qsize + 63) / 64) * sizeof(u64);

    if (pthread_spin_init(&ses->iomem.lock, PTHREAD_PROCESS_SHARED))
        FATAL("pthread_spin_init");

    LIST_ADD(unvme_dev.ses, ses);
    if (!nsid) {
        unvme_adminq_create(ses);
        unvme_ns_init(ses, nsid);
        DEBUG_FN("%x: adminq", unvme_dev.vfiodev->pci);
    } else {
        unvme_ns_init(ses, nsid);
        int i;
        for (i = 0; i < qcount; i++) unvme_ioq_create(ses, i);
        DEBUG_FN("%x: q=%d-%d bs=%d nb=%lu", unvme_dev.vfiodev->pci,
                 ses->id, ses->queues[qcount-1].id,
                 ses->ns.blocksize, ses->ns.blockcount);
    }

    return ses;
}
예제 #11
0
파일: node.c 프로젝트: dardevelin/utu
void Node_add_sib(Node *sib1, Node *sib2)
{
  assert_not(sib1, NULL);
  assert_not(sib2, NULL);

  LIST_ADD(Node, sib1, sib2, sibling);
  sib2->parent = sib1->parent;
}
예제 #12
0
파일: node.c 프로젝트: dardevelin/utu
void Node_add_child(Node *parent, Node *child) 
{
  assert_not(parent, NULL);
  assert_not(child, NULL);

  LIST_ADD(Node, parent->child, child, sibling);
  child->parent = parent;
}
예제 #13
0
static void *gp_worker_main(void *pvt)
{
    struct gp_thread *t = (struct gp_thread *)pvt;
    struct gp_query *q = NULL;
    char dummy = 0;
    int ret;

    while (!t->pool->shutdown) {

        /* ======> COND_MUTEX */
        pthread_mutex_lock(&t->cond_mutex);
        while (t->query == NULL) {
            /* wait for next query */
            pthread_cond_wait(&t->cond_wakeup, &t->cond_mutex);
            if (t->pool->shutdown) {
                pthread_exit(NULL);
            }
        }

        /* grab the query off the shared pointer */
        q = t->query;
        t->query = NULL;

        /* <====== COND_MUTEX */
        pthread_mutex_unlock(&t->cond_mutex);

        /* handle the client request */
        gp_handle_query(t->pool, q);

        /* now get lock on main queue, to play with the reply list */
        /* ======> POOL LOCK */
        pthread_mutex_lock(&t->pool->lock);

        /* put back query so that dispatcher can send reply */
        q->next = t->pool->reply_list;
        t->pool->reply_list = q;

        /* add us back to the free list but only if we are not
         * shutting down */
        if (!t->pool->shutdown) {
            LIST_DEL(t->pool->busy_list, t);
            LIST_ADD(t->pool->free_list, t);
        }

        /* <====== POOL LOCK */
        pthread_mutex_unlock(&t->pool->lock);

        /* and wake up dispatcher so it will handle it */
        ret = write(t->pool->sig_pipe[1], &dummy, 1);
        if (ret == -1) {
            GPERROR("Failed to signal dispatcher!");
        }
    }

    pthread_exit(NULL);
}
예제 #14
0
void add_pawn_move(list_t * list, int from, int to) {

   int move;

   ASSERT(list!=NULL);
   ASSERT(SQUARE_IS_OK(from));
   ASSERT(SQUARE_IS_OK(to));

   move = MOVE_MAKE(from,to);

   if (SQUARE_IS_PROMOTE(to)) {
      LIST_ADD(list,move|MovePromoteQueen);
      LIST_ADD(list,move|MovePromoteKnight);
      LIST_ADD(list,move|MovePromoteRook);
      LIST_ADD(list,move|MovePromoteBishop);
   } else {
      LIST_ADD(list,move);
   }
}
static INLINE struct svga_winsys_surface *
svga_screen_cache_lookup(struct svga_screen *svgascreen,
                         const struct svga_host_surface_cache_key *key)
{
   struct svga_host_surface_cache *cache = &svgascreen->cache;
   struct svga_winsys_screen *sws = svgascreen->sws;
   struct svga_host_surface_cache_entry *entry;
   struct svga_winsys_surface *handle = NULL;
   struct list_head *curr, *next;
   unsigned bucket;
   unsigned tries = 0;

   assert(key->cachable);

   bucket = svga_screen_cache_bucket(key);

   pipe_mutex_lock(cache->mutex);

   curr = cache->bucket[bucket].next;
   next = curr->next;
   while(curr != &cache->bucket[bucket]) {
      ++tries;
      
      entry = LIST_ENTRY(struct svga_host_surface_cache_entry, curr, bucket_head);

      assert(entry->handle);
      
      if(memcmp(&entry->key, key, sizeof *key) == 0 &&
         sws->fence_signalled( sws, entry->fence, 0 ) == 0) {
         assert(sws->surface_is_flushed(sws, entry->handle));
         
         handle = entry->handle; // Reference is transfered here.
         entry->handle = NULL;
         
         LIST_DEL(&entry->bucket_head);

         LIST_DEL(&entry->head);
         
         LIST_ADD(&entry->head, &cache->empty);

         break;
      }

      curr = next; 
      next = curr->next;
   }

   pipe_mutex_unlock(cache->mutex);
   
   if (SVGA_DEBUG & DEBUG_DMA)
      debug_printf("%s: cache %s after %u tries (bucket %d)\n", __FUNCTION__, 
                   handle ? "hit" : "miss", tries, bucket);
   
   return handle;
}
예제 #16
0
static void add_castle_moves(list_t * list, const board_t * board) {

   ASSERT(list!=NULL);
   ASSERT(board!=NULL);

   ASSERT(!board_is_check(board));

   if (COLOUR_IS_WHITE(board->turn)) {

      if ((board->flags & FlagsWhiteKingCastle) != 0
       && board->square[F1] == Empty
       && board->square[G1] == Empty
       && !is_attacked(board,F1,Black)) {
         LIST_ADD(list,MOVE_MAKE_FLAGS(E1,G1,MoveCastle));
      }

      if ((board->flags & FlagsWhiteQueenCastle) != 0
       && board->square[D1] == Empty
       && board->square[C1] == Empty
       && board->square[B1] == Empty
       && !is_attacked(board,D1,Black)) {
         LIST_ADD(list,MOVE_MAKE_FLAGS(E1,C1,MoveCastle));
      }

   } else { // black

      if ((board->flags & FlagsBlackKingCastle) != 0
       && board->square[F8] == Empty
       && board->square[G8] == Empty
       && !is_attacked(board,F8,White)) {
         LIST_ADD(list,MOVE_MAKE_FLAGS(E8,G8,MoveCastle));
      }

      if ((board->flags & FlagsBlackQueenCastle) != 0
       && board->square[D8] == Empty
       && board->square[C8] == Empty
       && board->square[B8] == Empty
       && !is_attacked(board,D8,White)) {
         LIST_ADD(list,MOVE_MAKE_FLAGS(E8,C8,MoveCastle));
      }
   }
}
예제 #17
0
static void add_check(list_t * list, int move, board_t * board) {

    undo_t undo[1];

    ASSERT(list!=NULL);
    ASSERT(move_is_ok(move));
    ASSERT(board!=NULL);

    move_do(board,move,undo);
    if (IS_IN_CHECK(board,board->turn)) LIST_ADD(list,move);
    move_undo(board,move,undo);
}
예제 #18
0
파일: rtl8139.c 프로젝트: 1tgr/mobius
void RtlHandleRx(rtl8139_t *rtl)
{
    uint32_t ring_offs, rx_size, rx_status;
    rxpacket_t *packet;

    ring_offs = rtl->cur_rx % RX_BUF_LEN;
    rx_status = *(uint32_t*) (rtl->rx_ring + ring_offs);
    rx_size = rx_status >> 16;
    rx_status &= 0xffff;

    if ((rx_status & (RxBadSymbol | RxRunt | RxTooLong | RxCRCErr | RxBadAlign)) ||
        (rx_size < ETH_ZLEN) || 
        (rx_size > ETH_FRAME_LEN + 4))
    {
        wprintf(L"rx error 0x%x\n", rx_status);
        RtlReset(rtl);  /* this clears all interrupts still pending */
        RtlStartIo(rtl);
        return;
    }

    packet = malloc(sizeof(rxpacket_t) - 1 + rx_size - 4);
    if (packet == NULL)
        return;

    packet->length = rx_size - 4;   /* no one cares about the FCS */
    /* Received a good packet */
    if (ring_offs + 4 + rx_size - 4 > RX_BUF_LEN)
    {
        int semi_count = RX_BUF_LEN - ring_offs - 4;

        memcpy(packet->data, rtl->rx_ring + ring_offs + 4, semi_count);
        memcpy(packet->data + semi_count, rtl->rx_ring, rx_size - 4 - semi_count);
        //wprintf(L"rx packet %d+%d bytes", semi_count,rx_size - 4 - semi_count);
    }
    else
    {
        memcpy(packet->data, rtl->rx_ring + ring_offs + 4, packet->length);
        //wprintf(L"rx packet %d bytes", rx_size-4);
    }

    /*wprintf(L" at %X type %02X%02X rxstatus %hX\n",
        (unsigned long)(rtl->rx_ring + ring_offs+4),
        packet->data[12], packet->data[13], rx_status);*/

    packet->type = *(unsigned short*) (packet->data + 12);
    LIST_ADD(rtl->packet, packet);

    rtl->cur_rx = (rtl->cur_rx + rx_size + 4 + 3) & ~3;
    out16(rtl->iobase + RxBufPtr, rtl->cur_rx - 16);

    RtlStartIo(rtl);
}
예제 #19
0
/*
 * Returns:
 *  1 - If message is added to the retry queue.
 *  0 - If message is not added to the retry queue
 */
static int
iio_msg_done(struct qnio_msg *msg)
{
    struct iio_device *device = (struct iio_device*)msg->reserved;
    struct channel *channel = device->channel;
    int retry = 0;
    int do_failover = 0;
    int error;

    ck_spinlock_lock(&device->slock);
    device->active_msg_count --;
    error = msg->hinfo.err;
    if (error == QNIOERROR_HUP) {
        nioDbg("QNIOERROR_HUP received on msgid=%ld %p",msg->hinfo.cookie, msg);
        switch (device->state) {
        case IIO_DEVICE_ACTIVE:
            device->state = IIO_DEVICE_QUIESCE;
            /* Continue */

        case IIO_DEVICE_QUIESCE:
        case IIO_DEVICE_FAILOVER:
            device->retry_msg_count ++;
            device->active_msg_count ++;
            channel->cd->chdrv_msg_resend_cleanup(msg);
            LIST_ADD(&device->retryq, &msg->lnode);
            retry = 1;
            break;

        case IIO_DEVICE_FAILED:
            break;

        default:
            nioDbg("Unknown device state");
            break;
        }
    } else if (error) {
        nioDbg("message failed with error %d", error);
    }

    if (device->state == IIO_DEVICE_QUIESCE &&
        device->active_msg_count == device->retry_msg_count) {
        device->state = IIO_DEVICE_FAILOVER;
        do_failover = 1;
    }
    ck_spinlock_unlock(&device->slock);

    if (do_failover) {
        iio_device_failover(device);
    }

    return retry;
}
예제 #20
0
static void
pool_buffer_destroy(struct pb_buffer *buf)
{
   struct pool_buffer *pool_buf = pool_buffer(buf);
   struct pool_pb_manager *pool = pool_buf->mgr;
   
   assert(!pipe_is_referenced(&pool_buf->base.reference));

   pipe_mutex_lock(pool->mutex);
   LIST_ADD(&pool_buf->head, &pool->free);
   pool->numFree++;
   pipe_mutex_unlock(pool->mutex);
}
예제 #21
0
파일: node.c 프로젝트: dardevelin/utu
inline Node *Node_create(Node *parent, enum NodeType type) 
{
  Node *node = node_test_calloc();
  assert_mem(node);

  node->type = type;

  // now just add the new node on to the current's children
  if(parent) {
    node->parent = parent;
    LIST_ADD(Node, parent->child, node, sibling);
  }

  return node;
}
예제 #22
0
int usb_os_find_busses(struct usb_bus **busses)
{
    struct usb_bus *fbus = NULL;
    DIR *dir;
    struct dirent *entry;

    dir = opendir(usb_path);
    if (!dir)
        USB_ERROR_STR(-errno, "couldn't opendir(%s): %s", usb_path,
                      strerror(errno));

    while ((entry = readdir(dir)) != NULL)
    {
        struct usb_bus *bus;

        /* Skip anything starting with a . */
        if (entry->d_name[0] == '.')
            continue;

        if (!strchr("0123456789", entry->d_name[strlen(entry->d_name) - 1]))
        {
            if (usb_debug >= 2)
                fprintf(stderr, "usb_os_find_busses: Skipping non bus directory %s\n",
                        entry->d_name);
            continue;
        }

        bus = malloc(sizeof(*bus));
        if (!bus)
            USB_ERROR(-ENOMEM);

        memset((void *)bus, 0, sizeof(*bus));

        strncpy(bus->dirname, entry->d_name, sizeof(bus->dirname) - 1);
        bus->dirname[sizeof(bus->dirname) - 1] = 0;

        LIST_ADD(fbus, bus);

        if (usb_debug >= 2)
            fprintf(stderr, "usb_os_find_busses: Found %s\n", bus->dirname);
    }

    closedir(dir);

    *busses = fbus;

    return 0;
}
예제 #23
0
/**
 * Put a descriptor entry back by moving it from the use to the free list.
 * @param   desc    descriptor
 */
static void unvme_put_desc(unvme_desc_t* desc)
{
    unvme_queue_t* ioq = desc->ioq;

    if (ioq->descnext == desc) {
        if (desc != desc->next) ioq->descnext = desc->next;
        else ioq->descnext = NULL;
    }

    LIST_DEL(ioq->desclist, desc);
    memset(desc, 0, sizeof(unvme_desc_t) + ioq->ses->masksize);
    desc->ioq = ioq;
    LIST_ADD(ioq->descfree, desc);

    ioq->desccount--;
}
예제 #24
0
파일: port.c 프로젝트: 1tgr/mobius
status_t PortLookupFile(fsd_t *fsd, vnode_id_t node, uint32_t open_flags, 
                        void **cookie)
{
    port_fsd_t *pfsd;
    port_t *server, *client;
    port_waiter_t *waiter;
    pipe_t *ends[2];

    pfsd = (port_fsd_t*) fsd;
    if (node == VNODE_ROOT)
        return EACCESS;

    server = (port_t*) node;
    assert(server->is_server);

    client = malloc(sizeof(port_t));
    if (client == NULL)
        goto error0;

    waiter = malloc(sizeof(port_waiter_t));
    if (waiter == NULL)
        goto error1;

    if (!FsCreatePipeInternal(ends))
        goto error2;

    memset(client, 0, sizeof(*client));
    memset(waiter, 0, sizeof(*waiter));
    client->is_server = false;
    waiter->end_client = client->u.client = ends[0];
    waiter->end_server = ends[1];

    SpinAcquire(&server->u.server.sem);
    LIST_ADD(server->u.server.waiter, waiter);
    SpinRelease(&server->u.server.sem);

    *cookie = client;
    PortWakeBlockedAcceptors(server);
    return 0;

error2:
    free(waiter);
error1:
    free(client);
error0:
    return errno;
}
예제 #25
0
jobject vector_Ptr_Layer_to_List(JNIEnv* env, std::vector<cv::Ptr<cv::dnn::Layer> >& vs)
{
    static jclass juArrayList   = ARRAYLIST(env);
    static jmethodID m_create   = CONSTRUCTOR(env, juArrayList);
    jmethodID m_add       = LIST_ADD(env, juArrayList);

    static jclass jLayerClass = LAYER(env);
    static jmethodID m_create_layer = LAYER_CONSTRUCTOR(env, jLayerClass);

    jobject result = env->NewObject(juArrayList, m_create, vs.size());
    for (std::vector< cv::Ptr<cv::dnn::Layer> >::iterator it = vs.begin(); it != vs.end(); ++it) {
        jobject element = env->NewObject(jLayerClass, m_create_layer, (*it).get());
        env->CallBooleanMethod(result, m_add, element);
        env->DeleteLocalRef(element);
    }
    return result;
}
예제 #26
0
static bool add_pawn_moves(list_t * list, const board_t * board, int to, bool legal, bool stop) {

   int me;
   int inc;
   int pawn;
   int from;
   int piece;

   ASSERT(list!=NULL);
   ASSERT(board!=NULL);
   ASSERT(SQUARE_IS_OK(to));
   ASSERT(legal==true||legal==false);
   ASSERT(stop==true||stop==false);

   ASSERT(board->square[to]==Empty);

   me = board->turn;

   inc = PAWN_MOVE_INC(me);
   pawn = PAWN_MAKE(me);

   from = to - inc;
   piece = board->square[from];

   if (piece == pawn) { // single push

      if (!legal || !is_pinned(board,from,me)) {
         if (stop) return true;
         add_pawn_move(list,from,to);
      }

   } else if (piece == Empty && PAWN_RANK(to,me) == Rank4) { // double push

      from = to - (2*inc);
      if (board->square[from] == pawn) {
         if (!legal || !is_pinned(board,from,me)) {
            if (stop) return true;
            ASSERT(!SQUARE_IS_PROMOTE(to));
            LIST_ADD(list,MOVE_MAKE(from,to));
         }
      }
   }

   return false;
}
예제 #27
0
파일: device.c 프로젝트: 1tgr/mobius
static void DevCallLoader(load_request_t *load)
{
    event_t *evt_done;

    evt_done = EvtCreate(false);
    load->evt_done = evt_done;

    SemDown(mux_load);
    LIST_ADD(load, load);
    SemUp(mux_load);

    wprintf(L"DevCallLoader: submitting request\n");
    SemUp(sem_load);
    ThrWaitHandle(current(), &evt_done->hdr);
    KeYield();

    HndClose(&evt_done->hdr);
}
예제 #28
0
static int find_devices(libusb_device **dev_list, int dev_list_len,
	struct usb_bus *bus, struct usb_device **ret)
{
	struct usb_device *devices = NULL;
	struct usb_device *dev;
	int i;
	
	for (i = 0; i < dev_list_len; i++) {
		libusb_device *newlib_dev = dev_list[i];
		uint8_t bus_num = libusb_get_bus_number(newlib_dev);
		
		if (bus_num != bus->location)
			continue;
		
		dev = malloc(sizeof(*dev));
		if (!dev)
			goto err;

		/* No need to reference the device now, just take the pointer. We
		 * increase the reference count later if we keep the device. */
		 
		dev->dev = newlib_dev;

		dev->bus = bus;
		dev->devnum = libusb_get_device_address(newlib_dev);
		sprintf(dev->filename, "%03d", dev->devnum);
		LIST_ADD(devices, dev);
	}

	*ret = devices;
	return 0;

err:
	dev = devices;
	
	while (dev) {
		struct usb_device *tdev = dev->next;
		free(dev);
		dev = tdev;
	}
	return -ENOMEM;
}
예제 #29
0
static int32_t
iio_msg_submit(struct iio_device *device, struct qnio_msg *msg, uint32_t flags)
{
    int32_t err;
    int retry;
    struct channel *channel;

    nioDbg("iio_msg_submit: msg=%p, usr_ctx=%p, opcode=%d",
           msg, msg->user_ctx, (int)msg->hinfo.opcode);
    ck_spinlock_lock(&device->slock);
    if (device->state == IIO_DEVICE_FAILED) {
        ck_spinlock_unlock(&device->slock);
        msg->hinfo.err = QNIOERROR_NOCONN;
        errno = ENXIO;
        return -1;
    }
    device->active_msg_count ++;
    if (device->state == IIO_DEVICE_FAILOVER ||
        device->state == IIO_DEVICE_QUIESCE) {
        device->retry_msg_count ++;
        LIST_ADD(&device->retryq, &msg->lnode);
        ck_spinlock_unlock(&device->slock);
        return 0;
    }
    ck_spinlock_unlock(&device->slock); 
    if(flags & IIO_FLAG_ASYNC) {
        msg->hinfo.flags |= QNIO_FLAG_REQ;
    } else {
        msg->hinfo.flags |= QNIO_FLAG_SYNC_REQ;
    }
    msg->reserved = device;
    channel = device->channel;
    err = channel->cd->chdrv_msg_send(channel, msg);
    if(err != 0) {
        retry = iio_msg_done(msg);
        if (retry) {
            err = 0;
        }
    }
    return err;
}
예제 #30
0
파일: bsd.c 프로젝트: withwave/RT5350
int usb_os_find_busses(struct usb_bus **busses)
{
    struct usb_bus *fbus = NULL;
    int controller;
    int fd;
    char buf[20];

    for (controller = 0; controller < MAX_CONTROLLERS; controller++) {
        struct usb_bus *bus;

        snprintf(buf, sizeof(buf) - 1, "/dev/usb%d", controller);
        fd = open(buf, O_RDWR);
        if (fd < 0) {
            if (usb_debug >= 2)
                if (errno != ENXIO && errno != ENOENT)
                    fprintf(stderr, "usb_os_find_busses: can't open %s: %s\n",
                            buf, strerror(errno));
            continue;
        }
        close(fd);

        bus = malloc(sizeof(*bus));
        if (!bus)
            USB_ERROR(-ENOMEM);

        memset((void *)bus, 0, sizeof(*bus));

        strncpy(bus->dirname, buf, sizeof(bus->dirname) - 1);
        bus->dirname[sizeof(bus->dirname) - 1] = 0;

        LIST_ADD(fbus, bus);

        if (usb_debug >= 2)
            fprintf(stderr, "usb_os_find_busses: Found %s\n", bus->dirname);
    }

    *busses = fbus;

    return 0;
}