Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
Alexander Vdolainen | c7349c628d | 9 years ago |
Alexander Vdolainen | af2c8aca25 | 9 years ago |
Alexander Vdolainen | 9c2cc9bb2f | 9 years ago |
@ -1 +1,2 @@
|
|||||||
nobase_include_HEADERS = tdata/bitwise.h tdata/idx_allocator.h tdata/macro.h tdata/tree.h tdata/usrtc.h tdata/list.h
|
nobase_include_HEADERS = tdata/bitwise.h tdata/idx_allocator.h tdata/macro.h \
|
||||||
|
tdata/tree.h tdata/usrtc.h tdata/list.h tdata/ctrie.h
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
|
||||||
|
/*
|
||||||
|
* cas.c
|
||||||
|
* Copyright (C) 2015 Alexander Vdolainen <avdolainen@gmail.com>
|
||||||
|
*
|
||||||
|
* libtdata is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* libtdata is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __TDATA_CTRIE_H__
|
||||||
|
#define __TDATA_CTRIE_H__
|
||||||
|
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
|
/* flags */
|
||||||
|
#define CTRIE_FLAG_RO (1 << 1)
|
||||||
|
|
||||||
|
/* structure Ctrie (flags is also underlying node type) */
|
||||||
|
typedef struct __ctrie_type {
|
||||||
|
int flags;
|
||||||
|
void **root;
|
||||||
|
}__attribute__((packed)) ctrie_t;
|
||||||
|
|
||||||
|
/* structure SNode (key-value node) */
|
||||||
|
typedef struct __ctrie_snode {
|
||||||
|
ct_key_t key;
|
||||||
|
void *value;
|
||||||
|
}__attribute__((packed)) ct_snode_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __TDATA_CTRIE_H__ */
|
@ -0,0 +1,51 @@
|
|||||||
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
|
||||||
|
/*
|
||||||
|
* cas.c
|
||||||
|
* Copyright (C) 2015 Alexander Vdolainen <avdolainen@gmail.com>
|
||||||
|
*
|
||||||
|
* libtdata is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as published
|
||||||
|
* by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* libtdata is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
|
#if !defined (HAVE__SYNC_BOOL_COMPARE_AND_SWAP_8)
|
||||||
|
#include <pthread.h>
|
||||||
|
static pthread_mutex_t __sync_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE__SYNC_BOOL_COMPARE_AND_SWAP_8
|
||||||
|
_Bool __sync_bool_compare_and_swap_8 (uint64_t*, uint64_t, uint64_t)
|
||||||
|
__attribute__ ((visibility ("hidden")));
|
||||||
|
|
||||||
|
_Bool __sync_bool_compare_and_swap_8 (uint64_t* ptr, uint64_t old, uint64_t new)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
_Bool ret;
|
||||||
|
|
||||||
|
i = pthread_mutex_lock(&__sync_lock);
|
||||||
|
|
||||||
|
if(*ptr != old) ret = 0;
|
||||||
|
else {
|
||||||
|
*ptr = new;
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = pthread_mutex_unlock(&__sync_lock);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
Loading…
Reference in New Issue