int
osip_sem_post (struct osip_sem *_sem)
{
  osip_sem_t *sem = (osip_sem_t *) _sem;
  if (sem == NULL)
    return -1;
  return (sm_v (sem->id));
}
int
osip_mutex_unlock (struct osip_mutex *_mut)
{
  osip_mutex_t *mut = (osip_mutex_t *) _mut;
  if (mut)
    {
      sm_v (mut->id);
    }

  return (0);
}
Exemple #3
0
int sem_post(sem_t * sem)
{
	unsigned int rc;
	extern int __tk_IntFlagCntr;

	if (__tk_IntFlagCntr)
		rc = sm_v_ny(*sem);
	else
		rc = sm_v(*sem);

	errno = rc;

	if (rc == ERR_OK)
		return 0;
	else
		return EINVAL;

	return 0;
}
Exemple #4
0
void 
SHM_Free(void *__ptr)
{
	unsigned long flags;
	unsigned int order;
	struct PageDescriptor *page, **pg;
	struct SizeDescriptor *bucket;

	if (!__ptr)
		goto null_kfree;

	/* Acquire Locks */
	sm_p(memoryMap->semid, 0, 0);

#define ptr ((struct BlockHeader *) __ptr)
	page = PAGE_DESC(ptr);
	__ptr = ptr - 1;
	if (~SHMLBA_MASK & (unsigned long)page->next)
	{
		goto bad_order;
	}
	order = page->order;
	if (order >= /* sizeof(sizes) / sizeof(sizes[0]) */NSIZES)
	{
		goto bad_order;
	}
	bucket = sizes + order;
	pg = &bucket->firstFree;
	if (ptr->bhFlags != MF_USED)
	{
		goto bad_order;
	}
	ptr->bhFlags = MF_FREE;	/* As of now this block is officially free */
#ifdef SADISTIC_KMALLOC
	memset(ptr+1, 0xe0, ptr->bhLength);
#endif

	bucket->nFrees++;
	bucket->nBytesMalloced -= ptr->bhLength;

	ptr->bhNext = page->firstFree;
	page->firstFree = ptr;
	if (!page->nFree++) 
	{
/* Page went from full to one free block: put it on the freelist. */
		if (bucket->nBlocks == 1)
		{
			goto free_page;
		}
		page->next = *pg;
		*pg = page;
	}
/* If page is completely free, free it */
	if (page->nFree == bucket->nBlocks) {
		for (;;) {
			struct PageDescriptor *tmp = *pg;
			if (!tmp)
				goto not_on_freelist;
			if (tmp == page)
				break;
			pg = &tmp->next;
		}
		*pg = page->next;
free_page:
		bucket->nPages--;
		SHM_FreePage(page, bucket->gfporder);
	}

	sm_v(memoryMap->semid);

null_kfree:
	return;

bad_order:
	sm_v(memoryMap->semid);

	printf("SHM_Free of non-malloced memory[%lu]: %p, next= %p, order=%d\n",
		ULONG_FMT(getpid()),
	       ptr+1, page->next, page->order);
	return;

not_on_freelist:
	sm_v(memoryMap->semid);

	printf("Ooops. page %p doesn't show on freelist.\n", page);
}
Exemple #5
0
/*
 * Ugh, this is ugly, but we want the default case to run
 * straight through, which is why we have the ugly goto's
 */
void * 
SHM_Malloc(size_t size)
{
	unsigned long flags;
	unsigned long type;
	int order;
	struct BlockHeader *p;
	struct PageDescriptor *page, **pg;
	struct SizeDescriptor *bucket = sizes;

	if ((size <= 0) || !memoryMap)
	{
		return NULL;
	}

	/* Get order */
	order = 0;
	{
		unsigned int realsize = size + sizeof(struct BlockHeader);
		for (;;) {
			int ordersize = BLOCKSIZE(order);
			if (realsize <= ordersize)
				break;
			order++;
			bucket++;
			if (ordersize)
				continue;
			printf("malloc of too large a block (%d bytes).\n", (int) size);
			return NULL;
		}
	}

	/* Acquire Locks */
	sm_p(memoryMap->semid, 0, 0);

	type = MF_USED;
	pg = &bucket->firstFree;

	page = *pg;
	if (!page)
	{
		goto no_bucket_page;
	}

	p = page->firstFree;
	if (p->bhFlags != MF_FREE)
	{
		goto not_free_on_freelist;
	}

found_it:
	page->firstFree = p->bhNext;
	page->nFree--;
	if (!page->nFree)
	{
		*pg = page->next;
	}
	bucket->nMallocs++;
	bucket->nBytesMalloced += size;
	p->bhFlags = type;	/* As of now this block is officially in use */
	p->bhLength = size;
#ifdef SADISTIC_KMALLOC
	memset(p+1, 0xf0, size);
#endif
	sm_v(memoryMap->semid);

	return p + 1;		/* Pointer arithmetic: increments past header */


no_bucket_page:
	/*
	 * If we didn't find a page already allocated for this
	 * bucket size, we need to get one..
	 *
	 */

	{
		int i, sz;
		
		/* sz is the size of the blocks we're dealing with */
		sz = BLOCKSIZE(order);

		page = SHM_GetFreePage(bucket->gfporder);
		if (!page)
		{
			goto no_free_page;
		}
found_cached_page:

		bucket->nPages++;

		page->order = order;
		/* Loop for all but last block: */
		i = (page->nFree = bucket->nBlocks) - 1;
		p = BH(page + 1);
		while (i > 0) {
			i--;
			p->bhFlags = MF_FREE;
			p->bhNext = BH(((long) p) + sz);
			p = p->bhNext;
		}
		/* Last block: */
		p->bhFlags = MF_FREE;
		p->bhNext = NULL;

		p = BH(page+1);
	}

	/*
	 * Now we're going to muck with the "global" freelist
	 * for this size: this should be uninterruptible
	 */
	page->next = *pg;
	*pg = page;
	goto found_it;

no_free_page:
	printf("Problem: no free page\n");
	sm_v(memoryMap->semid);
	return NULL;

not_free_on_freelist:
	printf("Problem: block on freelist at %08lx isn't free.\n", (long) p);
	sm_v(memoryMap->semid);
	return NULL;
}