summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
ab179a1)
unsigned wraps properly in C (modulo ULONG_MAX + 1), IOW ULONG_MAX + 2
_is_ defined and is 1.
Rewrite rcu_gp_ongoing test to work in the unsigned case:
a - b < 0
becomes
a - b > ULONG_MAX / 2
This test actually means a - b > 0x7f....f which is exactly what we want
to test for in the first place, but in a portable way.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
#include <stdlib.h>
#include <pthread.h>
#include <assert.h>
#include <stdlib.h>
#include <pthread.h>
#include <assert.h>
#include <compiler.h>
#include <arch.h>
#include <compiler.h>
#include <arch.h>
* Using a int rather than a char to eliminate false register dependencies
* causing stalls on some architectures.
*/
* Using a int rather than a char to eliminate false register dependencies
* causing stalls on some architectures.
*/
-extern long urcu_gp_ctr;
+extern unsigned long urcu_gp_ctr;
-extern long __thread rcu_reader_qs_gp;
+extern unsigned long __thread rcu_reader_qs_gp;
-static inline int rcu_gp_ongoing(long *value)
+static inline int rcu_gp_ongoing(unsigned long *value)
+ unsigned long reader_gp;
if (value == NULL)
return 0;
reader_gp = LOAD_SHARED(*value);
if (value == NULL)
return 0;
reader_gp = LOAD_SHARED(*value);
- return reader_gp && (reader_gp - urcu_gp_ctr < 0);
+ return reader_gp && (reader_gp - urcu_gp_ctr > ULONG_MAX / 2);
}
static inline void _rcu_read_lock(void)
}
static inline void _rcu_read_lock(void)
/*
* Global grace period counter.
*/
/*
* Global grace period counter.
*/
+unsigned long urcu_gp_ctr = 1;
/*
* Written to only by each individual reader. Read by both the reader and the
* writers.
*/
/*
* Written to only by each individual reader. Read by both the reader and the
* writers.
*/
-long __thread rcu_reader_qs_gp;
+unsigned long __thread rcu_reader_qs_gp;
/* Thread IDs of registered readers */
#define INIT_NUM_THREADS 4
struct reader_registry {
pthread_t tid;
/* Thread IDs of registered readers */
#define INIT_NUM_THREADS 4
struct reader_registry {
pthread_t tid;
- long *rcu_reader_qs_gp;
+ unsigned long *rcu_reader_qs_gp;
void synchronize_rcu(void)
{
void synchronize_rcu(void)
{
+ unsigned long was_online;
was_online = rcu_reader_qs_gp;
was_online = rcu_reader_qs_gp;