h_mgr.cpp File Reference

#include "precompiled.h"
#include "h_mgr.h"
#include <boost/unordered_map.hpp>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <new>
#include "lib/fnv_hash.h"
#include "lib/allocators/overrun_protector.h"
#include "lib/config2.h"
#include "lib/sysdep/vm.h"
#include "lib/allocators/pool.h"
#include "lib/module_init.h"
#include "lib/posix/posix_pthread.h"

Classes

struct  HDATA
struct  H_ScopedLock

Namespaces

namespace  ERR
 

Introduction ------------.


Defines

#define IDX_BITS   16
#define TAG_BITS   48

Typedefs

typedef i64 Tag
typedef
boost::unordered_multimap
< uintptr_t, ssize_t
Key2Idx
typedef Key2Idx::iterator It

Enumerations

enum  KeyRemoveFlag { KEY_NOREMOVE, KEY_REMOVE }

Functions

 STATUS_ADD_DEFINITIONS (hStatusDefinitions)
 cassert (IDX_BITS+TAG_BITS<=sizeof(Handle)*CHAR_BIT)
static size_t h_idx (const Handle h)
static Tag h_tag (Handle h)
static Handle handle (size_t idx, u64 tag)
static Status h_data_from_idx (ssize_t idx, HDATA *&hd)
static ssize_t h_idx_from_data (HDATA *hd)
static Status h_data_no_tag (const Handle h, HDATA *&hd)
static Status h_data_tag (Handle h, HDATA *&hd)
static Status h_data_tag_type (const Handle h, const H_Type type, HDATA *&hd)
static Handle key_find (uintptr_t key, H_Type type, KeyRemoveFlag remove_option=KEY_NOREMOVE)
static void key_add (uintptr_t key, Handle h)
static void key_remove (uintptr_t key, H_Type type)
static void warn_if_invalid (HDATA *hd)
static Status type_validate (H_Type type)
static Tag gen_tag ()
static Handle reuse_existing_handle (uintptr_t key, H_Type type, size_t flags)
static Status call_init_and_reload (Handle h, H_Type type, HDATA *hd, const PIVFS &vfs, const VfsPath &pathname, va_list *init_args)
static Handle alloc_new_handle (H_Type type, const PIVFS &vfs, const VfsPath &pathname, uintptr_t key, size_t flags, va_list *init_args)
Handle h_alloc (H_Type type, const PIVFS &vfs, const VfsPath &pathname, size_t flags,...)
static void h_free_hd (HDATA *hd)
Status h_free (Handle &h, H_Type type)
void * h_user_data (const Handle h, const H_Type type)
VfsPath h_filename (const Handle h)
Status h_reload (const PIVFS &vfs, const VfsPath &pathname)
Handle h_find (H_Type type, uintptr_t key)
Status h_force_free (Handle h, H_Type type)
void h_add_ref (Handle h)
intptr_t h_get_refcnt (Handle h)
static Status Init ()
static void Shutdown ()
void h_mgr_init ()
void h_mgr_shutdown ()

Variables

static const Status ERR::H_IDX_INVALID = -120000
static const Status ERR::H_IDX_UNUSED = -120001
static const Status ERR::H_TAG_MISMATCH = -120003
static const Status ERR::H_TYPE_MISMATCH = -120004
static const Status ERR::H_ALREADY_FREED = -120005
static const StatusDefinition hStatusDefinitions []
static const u64 IDX_MASK = (1l << IDX_BITS) - 1
static const u64 TAG_MASK = 0xFFFFFFFF
static const size_t HDATA_USER_SIZE = 100
static const ssize_t hdata_cap = (1ul << IDX_BITS)/4
static Pool hpool
static bool ignoreDoubleFree = false
static OverrunProtector< Key2Idxkey2idx_wrapper
static pthread_mutex_t h_mutex
static ModuleInitState initState

Define Documentation

#define IDX_BITS   16
#define TAG_BITS   48

Typedef Documentation

typedef Key2Idx::iterator It
typedef boost::unordered_multimap<uintptr_t, ssize_t> Key2Idx
typedef i64 Tag

Enumeration Type Documentation

Enumerator:
KEY_NOREMOVE 
KEY_REMOVE 

Function Documentation

static Handle alloc_new_handle ( H_Type  type,
const PIVFS vfs,
const VfsPath pathname,
uintptr_t  key,
size_t  flags,
va_list *  init_args 
) [static]
static Status call_init_and_reload ( Handle  h,
H_Type  type,
HDATA hd,
const PIVFS vfs,
const VfsPath pathname,
va_list *  init_args 
) [static]
cassert ( IDX_BITS+TAG_BITS<=sizeof(Handle)*  CHAR_BIT  ) 
static Tag gen_tag (  )  [static]
void h_add_ref ( Handle  h  ) 
Handle h_alloc ( H_Type  type,
const PIVFS vfs,
const VfsPath pathname,
size_t  flags,
  ... 
)
static Status h_data_from_idx ( ssize_t  idx,
HDATA *&  hd 
) [static]
static Status h_data_no_tag ( const Handle  h,
HDATA *&  hd 
) [inline, static]
static Status h_data_tag ( Handle  h,
HDATA *&  hd 
) [inline, static]
static Status h_data_tag_type ( const Handle  h,
const H_Type  type,
HDATA *&  hd 
) [static]
VfsPath h_filename ( const Handle  h  ) 
Handle h_find ( H_Type  type,
uintptr_t  key 
)
Status h_force_free ( Handle  h,
H_Type  type 
)
Status h_free ( Handle h,
H_Type  type 
)
static void h_free_hd ( HDATA hd  )  [static]
intptr_t h_get_refcnt ( Handle  h  ) 
static size_t h_idx ( const Handle  h  )  [inline, static]
static ssize_t h_idx_from_data ( HDATA hd  )  [static]
void h_mgr_init (  ) 
void h_mgr_shutdown (  ) 
Status h_reload ( const PIVFS vfs,
const VfsPath pathname 
)
static Tag h_tag ( Handle  h  )  [inline, static]
void* h_user_data ( const Handle  h,
const H_Type  type 
)
static Handle handle ( size_t  idx,
u64  tag 
) [inline, static]
static Status Init (  )  [static]
static void key_add ( uintptr_t  key,
Handle  h 
) [static]
static Handle key_find ( uintptr_t  key,
H_Type  type,
KeyRemoveFlag  remove_option = KEY_NOREMOVE 
) [static]
static void key_remove ( uintptr_t  key,
H_Type  type 
) [static]
static Handle reuse_existing_handle ( uintptr_t  key,
H_Type  type,
size_t  flags 
) [static]
static void Shutdown (  )  [static]
STATUS_ADD_DEFINITIONS ( hStatusDefinitions   ) 
static Status type_validate ( H_Type  type  )  [static]
static void warn_if_invalid ( HDATA hd  )  [static]

Variable Documentation

const ssize_t hdata_cap = (1ul << IDX_BITS)/4 [static]
const size_t HDATA_USER_SIZE = 100 [static]
Pool hpool [static]
Initial value:
 {
    { ERR::H_IDX_INVALID,   L"Handle index completely out of bounds" },
    { ERR::H_IDX_UNUSED,    L"Handle index exceeds high-water mark" },
    { ERR::H_TAG_MISMATCH,  L"Handle tag mismatch (stale reference?)" },
    { ERR::H_TYPE_MISMATCH, L"Handle type mismatch" },
    { ERR::H_ALREADY_FREED, L"Handle already freed" }
}
const u64 IDX_MASK = (1l << IDX_BITS) - 1 [static]
bool ignoreDoubleFree = false [static]
const u64 TAG_MASK = 0xFFFFFFFF [static]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed May 16 03:15:23 2012 for Pyrogenesis by  doxygen 1.6.3