compat(3)

πŸ“¦
version 0.9.35 Β· 5 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– compat(3) πŸ’–

no cap, this is compat(3) from the Library Functions Manual, and it's literally the little drawer of ✨ Compatibility Macros ✨ that keeps everything else from drowning in platform-specific ifdefs. pull up a chair bestie 🫢


🌈 NAME 🌈

compat β€” Compatibility Macros

πŸŽ€ SYNOPSIS πŸŽ€

Macros

#define MDB_DEVEL   0
#define mdb_func_   '<mdb_unknown>'
#define MDB_NO_ROOT   (MDB_LAST_ERRCODE + 10)
#define MDB_USE_ROBUST   1
#define THREAD_RET   void *
#define THREAD_CREATE(thr,  start,  arg)
#define THREAD_FINISH(thr)
#define Z   'z'
#define MDB_PIDLOCK   1
#define LOCK_MUTEX0(mutex)
#define UNLOCK_MUTEX(mutex)
#define mdb_mutex_consistent(mutex)
#define ErrCode()
#define HANDLE   int
#define INVALID_HANDLE_VALUE   (-1)
#define GET_PAGESIZE(x)
#define MNAME_LEN   (sizeof(pthread_mutex_t))

Typedefs

typedef pthread_mutex_t mdb_mutex_t[1]
typedef pthread_mutex_t * mdb_mutexref_t

πŸ¦‹ Detailed Description πŸ¦‹

it's giving "glue code, but make it cute". this is a whole little crew of macros whose entire job is to shrink down the number of platform-specific ifdefs scattered through the rest of the code. and the vibe check here is: whenever the features this library needs are similar enough to POSIX that they can be tucked away in a one-or-two line replacement, boom β€” that's where this macro approach comes in. slay. πŸ’…


πŸ‘‘ Macro Definition Documentation πŸ‘‘

#define MDB_DEVEL 0

Features under development ✨

#define mdb_func_ '<mdb_unknown>'

Wrapper around func, which is a C99 feature.

#define MDB_USE_ROBUST 1

okay so here's the tea β˜•: some platforms go ahead and define the EOWNERDEAD error code even though they don't actually support Robust Mutexes. so you compile with -DMDB_USE_ROBUST=0, or you use some other mechanism like -DMDB_USE_POSIX_SEM instead of -DMDB_USE_POSIX_MUTEX. (and just so you know β€” Posix semaphores are not robust. noted. πŸ“)

#define THREAD_CREATE( thr, start, arg)

Value:

pthread_create(&thr,NULL,start,arg)

#define THREAD_FINISH( thr)

Value:

pthread_join(thr,NULL)

#define Z 'z'

printf format modifier for size_t πŸ’…

#define MDB_PIDLOCK 1

For MDB_LOCK_FORMAT: True if readers take a pid lock in the lockfile πŸ”’

#define LOCK_MUTEX0( mutex)

Value:

pthread_mutex_lock(mutex)

Lock the reader or writer mutex. Returns 0 or a code to give mdb_mutex_failed(), as in LOCK_MUTEX().

#define UNLOCK_MUTEX( mutex)

Value:

pthread_mutex_unlock(mutex)

Unlock the reader or writer mutex. bye bestie πŸ‘‹

#define mdb_mutex_consistent( mutex)

Value:

pthread_mutex_consistent(mutex)

Mark mutex-protected data as repaired, after death of previous owner. πŸ’€βž‘οΈβœ¨

#define ErrCode()

Value:

errno

Get the error code for the last failed system function. classic. πŸ™ˆ

#define HANDLE int

An abstraction for a file handle. On POSIX systems file handles are small integers. On Windows they're opaque pointers. (windows being windows 😭)

#define INVALID_HANDLE_VALUE (-1)

A value for an invalid file handle. Mainly used to initialize file variables and signify that they are unused.

#define GET_PAGESIZE( x)

Value:

((x) = sysconf(_SC_PAGE_SIZE))

Get the size of a memory page for the system. This is the basic size that the platform's memory manager uses, and is fundamental to the use of memory-mapped files. iconic, frankly. πŸ“„


🧚 Typedef Documentation 🧚

typedef pthread_mutex_t mdb_mutex_t[1]

Shared mutex/semaphore as the original is stored.

Not for copies. 🚫 instead it can be assigned to an mdb_mutexref_t. When mdb_mutexref_t is a pointer and mdb_mutex_t is not, then it is array[size 1] so it can be assigned to the pointer.

typedef pthread_mutex_t* mdb_mutexref_t

Reference to an mdb_mutex_t.


🌸 Author 🌸

Generated automatically by Doxygen for LMDB from the source code. (not a human writing this, just doxygen doing its little thing 🫢)


and that's the whole page, bestie! πŸŽ€ this was compat(3) from the LMDB crew β€” main character energy from a header full of macros, fr fr. go forth and #define responsibly πŸ’–πŸŒˆ

πŸ“¦ where this page comes from