NCBI C++ ToolKit
Classes | Macros | Typedefs | Functions
buffering.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Go to the SVN repository for this file.

Classes

struct  dblib_buffer_row
 

Macros

#define BUFFER_CHECK(buf)   do {} while(0)
 

Typedefs

typedef struct dblib_buffer_row DBLIB_BUFFER_ROW
 

Functions

static void buffer_struct_print (const DBPROC_ROWBUF *buf)
 
static RETCODE buffer_save_row (DBPROCESS *dbproc)
 Save current row into row buffer. More...
 
static DBLIB_BUFFER_ROWbuffer_row_address (const DBPROC_ROWBUF *buf, int idx)
 Given an index, return the row storage, including the DBINT row number prefix. More...
 
static int buffer_count (const DBPROC_ROWBUF *buf)
 A few words on the buffering design. More...
 
static int buffer_is_full (const DBPROC_ROWBUF *buf)
 Can the buffer be written to? More...
 
static int buffer_index_valid (const DBPROC_ROWBUF *buf, int idx)
 
static void buffer_free_row (DBLIB_BUFFER_ROW *row)
 
static void buffer_free (DBPROC_ROWBUF *buf)
 
static void buffer_reset (DBPROC_ROWBUF *buf)
 
static int buffer_idx_increment (const DBPROC_ROWBUF *buf, int idx)
 
static DBINT buffer_idx2row (const DBPROC_ROWBUF *buf, int idx)
 Convert an index to a row number. More...
 
static int buffer_row2idx (const DBPROC_ROWBUF *buf, int row_number)
 Convert a row number to an index. More...
 
static void buffer_delete_rows (DBPROC_ROWBUF *buf, int count)
 Deleting a row from the buffer doesn't affect memory allocation. More...
 
static void buffer_transfer_bound_data (DBPROC_ROWBUF *buf, TDS_INT res_type, TDS_INT compute_id, DBPROCESS *dbproc, int idx)
 Transfer data from buffer/tds back to client. More...
 
static int buffer_current_index (const DBPROCESS *dbproc)
 Return the current row buffer index. More...
 
static void buffer_set_capacity (DBPROCESS *dbproc, int nrows)
 
static void buffer_alloc (DBPROCESS *dbproc)
 
static int buffer_add_row (DBPROCESS *dbproc, TDSRESULTINFO *resinfo)
 Called by dbnextrow Returns a row buffer index, or -1 to indicate the buffer is full. More...
 

Macro Definition Documentation

◆ BUFFER_CHECK

#define BUFFER_CHECK (   buf)    do {} while(0)

Definition at line 80 of file buffering.h.

Typedef Documentation

◆ DBLIB_BUFFER_ROW

Function Documentation

◆ buffer_add_row()

static int buffer_add_row ( DBPROCESS dbproc,
TDSRESULTINFO resinfo 
)
static

◆ buffer_alloc()

static void buffer_alloc ( DBPROCESS dbproc)
static

Definition at line 463 of file buffering.h.

References assert, buf, buffer_reset(), dbproc, NULL, tds_dblib_dbprocess::row_buf, and tds_new0.

◆ buffer_count()

static int buffer_count ( const DBPROC_ROWBUF buf)
static

A few words on the buffering design.

DBPROC_ROWBUF::buf is a block of row buffers, managed as a ring, indexed by head, tail, and current:

head – where new elements are inserted. tail – oldest element. current – active row (read by dbgetrow/dbnextrow)

capacity is the number of rows that buf can hold.

Each element in buf is preceded by its row_number: the result_set row number, determined by counting the rows as they're received from the server. Applications communicate to db-lib in row numbers, not buffer indices.

Semantics: head == 0 && tail == capacity is the initial condition. head == tail means the buffer is full, except when capacity is 1. head < tail means the buffer has wrapped around.

Whether or not buffering is active is governed by dbproc->dbopts[DBBUFFER].optactive.

number of rows in the buffer

Definition at line 112 of file buffering.h.

References buf, and BUFFER_CHECK.

Referenced by buffer_delete_rows(), buffer_is_full(), and buffer_struct_print().

◆ buffer_current_index()

static int buffer_current_index ( const DBPROCESS dbproc)
static

Return the current row buffer index.

We strive to validate it first. It must be: between zero and capacity (obviously), and between the head and the tail, logically.

If the head has wrapped the tail, it shouldn't be in no man's land. IOW, if capacity is 9, head is 3 and tail is 7, good rows are 7-8 and 0-2. (Row 3 is about-to-be-inserted, and 4-6 are not in use.) Here's a diagram: d d d ! ! ! ! d d 0 1 2 3 4 5 6 7 8 ^ ^ Head Tail

The special case is capacity == 1, meaning there's no buffering, and head == tail === 0.

Definition at line 405 of file buffering.h.

References assert, buf, buffer_struct_print(), dbproc, and tds_dblib_dbprocess::row_buf.

◆ buffer_delete_rows()

static void buffer_delete_rows ( DBPROC_ROWBUF buf,
int  count 
)
static

Deleting a row from the buffer doesn't affect memory allocation.

It just makes the space available for a different row.

Definition at line 275 of file buffering.h.

References buf, BUFFER_CHECK, buffer_count(), buffer_free_row(), buffer_idx_increment(), buffer_reset(), buffer_struct_print(), and i.

◆ buffer_free()

static void buffer_free ( DBPROC_ROWBUF buf)
static

Definition at line 177 of file buffering.h.

References buf, BUFFER_CHECK, buffer_free_row(), i, NULL, and TDS_ZERO_FREE.

Referenced by buffer_set_capacity().

◆ buffer_free_row()

static void buffer_free_row ( DBLIB_BUFFER_ROW row)
static

Definition at line 153 of file buffering.h.

References NULL, row, tds_free_results, tds_free_row, and TDS_ZERO_FREE.

Referenced by buffer_delete_rows(), and buffer_free().

◆ buffer_idx2row()

static DBINT buffer_idx2row ( const DBPROC_ROWBUF buf,
int  idx 
)
static

Convert an index to a row number.

Definition at line 231 of file buffering.h.

References buf, BUFFER_CHECK, buffer_row_address(), and dblib_buffer_row::row.

Referenced by buffer_row2idx().

◆ buffer_idx_increment()

static int buffer_idx_increment ( const DBPROC_ROWBUF buf,
int  idx 
)
static

Definition at line 202 of file buffering.h.

References buf.

Referenced by buffer_add_row(), buffer_delete_rows(), buffer_row2idx(), and buffer_transfer_bound_data().

◆ buffer_index_valid()

static int buffer_index_valid ( const DBPROC_ROWBUF buf,
int  idx 
)
static

Definition at line 132 of file buffering.h.

References buf, BUFFER_CHECK, buffer_struct_print(), head, TDS_DBG_FUNC, and tdsdump_log.

Referenced by buffer_transfer_bound_data().

◆ buffer_is_full()

static int buffer_is_full ( const DBPROC_ROWBUF buf)
static

Can the buffer be written to?

Definition at line 124 of file buffering.h.

References buf, BUFFER_CHECK, and buffer_count().

Referenced by buffer_add_row().

◆ buffer_reset()

static void buffer_reset ( DBPROC_ROWBUF buf)
static

Definition at line 194 of file buffering.h.

References buf, and BUFFER_CHECK.

Referenced by buffer_alloc(), and buffer_delete_rows().

◆ buffer_row2idx()

static int buffer_row2idx ( const DBPROC_ROWBUF buf,
int  row_number 
)
static

Convert a row number to an index.

Definition at line 241 of file buffering.h.

References assert, buf, BUFFER_CHECK, buffer_idx2row(), buffer_idx_increment(), and i.

◆ buffer_row_address()

static DBLIB_BUFFER_ROW * buffer_row_address ( const DBPROC_ROWBUF buf,
int  idx 
)
static

Given an index, return the row storage, including the DBINT row number prefix.

Definition at line 215 of file buffering.h.

References buf, BUFFER_CHECK, buffer_struct_print(), NULL, TDS_DBG_WARN, and tdsdump_log.

Referenced by buffer_add_row(), buffer_idx2row(), and buffer_transfer_bound_data().

◆ buffer_save_row()

static RETCODE buffer_save_row ( DBPROCESS dbproc)
static

Save current row into row buffer.

Definition at line 533 of file buffering.h.

References buf, dbproc, row, tds_dblib_dbprocess::row_buf, SUCCEED, and tds_alloc_row.

◆ buffer_set_capacity()

static void buffer_set_capacity ( DBPROCESS dbproc,
int  nrows 
)
static

Definition at line 434 of file buffering.h.

References assert, buf, BUFFER_CHECK, buffer_free(), dbproc, and tds_dblib_dbprocess::row_buf.

◆ buffer_struct_print()

static void buffer_struct_print ( const DBPROC_ROWBUF buf)
static

◆ buffer_transfer_bound_data()

static void buffer_transfer_bound_data ( DBPROC_ROWBUF buf,
TDS_INT  res_type,
TDS_INT  compute_id,
DBPROCESS dbproc,
int  idx 
)
static
Modified on Sat Jun 08 14:25:32 2024 by modify_doxy.py rev. 669887