Files
xen/tools/xenstore/utils.h
T
kaf24@firebug.cl.cam.ac.uk bddd41366d xenstored now supports multiple concurrent transactions per
connection, plus interleaving of transactional and
non-transactional accesses. A transaction identifier is added
to the xsd_sockmsg header structure (0 means 'not in context
of a transaction'). The user and kernel xs interfaces accept
a pointer to a transaction handle where appropriate --
currently this is directly cast to an integer identifier in
the client library / kernel driver, but will allow for keeping
extra dynamic client-side state in future if we need to.

The transaction mutex has now gone. It's replaced with a
read-write mutex, but this is only acquired for exclusive
access during suspend/resume, to ensure there are no in-progress
transactions.

Signed-off-by: Keir Fraser <keir@xensource.com>
2005-10-10 15:38:01 +01:00

89 lines
2.1 KiB
C

#ifndef _UTILS_H
#define _UTILS_H
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
/* Is A == B ? */
#define streq(a,b) (strcmp((a),(b)) == 0)
/* Does A start with B ? */
#define strstarts(a,b) (strncmp((a),(b),strlen(b)) == 0)
/* Does A end in B ? */
static inline bool strends(const char *a, const char *b)
{
if (strlen(a) < strlen(b))
return false;
return streq(a + strlen(a) - strlen(b), b);
}
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define ___stringify(x) #x
#define __stringify(x) ___stringify(x)
/* Convenient wrappers for malloc and realloc. Use them. */
#define new(type) ((type *)malloc_nofail(sizeof(type)))
#define new_array(type, num) realloc_array((type *)0, (num))
#define realloc_array(ptr, num) ((__typeof__(ptr))_realloc_array((ptr), sizeof((*ptr)), (num)))
void *malloc_nofail(size_t size);
void *realloc_nofail(void *ptr, size_t size);
void *_realloc_array(void *ptr, size_t size, size_t num);
void barf(const char *fmt, ...) __attribute__((noreturn));
void barf_perror(const char *fmt, ...) __attribute__((noreturn));
/* This version adds one byte (for nul term) */
void *grab_file(const char *filename, unsigned long *size);
void release_file(void *data, unsigned long size);
/* Signal handling: returns fd to listen on. */
int signal_to_fd(int signal);
void close_signal(int fd);
void xprintf(const char *fmt, ...);
#define eprintf(_fmt, _args...) xprintf("[ERR] %s" _fmt, __FUNCTION__, ##_args)
#define iprintf(_fmt, _args...) xprintf("[INF] %s" _fmt, __FUNCTION__, ##_args)
#ifdef DEBUG
#define dprintf(_fmt, _args...) xprintf("[DBG] %s" _fmt, __FUNCTION__, ##_args)
#else
#define dprintf(_fmt, _args...) ((void)0)
#endif
/*
* Mux errno values onto returned pointers.
*/
static inline void *ERR_PTR(long error)
{
return (void *)error;
}
static inline long PTR_ERR(const void *ptr)
{
return (long)ptr;
}
static inline long IS_ERR(const void *ptr)
{
return ((unsigned long)ptr > (unsigned long)-1000L);
}
#endif /* _UTILS_H */
/*
* Local variables:
* c-file-style: "linux"
* indent-tabs-mode: t
* c-indent-level: 8
* c-basic-offset: 8
* tab-width: 8
* End:
*/