We'll want to use these for other stuff too.
}
}
-/** As tor_mutex_init, but initialize a mutex suitable for use with a
- * condition variable. */
+/** As tor_mutex_init, but initialize a mutex suitable that may be
+ * non-reentrant, if the OS supports that. */
void
-tor_mutex_init_for_cond(tor_mutex_t *mutex)
+tor_mutex_init_nonreentrant(tor_mutex_t *mutex)
{
int err;
if (PREDICT_UNLIKELY(!threads_initialized))
tor_mutex_init(m);
return m;
}
+/** Return a newly allocated, ready-for-use mutex. This one might be
+ * non-reentrant, if that's faster. */
+tor_mutex_t *
+tor_mutex_new_nonreentrant(void)
+{
+ tor_mutex_t *m = tor_malloc_zero(sizeof(tor_mutex_t));
+ tor_mutex_init_nonreentrant(m);
+ return m;
+}
/** Release all storage and system resources held by <b>m</b>. */
void
tor_mutex_free(tor_mutex_t *m)
tor_mutex_t *tor_mutex_new(void);
+tor_mutex_t *tor_mutex_new_nonreentrant(void);
void tor_mutex_init(tor_mutex_t *m);
-void tor_mutex_init_for_cond(tor_mutex_t *m);
+void tor_mutex_init_nonreentrant(tor_mutex_t *m);
void tor_mutex_acquire(tor_mutex_t *m);
void tor_mutex_release(tor_mutex_t *m);
void tor_mutex_free(tor_mutex_t *m);
unsigned long tor_get_thread_id(void);
void tor_threads_init(void);
+/** Conditions need nonreentrant mutexes with pthreads. */
+#define tor_mutex_init_for_cond(m) tor_mutex_init_nonreentrant(m)
+
void set_main_thread(void);
int in_main_thread(void);
InitializeCriticalSection(&m->mutex);
}
void
-tor_mutex_init_for_cond(tor_mutex_t *m)
+tor_mutex_init_nonreentrant(tor_mutex_t *m)
{
InitializeCriticalSection(&m->mutex);
}