-/*\r
- * Copyright (c) 2009 Intel Corporation. All rights reserved.\r
- *\r
- * This software is available to you under the OpenIB.org BSD license\r
- * below:\r
- *\r
- * Redistribution and use in source and binary forms, with or\r
- * without modification, are permitted provided that the following\r
- * conditions are met:\r
- *\r
- * - Redistributions of source code must retain the above\r
- * copyright notice, this list of conditions and the following\r
- * disclaimer.\r
- *\r
- * - Redistributions in binary form must reproduce the above\r
- * copyright notice, this list of conditions and the following\r
- * disclaimer in the documentation and/or other materials\r
- * provided with the distribution.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV\r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
- * SOFTWARE.\r
- */\r
-\r
-#ifndef _DLIST_H_\r
-#define _DLIST_H_\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-typedef struct _DLIST_ENTRY {\r
- struct _DLIST_ENTRY *Next;\r
- struct _DLIST_ENTRY *Prev;\r
-\r
-} DLIST_ENTRY;\r
-\r
-static void DListInit(DLIST_ENTRY *pHead)\r
-{\r
- pHead->Next = pHead;\r
- pHead->Prev = pHead;\r
-}\r
-\r
-static int DListEmpty(DLIST_ENTRY *pHead)\r
-{\r
- return pHead->Next == pHead;\r
-}\r
-\r
-static void DListInsertAfter(DLIST_ENTRY *pNew, DLIST_ENTRY *pHead)\r
-{\r
- pNew->Next = pHead->Next;\r
- pNew->Prev = pHead;\r
- pHead->Next->Prev = pNew;\r
- pHead->Next = pNew;\r
-}\r
-\r
-static void DListInsertBefore(DLIST_ENTRY *pNew, DLIST_ENTRY *pHead)\r
-{\r
- DListInsertAfter(pNew, pHead->Prev);\r
-}\r
-\r
-#define DListInsertHead DListInsertAfter\r
-#define DListInsertTail DListInsertBefore\r
-\r
-static void DListRemove(DLIST_ENTRY *pEntry)\r
-{\r
- pEntry->Prev->Next = pEntry->Next;\r
- pEntry->Next->Prev = pEntry->Prev;\r
-}\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif // _DLIST_H_\r
-\r
+/*
+ * Copyright (c) 2009 Intel Corporation. All rights reserved.
+ *
+ * This software is available to you under the OpenIB.org BSD license
+ * below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef _DLIST_H_
+#define _DLIST_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct _DLIST_ENTRY {
+ struct _DLIST_ENTRY *Next;
+ struct _DLIST_ENTRY *Prev;
+
+} DLIST_ENTRY;
+
+static void DListInit(DLIST_ENTRY *pHead)
+{
+ pHead->Next = pHead;
+ pHead->Prev = pHead;
+}
+
+static int DListEmpty(DLIST_ENTRY *pHead)
+{
+ return pHead->Next == pHead;
+}
+
+static void DListInsertAfter(DLIST_ENTRY *pNew, DLIST_ENTRY *pHead)
+{
+ pNew->Next = pHead->Next;
+ pNew->Prev = pHead;
+ pHead->Next->Prev = pNew;
+ pHead->Next = pNew;
+}
+
+static void DListInsertBefore(DLIST_ENTRY *pNew, DLIST_ENTRY *pHead)
+{
+ DListInsertAfter(pNew, pHead->Prev);
+}
+
+#define DListInsertHead DListInsertAfter
+#define DListInsertTail DListInsertBefore
+
+static void DListRemove(DLIST_ENTRY *pEntry)
+{
+ pEntry->Prev->Next = pEntry->Next;
+ pEntry->Next->Prev = pEntry->Prev;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // _DLIST_H_
*
* This software is available to you under the OpenFabrics.org BSD license
* below:
- *\r
- * Redistribution and use in source and binary forms, with or\r
- * without modification, are permitted provided that the following\r
- * conditions are met:\r
- *\r
- * - Redistributions of source code must retain the above\r
- * copyright notice, this list of conditions and the following\r
- * disclaimer.\r
- *\r
- * - Redistributions in binary form must reproduce the above\r
- * copyright notice, this list of conditions and the following\r
- * disclaimer in the documentation and/or other materials\r
- * provided with the distribution.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV\r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
- * SOFTWARE.\r
- */\r
-\r
-#if !defined(OSD_H)\r
-#define OSD_H\r
-\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <stdio.h>\r
-#include <unistd.h>\r
-#include <errno.h>\r
-#include <byteswap.h>\r
-#include <pthread.h>\r
-#include <sys/socket.h>\r
-#include <sys/types.h>\r
-#include <sys/stat.h>\r
-#include <malloc.h>\r
-#include <arpa/inet.h>\r
-#include <sys/time.h>\r
-#include <netinet/in.h>\r
-\r
-#ifndef SYSCONFDIR\r
-#define SYSCONFDIR "/etc"\r
-#endif\r
-#ifndef BINDIR\r
-#define BINDIR "/usr/bin"\r
-#endif\r
-#ifndef RDMADIR\r
-#define RDMADIR "rdma"\r
-#endif\r
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#if !defined(OSD_H)
+#define OSD_H
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <byteswap.h>
+#include <pthread.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <malloc.h>
+#include <arpa/inet.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+
+#ifndef SYSCONFDIR
+#define SYSCONFDIR "/etc"
+#endif
+#ifndef BINDIR
+#define BINDIR "/usr/bin"
+#endif
+#ifndef RDMADIR
+#define RDMADIR "rdma"
+#endif
#define ACM_CONF_DIR SYSCONFDIR "/" RDMADIR
#define ACM_ADDR_FILE "ibacm_addr.cfg"
#define ACM_OPTS_FILE "ibacm_opts.cfg"
#define LIB_DESTRUCTOR __attribute__((destructor))
#define CDECL_FUNC
-\r
-#define container_of(ptr, type, field) \\r
- ((type *) ((void *) ptr - offsetof(type, field)))\r
-\r
-#define min(a, b) (a < b ? a : b)\r
-#define max(a, b) (a > b ? a : b)\r
-\r
-#if __BYTE_ORDER == __LITTLE_ENDIAN\r
-#define htonll(x) bswap_64(x)\r
-#else\r
-#define htonll(x) (x)\r
-#endif\r
-#define ntohll(x) htonll(x)\r
-\r
-#if DEFINE_ATOMICS\r
-typedef struct { pthread_mutex_t mut; int val; } atomic_t;\r
-static inline int atomic_inc(atomic_t *atomic)\r
-{\r
- int v;\r
-\r
- pthread_mutex_lock(&atomic->mut);\r
- v = ++(atomic->val);\r
- pthread_mutex_unlock(&atomic->mut);\r
- return v;\r
-}\r
-static inline int atomic_dec(atomic_t *atomic)\r
-{\r
- int v;\r
-\r
- pthread_mutex_lock(&atomic->mut);\r
- v = --(atomic->val);\r
- pthread_mutex_unlock(&atomic->mut);\r
- return v;\r
-}\r
-static inline void atomic_init(atomic_t *atomic)\r
-{\r
- pthread_mutex_init(&atomic->mut, NULL);\r
- atomic->val = 0;\r
-}\r
-#else\r
-typedef struct { volatile int val; } atomic_t;\r
-#define atomic_inc(v) (__sync_add_and_fetch(&(v)->val, 1))\r
-#define atomic_dec(v) (__sync_sub_and_fetch(&(v)->val, 1))\r
-#define atomic_init(v) ((v)->val = 0)\r
-#endif\r
-#define atomic_get(v) ((v)->val)\r
-#define atomic_set(v, s) ((v)->val = s)\r
-\r
-#define stricmp strcasecmp\r
-#define strnicmp strncasecmp\r
-\r
-typedef struct { pthread_cond_t cond; pthread_mutex_t mutex; } event_t;\r
-static inline void event_init(event_t *e)\r
-{\r
- pthread_cond_init(&e->cond, NULL);\r
- pthread_mutex_init(&e->mutex, NULL);\r
-}\r
-#define event_signal(e) pthread_cond_signal(&(e)->cond)\r
-static inline int event_wait(event_t *e, int timeout) \r
-{\r
- struct timeval curtime;\r
- struct timespec wait;\r
- int ret;\r
-\r
- gettimeofday(&curtime, NULL);\r
- wait.tv_sec = curtime.tv_sec + ((unsigned) timeout) / 1000;\r
- wait.tv_nsec = (curtime.tv_usec + (((unsigned) timeout) % 1000) * 1000) * 1000;\r
- pthread_mutex_lock(&e->mutex);\r
- ret = pthread_cond_timedwait(&e->cond, &e->mutex, &wait);\r
- pthread_mutex_unlock(&e->mutex);\r
- return ret;\r
-}\r
-\r
-#define lock_t pthread_mutex_t\r
-#define lock_init(x) pthread_mutex_init(x, NULL)\r
-#define lock_acquire pthread_mutex_lock\r
-#define lock_release pthread_mutex_unlock\r
-\r
-#define osd_init() 0\r
-#define osd_close()\r
-\r
-#define SOCKET int\r
-#define SOCKET_ERROR -1\r
-#define INVALID_SOCKET -1\r
-#define socket_errno() errno\r
-#define closesocket close\r
-\r
-static inline uint64_t time_stamp_us(void)\r
-{\r
- struct timeval curtime;\r
- timerclear(&curtime);\r
- gettimeofday(&curtime, NULL);\r
- return (uint64_t) curtime.tv_sec * 1000000 + (uint64_t) curtime.tv_usec;\r
-}\r
-\r
-#define time_stamp_ms() (time_stamp_us() / (uint64_t) 1000)\r
-#define time_stamp_sec() (time_stamp_ms() / (uint64_t) 1000)\r
-#define time_stamp_min() (time_stamp_sec() / (uint64_t) 60)\r
-\r
-#define PER_THREAD __thread\r
-static inline int beginthread(void (*func)(void *), void *arg)\r
-{\r
- pthread_t thread;\r
- return pthread_create(&thread, NULL, (void *(*)(void*)) func, arg);\r
-}\r
-\r
-#endif /* OSD_H */\r
-\r
+
+#define container_of(ptr, type, field) \
+ ((type *) ((void *) ptr - offsetof(type, field)))
+
+#define min(a, b) (a < b ? a : b)
+#define max(a, b) (a > b ? a : b)
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define htonll(x) bswap_64(x)
+#else
+#define htonll(x) (x)
+#endif
+#define ntohll(x) htonll(x)
+
+#if DEFINE_ATOMICS
+typedef struct { pthread_mutex_t mut; int val; } atomic_t;
+static inline int atomic_inc(atomic_t *atomic)
+{
+ int v;
+
+ pthread_mutex_lock(&atomic->mut);
+ v = ++(atomic->val);
+ pthread_mutex_unlock(&atomic->mut);
+ return v;
+}
+static inline int atomic_dec(atomic_t *atomic)
+{
+ int v;
+
+ pthread_mutex_lock(&atomic->mut);
+ v = --(atomic->val);
+ pthread_mutex_unlock(&atomic->mut);
+ return v;
+}
+static inline void atomic_init(atomic_t *atomic)
+{
+ pthread_mutex_init(&atomic->mut, NULL);
+ atomic->val = 0;
+}
+#else
+typedef struct { volatile int val; } atomic_t;
+#define atomic_inc(v) (__sync_add_and_fetch(&(v)->val, 1))
+#define atomic_dec(v) (__sync_sub_and_fetch(&(v)->val, 1))
+#define atomic_init(v) ((v)->val = 0)
+#endif
+#define atomic_get(v) ((v)->val)
+#define atomic_set(v, s) ((v)->val = s)
+
+#define stricmp strcasecmp
+#define strnicmp strncasecmp
+
+typedef struct { pthread_cond_t cond; pthread_mutex_t mutex; } event_t;
+static inline void event_init(event_t *e)
+{
+ pthread_cond_init(&e->cond, NULL);
+ pthread_mutex_init(&e->mutex, NULL);
+}
+#define event_signal(e) pthread_cond_signal(&(e)->cond)
+static inline int event_wait(event_t *e, int timeout)
+{
+ struct timeval curtime;
+ struct timespec wait;
+ int ret;
+
+ gettimeofday(&curtime, NULL);
+ wait.tv_sec = curtime.tv_sec + ((unsigned) timeout) / 1000;
+ wait.tv_nsec = (curtime.tv_usec + (((unsigned) timeout) % 1000) * 1000) * 1000;
+ pthread_mutex_lock(&e->mutex);
+ ret = pthread_cond_timedwait(&e->cond, &e->mutex, &wait);
+ pthread_mutex_unlock(&e->mutex);
+ return ret;
+}
+
+#define lock_t pthread_mutex_t
+#define lock_init(x) pthread_mutex_init(x, NULL)
+#define lock_acquire pthread_mutex_lock
+#define lock_release pthread_mutex_unlock
+
+#define osd_init() 0
+#define osd_close()
+
+#define SOCKET int
+#define SOCKET_ERROR -1
+#define INVALID_SOCKET -1
+#define socket_errno() errno
+#define closesocket close
+
+static inline uint64_t time_stamp_us(void)
+{
+ struct timeval curtime;
+ timerclear(&curtime);
+ gettimeofday(&curtime, NULL);
+ return (uint64_t) curtime.tv_sec * 1000000 + (uint64_t) curtime.tv_usec;
+}
+
+#define time_stamp_ms() (time_stamp_us() / (uint64_t) 1000)
+#define time_stamp_sec() (time_stamp_ms() / (uint64_t) 1000)
+#define time_stamp_min() (time_stamp_sec() / (uint64_t) 60)
+
+#define PER_THREAD __thread
+static inline int beginthread(void (*func)(void *), void *arg)
+{
+ pthread_t thread;
+ return pthread_create(&thread, NULL, (void *(*)(void*)) func, arg);
+}
+
+#endif /* OSD_H */