hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cf_hooks.h
Go to the documentation of this file.
1 /*
2  * Citrusleaf Foundation
3  * include/cf_hooks.h - hooks for application defined allocation and locking
4  *
5  * Copyright 2012 by Citrusleaf. All rights reserved.
6  * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE. THE COPYRIGHT NOTICE
7  * ABOVE DOES NOT EVIDENCE ANY ACTUAL OR INTENDED PUBLICATION.
8  */
9 
10 
11 #pragma once
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 typedef struct cf_mutex_hooks_s {
18  // Allocate and initialize new lock.
19  void *(*alloc)(void);
20  // Release all storage held in 'lock'.
21  void (*free)(void *lock);
22  // Acquire an already-allocated lock at 'lock'.
23  int (*lock)(void *lock);
24  // Release a lock at 'lock'.
25  int (*unlock)(void *lock);
27 
29 
30 static inline void
31 cf_hook_mutex(cf_mutex_hooks *hooks)
32 {
33  g_mutex_hooks = hooks;
34 }
35 
36 static inline void*
37 cf_hooked_mutex_alloc()
38 {
39  return g_mutex_hooks ? g_mutex_hooks->alloc() : 0;
40 }
41 
42 static inline void
43 cf_hooked_mutex_free(void *lock)
44 {
45  if (lock) {
46  g_mutex_hooks->free(lock);
47  }
48 }
49 
50 static inline int
51 cf_hooked_mutex_lock(void *lock)
52 {
53  return lock ? g_mutex_hooks->lock(lock) : 0;
54 }
55 
56 static inline int
57 cf_hooked_mutex_unlock(void *lock)
58 {
59  return lock ? g_mutex_hooks->unlock(lock) : 0;
60 }
61 
62 #ifdef __cplusplus
63 }
64 #endif
65