8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-31 01:23:02 +01:00
firebird-mirror/src/ipserver/alli.cpp

110 lines
2.3 KiB
C++
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* PROGRAM: Interprocess server interface
* MODULE: alli.c
* DESCRIPTION: Internal block allocator
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "firebird.h"
2001-05-23 15:26:42 +02:00
#include <windows.h>
#include "../ipserver/ipc.h"
2003-07-06 05:11:47 +02:00
#define BLKDEF(type, root, tail) {sizeof (struct root), tail},
2001-05-24 16:54:26 +02:00
static struct
{
2001-05-23 15:26:42 +02:00
SSHORT typ_root_length;
SSHORT typ_tail_length;
} PIPE_block_sizes[] = {
2003-07-06 05:11:47 +02:00
{0, 0},
2001-05-24 16:54:26 +02:00
2001-05-23 15:26:42 +02:00
#include "../ipserver/blk.h"
2003-07-06 05:11:47 +02:00
{0, 0}
2001-05-24 16:54:26 +02:00
};
2001-05-23 15:26:42 +02:00
#include "../jrd/gds_proto.h"
#include "../ipserver/alli_proto.h"
2001-05-24 16:54:26 +02:00
//____________________________________________________________
//
// Allocate a block.
//
void* ALLI_alloc(ULONG size)
2001-05-23 15:26:42 +02:00
{
return gds__alloc(size);
}
2001-05-24 16:54:26 +02:00
//____________________________________________________________
//
// Allocate a block from a given pool and initialize the block.
// This is the primary block allocation routine.
//
2001-05-23 15:26:42 +02:00
BLK ALLI_block(UCHAR type, int count)
{
/*
if (type <= (SCHAR) type_MIN || type >= (SCHAR) type_MAX)
abort();
*/
/* Compute block length */
2001-05-24 16:54:26 +02:00
const USHORT tail = PIPE_block_sizes[type].typ_tail_length;
USHORT size = PIPE_block_sizes[type].typ_root_length + count * tail;
2001-05-23 15:26:42 +02:00
2001-05-24 16:54:26 +02:00
BLK block = (BLK) ALLI_alloc((SLONG) size);
2001-05-23 15:26:42 +02:00
2001-05-24 16:54:26 +02:00
if (block)
{
block->blk_type = type;
block->blk_length = size;
2001-05-23 15:26:42 +02:00
2001-05-24 16:54:26 +02:00
size -= sizeof(struct blk);
if (size)
{
memset((SCHAR *) block + sizeof(struct blk), 0, size);
}
}
2001-05-23 15:26:42 +02:00
return block;
}
2001-05-24 16:54:26 +02:00
//____________________________________________________________
//
// Free a block.
//
void ALLI_free(void* block)
2001-05-23 15:26:42 +02:00
{
2001-05-24 16:54:26 +02:00
gds__free(block);
2001-05-23 15:26:42 +02:00
}
2001-05-24 16:54:26 +02:00
//____________________________________________________________
//
// Release a structured block.
//
void ALLI_release(BLK block)
2001-05-23 15:26:42 +02:00
{
2001-05-24 16:54:26 +02:00
ALLI_free(block);
2001-05-23 15:26:42 +02:00
}