aboutsummaryrefslogtreecommitdiff
path: root/src/common/compat_threads.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/compat_threads.h')
-rw-r--r--src/common/compat_threads.h24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/common/compat_threads.h b/src/common/compat_threads.h
index 171a9f93ff..42f14eab2a 100644
--- a/src/common/compat_threads.h
+++ b/src/common/compat_threads.h
@@ -1,6 +1,6 @@
/* Copyright (c) 2003-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2016, The Tor Project, Inc. */
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
#ifndef TOR_COMPAT_THREADS_H
@@ -20,7 +20,7 @@
#define USE_PTHREADS
#else
#error "No threading system was found"
-#endif
+#endif /* defined(_WIN32) || ... */
int spawn_func(void (*func)(void *), void *data);
void spawn_exit(void) ATTR_NORETURN;
@@ -41,7 +41,7 @@ typedef struct tor_mutex_t {
#else
/** No-threads only: Dummy variable so that tor_mutex_t takes up space. */
int _unused;
-#endif
+#endif /* defined(USE_WIN32_THREADS) || ... */
} tor_mutex_t;
tor_mutex_t *tor_mutex_new(void);
@@ -73,7 +73,7 @@ typedef struct tor_cond_t {
int generation;
#else
#error no known condition implementation.
-#endif
+#endif /* defined(USE_PTHREADS) || ... */
} tor_cond_t;
tor_cond_t *tor_cond_new(void);
@@ -147,5 +147,19 @@ void *tor_threadlocal_get(tor_threadlocal_t *threadlocal);
*/
void tor_threadlocal_set(tor_threadlocal_t *threadlocal, void *value);
-#endif
+/**
+ * Atomic counter type; holds a size_t value.
+ */
+typedef struct atomic_counter_t {
+ tor_mutex_t mutex;
+ size_t val;
+} atomic_counter_t;
+
+void atomic_counter_init(atomic_counter_t *counter);
+void atomic_counter_destroy(atomic_counter_t *counter);
+void atomic_counter_add(atomic_counter_t *counter, size_t add);
+void atomic_counter_sub(atomic_counter_t *counter, size_t sub);
+size_t atomic_counter_get(atomic_counter_t *counter);
+
+#endif /* !defined(TOR_COMPAT_THREADS_H) */