static void
remove_shader_variant(struct llvmpipe_context *lp,
                      struct lp_fragment_shader_variant *variant)
{
   struct llvmpipe_screen *screen = llvmpipe_screen(lp->pipe.screen);
   unsigned i;

   if (gallivm_debug & GALLIVM_DEBUG_IR) {
      debug_printf("llvmpipe: del fs #%u var #%u v created #%u v cached #%u v total cached #%u\n",
                    variant->shader->no, variant->no, variant->shader->variants_created,
                    variant->shader->variants_cached, lp->nr_fs_variants);
   }
   for (i = 0; i < Elements(variant->function); i++) {
      if (variant->function[i]) {
         if (variant->jit_function[i])
            LLVMFreeMachineCodeForFunction(screen->engine,
                                           variant->function[i]);
         LLVMDeleteFunction(variant->function[i]);
      }
   }
   remove_from_list(&variant->list_item_local);
   variant->shader->variants_cached--;
   remove_from_list(&variant->list_item_global);
   lp->nr_fs_variants--;
   FREE(variant);
}
示例#2
0
文件: mud_event.c 项目: axanon/tbamud
void free_mud_event(struct mud_event_data *pMudEvent)
{
  struct descriptor_data * d;
  struct char_data * ch;

  switch (mud_event_index[pMudEvent->iId].iEvent_Type) {
    case EVENT_WORLD:
      remove_from_list(pMudEvent->pEvent, world_events);
    break;
    case EVENT_DESC:
      d = (struct descriptor_data *) pMudEvent->pStruct;
      remove_from_list(pMudEvent->pEvent, d->events);
    break;
    case EVENT_CHAR:
      ch = (struct char_data *) pMudEvent->pStruct;
      remove_from_list(pMudEvent->pEvent, ch->events);
    break;
  }

  if (pMudEvent->sVariables != NULL)
    free(pMudEvent->sVariables);

  pMudEvent->pEvent->event_obj = NULL;
  free(pMudEvent);
}
示例#3
0
文件: mm.c 项目: val-litvak/malloclab
/**
 * coalesce - Concatenate adjacent blocks to prevent fragmentation.
 *
 * Should upkeep the free list. Assumes that bp is a free block.
 * Also assumes that bp has not yet been added to a free list.
 */
static void *coalesce(void *bp)
{
	size_t prev_alloc = GET_PREVALLOC(bp);
	size_t next_alloc = GET_NEXTALLOC(bp);
	size_t size = GET_THISSIZE(bp);
	char *next_block = GET_NEXTBLOCK(bp);
	char *prev_block = GET_PREVBLOCK(bp);

	TRACE(">>>Entering coalesce(bp=0x%X)\n", (unsigned int)bp);

	/* Case 1, Both blocks allocated, does not need its own if statement */
	if (prev_alloc && !next_alloc) { /* Case 2: only next_block is free */
		remove_from_list(next_block, calc_list_index(GET_THISSIZE(next_block)));

		/* Only need to update the size field */
		size += GET_SIZE(GET_BLOCKHDR(next_block));

		PUTW(GET_BLOCKHDR(bp), PACK(size, prev_alloc));
		PUTW(GET_BLOCKFTR(bp), PACK(size, prev_alloc));
	}

	else if (!prev_alloc && next_alloc) { /* Case 3: only prev_block is free */
		remove_from_list(prev_block, calc_list_index(GET_THISSIZE(prev_block)));

		/* Need to update the size and prev_alloc field */
		size += GET_THISSIZE(prev_block);
		prev_alloc = GET_PREVALLOC(prev_block);

		PUTW(GET_BLOCKFTR(bp), PACK(size, prev_alloc));
		PUTW(GET_BLOCKHDR(prev_block), PACK(size, prev_alloc));
		bp = prev_block;
	}

	else if (!prev_alloc && !next_alloc) { /* Case 4: Both blocks are free */
		remove_from_list(next_block, calc_list_index(GET_THISSIZE(next_block)));
		remove_from_list(prev_block, calc_list_index(GET_THISSIZE(prev_block)));

		/* Need to update the size and prev_alloc field */
		size += GET_THISSIZE(prev_block) + GET_THISSIZE(next_block);
		prev_alloc = GET_PREVALLOC(prev_block);

		PUTW(GET_BLOCKHDR(GET_PREVBLOCK(bp)), PACK(size, prev_alloc));
		PUTW(GET_BLOCKFTR(GET_NEXTBLOCK(bp)), PACK(size, prev_alloc));
		bp = GET_PREVBLOCK(bp);
	}

	/* coalesce() is always called after a block is marked free
		so it needs to add the block to the appropriate free list */
	add_to_list(bp, calc_list_index(size));
	TRACE("<<<---Leaving coalesce()\n");
	return bp;
}
示例#4
0
文件: test.c 项目: kl0ss/java2pic
int main()
{
    printf("Testing lists...\n");
    List *list = (List *) create_list();
    assert(list != NULL);
    assert(list->data == NULL);
    assert(list->next == NULL);

    int w = 42;
    int x = 1;
    int y = 2;
    int z = 3;

    append_to_list(list, &x);
    assert(*(int *)(list->data) == 1);
    assert(list->next != NULL);

    append_to_list(list, &y);
    assert(*(int *)(list->next->data) == 2);
    assert(list->next->next != NULL);
    
    append_to_list(list, &z);
    assert(*(int *)(list->next->next->data) == 3);
    assert(list->next->next->next != NULL);

    assert(list->next->next->next->data == NULL);
    assert(list->next->next->next->next == NULL);


    list = (List *) push_to_list(list, &w);
    assert(*(int *)(list->data) == 42);
    assert(list->next != NULL);

    list = (List *) pop_from_list(list);
    assert(*(int *)(list->data) == 1);

    assert(list_length(list) == 3);
    assert(list_index(list, &y) == 1);
    assert(list_index(list, &w) == -1);
   
    list = remove_from_list(list, &x);
    assert(*(int *)(list->data) == 2);

    list = push_to_list(list, &x);
    list = remove_from_list(list, &y);
    assert(*(int *)(list->next->data) == 3);

    printf("List tests passed\n");
    return 0;
}
示例#5
0
/*
 * Allocates a page off one of our lists.
 *
 * Parameters:
 * - uiFlags = Flags for the page allocation.
 *
 * Returns:
 * INVALID_PAGE if the page could not be allocated, otherwise the index of the allocated page.
 */
static UINT32 allocate_page(UINT32 uiFlags)
{
  UINT32 rc;
  PPAGELIST ppgl = NULL;
  BOOL bZero = FALSE;

  if (uiFlags & PGALLOC_ZERO)
  { /* try zeroed list first, then free (but need to zero afterwards) */
    if (g_pglZeroed.cpg > 0)
      ppgl = &g_pglZeroed;
    else if (g_pglFree.cpg > 0)
    {
      ppgl = &g_pglFree;
      bZero = TRUE;
    }
  }
  else
  { /* try free list first, then zeroed */
    if (g_pglFree.cpg > 0)
      ppgl = &g_pglFree;
    else if (g_pglZeroed.cpg > 0)
      ppgl = &g_pglZeroed;
  }
  /* TODO: apply additional strategy if we don't yet have a page list */

  if (!ppgl)
    return INVALID_PAGE;
  rc = g_pMasterPageDB[ppgl->ndxLast].d.next;  /* take first page on list */
  remove_from_list(ppgl, rc);
  if (bZero)
    zero_page(rc);
  return rc;
}
示例#6
0
	void bin_index_t::file_node::remove_oldest()
	{
		for(page_wptr wp=last_page;pages.size()>=max_pages&&!wp.expired();)
		{
			page_ptr r;
			page_ptr l;

			{
				page_ptr p=wp.lock();
				r=p->right.lock();
				l=p->left.lock();
				flush_page(*p);
				pages.erase(p->page_offset);
				remove_from_list(p);
			}

			//Somebody still use this page and we can't delete it
			if(!wp.expired())
			{
				page_ptr p=wp.lock();
				pages[p->page_offset]=p;
				insert_into_list(p,r);
			}

			wp=l;
		}
	}
示例#7
0
static void
llvmpipe_resource_destroy(struct pipe_screen *pscreen,
                          struct pipe_resource *pt)
{
   struct llvmpipe_screen *screen = llvmpipe_screen(pscreen);
   struct llvmpipe_resource *lpr = llvmpipe_resource(pt);

   if (lpr->dt) {
      /* display target */
      struct sw_winsys *winsys = screen->winsys;
      winsys->displaytarget_destroy(winsys, lpr->dt);
   }
   else if (llvmpipe_resource_is_texture(pt)) {
      /* free linear image data */
      if (lpr->linear_img.data) {
         align_free(lpr->linear_img.data);
         lpr->linear_img.data = NULL;
      }
   }
   else if (!lpr->userBuffer) {
      assert(lpr->data);
      align_free(lpr->data);
   }

#ifdef DEBUG
   if (lpr->next)
      remove_from_list(lpr);
#endif

   FREE(lpr);
}
示例#8
0
void Free(void *ptr)
#endif
{
    if (ptr != NULL) {
#ifdef MEMORY_DEBUG
	memory_block *block_ptr = NULL;
	block_ptr = (memory_block*)(void*)((unsigned char*)ptr - offset);
#ifdef MEMORY_DEBUG_ADDRESS
        check_memory_address(block_ptr, 2);
#endif
	check_magic_values(filename, line, block_ptr, 0);
	remove_from_list(block_ptr);
	allocated_size -= block_ptr->size;
	memset(ptr, 0xAA, block_ptr->size);
#ifdef MEMORY_DEBUG_FREE
	add_to_free_list(block_ptr);
#else
	free(block_ptr);
#endif
#else
	free(ptr);
#endif
	free_count++;
    }
}
示例#9
0
char *sort_list(char *inlist, int inlist_size) {
	char *tmplist;
	char tmp[IFNAMSIZ];

	if (!inlist_size) return NULL;
	if (!inlist) return NULL;

	tmplist = (char *) malloc(inlist_size);
	if (!tmplist) return NULL;
	memset(tmplist, 0, inlist_size);

	char *b;
	int len;
	while ((b = find_smallest_in_list(inlist)) != NULL) {
		len = strcspn(b, " ");
		snprintf(tmp, len + 1, "%s", b);

		add_to_list(tmp, tmplist, inlist_size);
		remove_from_list(tmp, inlist, inlist_size);

	}
	strncpy(inlist, tmplist, inlist_size);

	free(tmplist);
	return inlist;
}
示例#10
0
void clean_up_unknown() 
{
    if(verbose_lvl)
	cout << indent(2) << "Cleaning up invalid hosts." << endl;
    
    // create a list of all links from an unknown to a node, and a list of
    // links from a node to an unkown and store them in a map
    LinkMap to_u;
    LinkMap from_u;
    fill_maps(network, to_u, from_u);
    
    // give all members of an non-empty intersection, of two elements of both
    // maps, the same name
    for(LinkMap_iter to_iter = to_u.begin(); to_iter != to_u.end(); to_iter++)
	for(LinkMap_iter from_iter = from_u.begin(); from_iter != from_u.end();
	    from_iter++)
	    if(to_iter->first->name() != from_iter->first->name()) {
		
		HostPList hl = intersect(to_iter->second, from_iter->second);
		
		if(!hl.empty())
		    equilize_names(network, hl);
	    }
    
    // clean up trash
    remove_from_list(hostlist, trash);

    network.sort();
    network.unique();    
}
示例#11
0
文件: handler.c 项目: Lundessa/raven3
void leave_group(struct char_data *ch)
{
  struct group_data *group;
  struct char_data *tch;
  struct iterator_data Iterator;
  bool found_pc = FALSE;
	
  if ((group = ch->group) == NULL)
    return;

  send_to_group(NULL, group, "%s has left the group.\r\n", GET_NAME(ch));

  remove_from_list(ch, group->members);
  ch->group = NULL;
  
  if (group->members->iSize) {
    for (tch = (struct char_data *) merge_iterator(&Iterator, group->members);
      tch; tch = next_in_list(&Iterator))
        if (!IS_NPC(tch)) 
          found_pc = TRUE;
          
    remove_iterator(&Iterator);  
  }

  if (!found_pc)
    SET_BIT(GROUP_FLAGS(group), GROUP_NPC);
  
  if (GROUP_LEADER(group) == ch && group->members->iSize) {
    group->leader = (struct char_data *) random_from_list(group->members);
    send_to_group(NULL, group, "%s has assumed leadership of the group.\r\n", GET_NAME(GROUP_LEADER(group)));
  } else if (group->members->iSize == 0)
    free_group(group); 
}
示例#12
0
文件: mm.c 项目: val-litvak/malloclab
/**
 * allocate - Place block, i.e. write header and footer.
 */
static void allocate(void *bp, size_t adjusted_size)
{
	size_t csize = GET_THISSIZE(bp);
	size_t is_prev_alloc = GET_PREVALLOC(bp);

	TRACE(">>>Entering allocate(bp=0x%X, adjusted_size=%u)\n", (unsigned int)bp, adjusted_size);

	/* We will always need to remove tshi block from the free list */
	remove_from_list(bp, calc_list_index(csize));

	/* See if there's room to split this block into two */
	if ((csize - adjusted_size) >= (MIN_SIZE)) {
		PUTW(GET_BLOCKHDR(bp), PACK(adjusted_size, THISALLOC | is_prev_alloc));
		PUTW(GET_BLOCKFTR(bp), PACK(adjusted_size, THISALLOC | is_prev_alloc));

		/* Using the new header info, mark the newly created block as free */
		bp = GET_NEXTBLOCK(bp);
		PUTW(GET_BLOCKHDR(bp), PACK(csize - adjusted_size, PREVALLOC));
		PUTW(GET_BLOCKFTR(bp), PACK(csize - adjusted_size, PREVALLOC));

		/* And add it to the appropriate free list */
		coalesce(bp);
	}
	else {/* If there's not room to create split the block, just extend the
		 	amount to allocated */
		PUTW(GET_BLOCKHDR(bp), PACK(csize, THISALLOC | is_prev_alloc));
		PUTW(GET_BLOCKFTR(bp), PACK(csize, THISALLOC | is_prev_alloc));

		/* Make sure the next block's header has the prevalloc field marked */
		bp = GET_BLOCKHDR(GET_NEXTBLOCK(bp));
		PUTW(bp, GETW(bp) | PREVALLOC);
	}
	TRACE("<<<---Leaving allocate()\n");
}
示例#13
0
int main(int argc, const char *argv[])
{
    TContact_list contact_list = {contact_list.first = NULL, contact_list.last = NULL};
    get_dir();
    
    switch(get_mode(argc, argv)){
        case DEL:
            get_data(&contact_list);
            remove_from_list(&contact_list, atoi(argv[2]));
            save_csv(&contact_list);
            generate_html(&contact_list);
            free_list(&contact_list);
            break;
        case ADD:
            get_data(&contact_list);
            add_to_list(argv, &contact_list);
            sort_list(&contact_list);
            save_csv(&contact_list);
            generate_html(&contact_list);
            free_list(&contact_list);
            break;
        case LIST:
            get_data(&contact_list);
            sort_list(&contact_list);
            print_list(&contact_list);
            save_csv(&contact_list);
            generate_html(&contact_list);
            free_list(&contact_list);
            break;
        case SIN:
            get_data(&contact_list);
            print_single(&contact_list, atoi(argv[2]));
            free_list(&contact_list);
            break;
        case FIND:
            get_data(&contact_list);
            find_in_list(&contact_list, (char *)argv[2]);
            generate_html(&contact_list);
            free_list(&contact_list);
            break;
        case PLIST:
            get_data(&contact_list);
            sort_list(&contact_list);
            generate_plist(&contact_list);
            free_list(&contact_list);
            break;
        case DELN:
            get_data(&contact_list);
            delete_by_name(&contact_list, (char *)argv[2], (char *)argv[3]);
            save_csv(&contact_list);
            generate_html(&contact_list);
            free_list(&contact_list);
        default:
            handle_errors();
            return EXIT_FAILURE;
    }
    if(handle_errors() != EXIT_SUCCESS) return EXIT_FAILURE;
    else return EXIT_SUCCESS;
}
示例#14
0
static void free_funcs( struct _tnl_dynfn *l )
{
   struct _tnl_dynfn *f, *tmp;
   foreach_s (f, tmp, l) {
      remove_from_list( f );
      ALIGN_FREE( f->code );
      FREE( f );
   }
示例#15
0
/* This function is called when the virtual memory system unmaps a page from
 * the virtual address space.  Remove the page from the list of resident
 * pages.
 */
void policy_page_unmapped(page_t page) {
    pageinfo_t *pginfo, *prev;

    pginfo = find_page(&pagelist, page, &prev);
    assert(pginfo != NULL);

    remove_from_list(&pagelist, pginfo, prev);
}
示例#16
0
static void free_funcs( struct dynfn *l )
{
   struct dynfn *f, *tmp;
   foreach_s (f, tmp, l) {
      remove_from_list( f );
      _mesa_exec_free( f->code );
      _mesa_free( f );
   }
示例#17
0
//创建UDP,接收设备的消息
void recvDevicemsg(void ) {
	short msgtype;
	char buf[300] ;
	int len, err;
	const int on = 1;
	memset(buf, 0, 300);
	
	while(1) {
		//阻塞在这里接受消息
		len = recvfrom(bsockfd, buf, 300, 0, NULL, NULL);
		memcpy(&msgtype, buf, 2);
		int ip ;	
		memcpy(&ip, buf+2, 4);
		
		char name[22];
		memcpy(&name, buf+6, 22);
		name[21] = '\0';
		
		char id[13];
		memcpy(&id, buf+28, 13);
		id[12] = '\0';
		printf("msgtype = %d\n", msgtype);
		printf("ip = %d\n", ip);
		printf("name = %s\n", name);
		printf("id = %s\n", id);
		//printf("id = %s\n", buf);
		int i;
		
		printf("UDP接收%s \n", strerror(errno));
		printf("收到消息:%s\n", buf); 
		//收到消息:smartlinkfind
		
			//msgtype = 0x0002;
	//如果msgtype == 0x0002 将消息当作设备消息处理
	if (msgtype == 0x0002) {
		//申请空间创建节点 将设备信息存入到链表中 乘以2 倍以后free不会出错
		pdevice_node pnode =(pdevice_node)malloc(sizeof(device_node)*2);
		pnode->pNext = NULL;
		//memcpy(pnode->device_id, "123456", 7);
		memcpy(pnode, buf+2, 284);

		//通过id查找链表中的此设备, 删除此设备,重新加入新的节点信息
		printf("%s\n", pnode->device_id);
		printf("%s\n", pnode->name);
		int data;
		memcpy(&data, buf+66, 4);
		printf("参数的值data = %d\n", data);
		printf("参数的值buf[66] = %d\n", buf[66]);
		pnode->online = 'y';
		printf("pnode->online:%c\n", pnode->online);
		remove_from_list(device_link, pnode->device_id);

		list_add(device_link, pnode);
	}

	}

}
示例#18
0
文件: lp_texture.c 项目: ideak/mesa
static void
llvmpipe_resource_destroy(struct pipe_screen *pscreen,
			  struct pipe_resource *pt)
{
   struct llvmpipe_screen *screen = llvmpipe_screen(pscreen);
   struct llvmpipe_resource *lpr = llvmpipe_resource(pt);

   if (lpr->dt) {
      /* display target */
      struct sw_winsys *winsys = screen->winsys;
      winsys->displaytarget_destroy(winsys, lpr->dt);

      if (lpr->tiled[0].data) {
         align_free(lpr->tiled[0].data);
         lpr->tiled[0].data = NULL;
      }

      FREE(lpr->layout[0]);
   }
   else if (resource_is_texture(pt)) {
      /* regular texture */
      uint level;

      /* free linear image data */
      for (level = 0; level < Elements(lpr->linear); level++) {
         if (lpr->linear[level].data) {
            align_free(lpr->linear[level].data);
            lpr->linear[level].data = NULL;
         }
      }

      /* free tiled image data */
      for (level = 0; level < Elements(lpr->tiled); level++) {
         if (lpr->tiled[level].data) {
            align_free(lpr->tiled[level].data);
            lpr->tiled[level].data = NULL;
         }
      }

      /* free layout flag arrays */
      for (level = 0; level < Elements(lpr->tiled); level++) {
         FREE(lpr->layout[level]);
         lpr->layout[level] = NULL;
      }
   }
   else if (!lpr->userBuffer) {
      assert(lpr->data);
      align_free(lpr->data);
   }

#ifdef DEBUG
   if (lpr->next)
      remove_from_list(lpr);
#endif

   FREE(lpr);
}
示例#19
0
static int nntpdriver_unsubscribe_folder(mailsession * session, const char * mb)
{
  int r;

  r = remove_from_list(session, mb);
  if (r < 0)
    return MAIL_ERROR_UNSUBSCRIBE;

  return MAIL_NO_ERROR;
}
示例#20
0
文件: proxy.c 项目: samzcmu/proxy
/* add_to_list takes a cell and adds that cell the
 * the cache list. It locks the cache for writing so
 * that other threads cannot modify it. */
void add_to_list(struct cache_cell *cell)
{
	/* locks the cache for writing */
	Pthread_rwlock_wrlock(&cache_lock);
	/* if there is enough space in the cache,
	 * no eviction is needed. */
	if (cache_size + cell->size <= MAX_CACHE_SIZE)
	{
		cell->next = head;
		if (head != NULL)
			head->previous = cell;
		head = cell;
		cache_size += cell->size;
		cell->last_use = cache_time;
		
		Pthread_mutex_lock(&time_mutex);
		cache_time++;
		Pthread_mutex_unlock(&time_mutex);
	}
	/* if there is not enough space in the cache,
	 * eviction is needed. */
	else
	{
		struct cache_cell *tmp_cell, *ptr;
		int tmp_last_use;
		
		/* remove elements from cache so that there is enough
		 * space in the cache. */
		while (!(cache_size + cell->size <= MAX_CACHE_SIZE))
		{
			tmp_last_use = cache_time + 1;
			for (ptr = head; ptr != NULL; ptr = ptr->next)
				if (ptr->last_use < tmp_last_use)
				{
					tmp_last_use = ptr->last_use;
					tmp_cell = ptr;
				}
			remove_from_list(tmp_cell);
		}
		
		/* add cell to cache */
		cell->next = head;
		if (head != NULL)
			head->previous = cell;
		head = cell;
		cache_size += cell->size;
		cell->last_use = cache_time;
		
		Pthread_mutex_lock(&time_mutex);
		cache_time++;
		Pthread_mutex_unlock(&time_mutex);
	}
	Pthread_rwlock_unlock(&cache_lock);
	return;
}
示例#21
0
文件: list.c 项目: ailin-nemui/epic5
/*
 * list_lookup: this routine just consolidates remove_from_list and
 * find_in_list.  I did this cause it fit better with some alread existing
 * code 
 */
List 	*list_lookup (List **list, const char *name, int wild, int rem)
{
	List	*tmp;

	if (rem)
		tmp = remove_from_list(list, name);
	else
		tmp = find_in_list(list, name, wild);

	return (tmp);
}
示例#22
0
文件: init.c 项目: hww3/pexts
static int parse_unlist (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
{
  do
  {
    mutt_extract_token (buf, s, 0);
    remove_from_list ((LIST **) data, buf->data);
  }
  while (MoreArgs (s));

  return 0;
}
示例#23
0
static Logfile *	logfile_remove (Logfile *log, char **args)
{
	char 		*arg = next_arg(*args, args);
	char            *ptr;
	WNickList       *new_nl;
	int		i;

	if (!log)
	{
		say("REMOVE: You need to specify a logfile first");
		return NULL;
	}

        if (!arg)
                say("Remove: Remove nicknames/channels logged to this file");

	else while (arg)
        {
	        if ((ptr = strchr(arg, ',')) != NULL)
			*ptr++ = 0;

		if (log->type == LOG_TARGETS)
		{
		    if ((new_nl = (WNickList *)remove_from_list((List **)&(log->targets), arg)))
		    {
			say("Removed %s from log target list", new_nl->nick);
			new_free(&new_nl->nick);
			new_free((char **)&new_nl);
		    }
		    else
			say("%s is not on the list for this log!", arg);
		}
		else if (log->type == LOG_SERVERS || log->type == LOG_WINDOWS)
		{
		    int refnum = my_atol(ptr);

		    for (i = 0; i < MAX_TARGETS; i++)
		    {
			if (log->refnums[i] == refnum)
			{
				say("Removed %d to log refnum list", refnum);
				log->refnums[i] = -1;
				break;
			}
		    }
		    if (i >= MAX_TARGETS)
			say("%s is not on the refnum list for this log!", arg);
		}

		arg = ptr;
        }

        return log;
}
示例#24
0
文件: locks.c 项目: chenbk85/jega
static PyObject*
condition_notify(ConditionObject *self, int num)
{
    PyObject *res, *waiters;
    PyObject *iter, *item;
    
    DEBUG("self:%p", self);
    res = call_method((PyObject*)self, "_is_owned");
    if (res == NULL) {
        return NULL;
    }
    
    if (PyObject_Not(res)) {
        Py_DECREF(res);
        PyErr_SetString(PyExc_RuntimeError, "cannot release un-acquired lock");
        return NULL;
    }
    Py_DECREF(res);
    waiters = PyList_GetSlice(self->waiters, 0, num);
    if (waiters == NULL) {
        return NULL;
    }
    if (PyObject_Not(waiters)) {
        Py_RETURN_NONE;
    }

    iter = PyObject_GetIter(waiters);
    if (PyErr_Occurred()) {
        return NULL;
    }

    while ((item =  PyIter_Next(iter))) {
        res = semaphore_release((SemaphoreObject*)item);
        Py_XDECREF(res);
        if (res == NULL) {
            Py_DECREF(item);
            goto err;
        }
        if (remove_from_list((PyListObject*)self->waiters, item) == -1) {
            Py_DECREF(item);
            goto err;
        }
        Py_DECREF(item);
        /* DEBUG("self->waiters len:%d", PyList_Size(self->waiters)); */
    }
    Py_DECREF(waiters);
    Py_DECREF(iter);
    Py_RETURN_NONE;
err:
    Py_DECREF(waiters);
    Py_DECREF(iter);
    return NULL;

}
示例#25
0
/* dispose of a menu */
VOID StMObDispose P1C(LVAL, menu)
{
  LVAL menu_list;
  
  if (StMObAllocated(menu)) StMObDisposeMach(menu);
  standard_hardware_clobber(menu);

  menu_list = GetMenuList();
  menu_list = remove_from_list(menu, menu_list);
  SetMenuList(menu_list);
}
示例#26
0
/* delete item from the list */
static VOID delete_menu_item P2C(LVAL, menu, LVAL, item)
{
  LVAL item_list;
   
  StMObDeleteItem(menu, item);
  
  item_list = slot_value(menu, s_items);
  item_list = remove_from_list(item, item_list);
  set_slot_value(menu, s_items,item_list);
  set_slot_value(item, s_menu, NIL);
}
示例#27
0
文件: init.c 项目: hww3/pexts
static int parse_ignore (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
{
  do
  {
    mutt_extract_token (buf, s, 0);
    remove_from_list (&UnIgnore, buf->data);
    add_to_list (&Ignore, buf->data);
  }
  while (MoreArgs (s));

  return 0;
}
示例#28
0
void free_mud_event(struct mud_event_data *pMudEvent)
{
  struct descriptor_data * d;
  struct char_data * ch;
  struct room_data * room;

  switch (mud_event_index[pMudEvent->iId].iEvent_Type) {
    case EVENT_WORLD:
      remove_from_list(pMudEvent->pEvent, world_events);
    break;
    case EVENT_DESC:
      d = (struct descriptor_data *) pMudEvent->pStruct;
      remove_from_list(pMudEvent->pEvent, d->events);
    break;
    case EVENT_CHAR:
      ch = (struct char_data *) pMudEvent->pStruct;
      remove_from_list(pMudEvent->pEvent, ch->events);
      
      if (ch->events->iSize == 0) {
        free_list(ch->events);
        ch->events = NULL;
      }
    break;
    case EVENT_ROOM:
      room = (struct room_data *) pMudEvent->pStruct;
      remove_from_list(pMudEvent->pEvent, room->events);
      
      if (room->events && (room->events->iSize == 0)) { 
        free_list(room->events);
        room->events = NULL;
      }      
    break;
  }

  if (pMudEvent->sVariables != NULL)
    free(pMudEvent->sVariables);

  pMudEvent->pEvent->event_obj = NULL;
  free(pMudEvent);
}
示例#29
0
文件: osprd.c 项目: AmberYu/CS111
// This function is called when a /dev/osprdX file is finally closed.
// (If the file descriptor was dup2ed, this function is called only when the
// last copy is closed.)
static int osprd_close_last(struct inode *inode, struct file *filp)
{
	if (filp) {
		osprd_info_t *d = file2osprd(filp);
		int filp_writable = filp->f_mode & FMODE_WRITE;

		// EXERCISE: If the user closes a ramdisk file that holds
		// a lock, release the lock.  Also wake up blocked processes
		// as appropriate.

		// Your code here.
		osp_spin_lock(&d->mutex);
		// When the file is closed;
		if ((filp->f_flags & F_OSPRD_LOCKED) != 0)
		{
			filp->f_flags &= ~F_OSPRD_LOCKED;
			if (filp_writable)
			{
				remove_from_list(d->write_locking_pids, current->pid);
				// eprintk("Write done!\n");
				// print_list(d->write_locking_pids);
			}
			else
			{
				remove_from_list(d->read_locking_pids, current->pid);
				// eprintk("Read done!\n");
				// print_list(d->read_locking_pids);
			}
			// eprintk("Locking command release!\n");
			wake_up_all(&d->blockq);
		}
		osp_spin_unlock(&d->mutex);

		// This line avoids compiler warnings; you may remove it.
		(void) filp_writable, (void) d;

	}

	return 0;
}
示例#30
0
/**
 * See header.
 */
int load_authorities_cfg(vici_conn_t *conn, command_format_options_t format,
						 settings_t *cfg)
{
	u_int found = 0, loaded = 0, unloaded = 0;
	char *section;
	enumerator_t *enumerator;
	linked_list_t *authorities;

	authorities = list_authorities(conn, format);

	enumerator = cfg->create_section_enumerator(cfg, "authorities");
	while (enumerator->enumerate(enumerator, &section))
	{
		remove_from_list(authorities, section);
		found++;
		if (load_authority(conn, cfg, section, format))
		{
			loaded++;
		}
	}
	enumerator->destroy(enumerator);

	/* unload all authorities in daemon, but not in file */
	while (authorities->remove_first(authorities, (void**)&section) == SUCCESS)
	{
		if (unload_authority(conn, section, format))
		{
			unloaded++;
		}
		free(section);
	}
	authorities->destroy(authorities);

	if (format & COMMAND_FORMAT_RAW)
	{
		return 0;
	}
	if (found == 0)
	{
		fprintf(stderr, "no authorities found, %u unloaded\n", unloaded);
		return 0;
	}
	if (loaded == found)
	{
		printf("successfully loaded %u authorities, %u unloaded\n",
			   loaded, unloaded);
		return 0;
	}
	fprintf(stderr, "loaded %u of %u authorities, %u failed to load, "
			"%u unloaded\n", loaded, found, found - loaded, unloaded);
	return EINVAL;
}