WL#3961: Plugin Service: mysys examples

Affects: Server-6.x   —   Status: Un-Assigned

We'll export mysys library in the form of Services (WL#3859), to allow plugins
to use it. This task is not about exporting all of the mysys, but only a few
selected services, to show how services are created.
1. Memory Allocation Services: malloc, safemalloc, and memroot:

  #define MY_FAE             8  /* Fatal if any error */
  #define MY_WME            16  /* Write message on error */
  #define MY_ZEROFILL       32  /* malloc(): fill array with zero */
  #define MY_ALLOW_ZERO_PTR 64  /* realloc(): zero ptr -> malloc */
  #define MY_FREE_ON_ERROR 128  /* realloc(): Free old ptr on error */
  #define MY_HOLD_ON_ERROR 256  /* realloc(): Return old ptr on error */

  typedef int myf;
  typedef struct st_mem_root MEM_ROOT;

  /* you normal malloc (safemalloc in debug builds) */
  struct Memory_Allocation_Service_Malloc {
    void *(*malloc)(size_t size, myf MyFlags);
    void (*free)(void* ptr, myf MyFlags);
    void *(*realloc)(void* oldpoint, size_t size, myf MyFlags);
    int  (*malloc_sanity_check)(const char *filename, uint lineno);
  } Memory_Allocation_Service_Malloc;

  /* largepages a.k.a. HugeTLD */
  struct Memory_Allocation_Service_Largepages {
    void *(*malloc)(size_t size, myf MyFlags);
    void (*free)(void* ptr, myf MyFlags);
  } Memory_Allocation_Service_Largepages;

  /* memroot allocator */
  struct Memory_Allocation_Service_Memroot {
    void (*init)(MEM_ROOT *mem_root, size_t block_size,
                 size_t pre_alloc_size, myf MyFlags);
    void *(*alloc)(MEM_ROOT *mem_root, size_t length, myf MyFlags);
    void (*free)(MEM_ROOT *root, myf MyFlags);
    int  (*sizeof_MEM_ROOT)();
  } Memory_Allocation_Service_Memroot;

here and below: alternatively, instead of

    int  (*sizeof_MEM_ROOT)();

we could have

    int   sizeof_MEM_ROOT;

2. Buffered IO Service - IO_CACHE

typedef struct st_io_cache IO_CACHE;
typedef struct st_io_cache_share IO_CACHE_SHARE;
enum cache_type {TYPE_NOT_SET, READ_CACHE, WRITE_CACHE, SEQ_READ_APPEND,
                 READ_FIFO, READ_NET,WRITE_NET};

  struct Buffered_IO_Service {
    int (*init)(IO_CACHE *info, int file, size_t cachesize, enum cache_type
type, off_t seek_offset, int use_async_io, myf MyFlags);
    int (*reinit)(IO_CACHE *info, enum cache_type type, off_t seek_offset, int
use_async_io, int clear_cache);
    int (*deinit)(IO_CACHE *info);
    int (*is_inited)(IO_CACHE *info);
    void (*init_share)(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare, IO_CACHE
*write_cache, uint num_threads);
    void (*remove_thread)(IO_CACHE *cache);
    int (*read)(IO_CACHE *info, char *buffer, size_t count);
    int (*write)(IO_CACHE *info, const char *buffer, size_t count);
    int (*append)(IO_CACHE *info, const char *buffer, size_t count);
    int (*flush)(IO_CACHE *info, int need_append_buffer_lock);
    void (*seek)(IO_CACHE *info,off_t pos);
    off_t (*tell)(IO_CACHE *info);
    int (*fill_cache)(IO_CACHE *info);
    int  (*bytes_in_cache)(IO_CACHE *info);
    int  (*sizeof_IO_CACHE)();
    int  (*sizeof_IO_CACHE_SHARE)();
  } Buffered_IO_Service;


OPEN ISSUES/COMMENTS ON THIS WL
===============================

On Fri, Jun 13, 2008 at 01:12:32AM +0200, Vladislav Vaintroub wrote:
> I think it is better *not* to use off_t, if you want the plugin
> services to be useful on Windows.  off_t is 32 bit integer , while a
> file can certainly be larger than 4GB.  "long long" , maybe unsigned
> is more appropriate here IMO.