git.haldean.org ubik / 8b2e1da
merge UBIK_SINGLETHREAD and UBIK_DISABLE_MT haldean 3 years ago
4 changed file(s) with 13 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
2121 #include <pthread.h>
2222 #include <stdint.h>
2323
24 #define UBIK_DISABLE_MT
25
2624 /* Returns the number of threads the Ubik environment should use. Guaranteed to
2725 * not change over the lifetime of the environment. */
2826 size_t
1616 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1717 */
1818
19 #include <pthread.h>
20
2119 /* Threadsafe printf; calls to this function are guaranteed to produce
2220 * non-interleaved user output. */
2321 void __attribute__((format(printf, 1, 2)))
3737 printf(opname " failed: %s (%d)\n", strerror(__err), __err); \
3838 ubik_assert(__err == 0);
3939
40 #if !UBIK_SINGLETHREAD
40 #ifndef UBIK_DISABLE_MT
4141
4242 void
4343 ubik_rwlock_init(struct ubik_rwlock *rwl)
108108
109109 #else
110110
111 void ubik_rwlock_init(struct ubik_rwlock *rwl) { unused(rwl); }
112 void ubik_rwlock_read(struct ubik_rwlock *rwl) { unused(rwl); }
113 void ubik_rwlock_write(struct ubik_rwlock *rwl) { unused(rwl); }
114 void ubik_rwlock_release(struct ubik_rwlock *rwl) { unused(rwl); }
115 void ubik_rwlock_destroy(struct ubik_rwlock *rwl) { unused(rwl); }
111 void ubik_rwlock_init(struct ubik_rwlock *) {}
112 void ubik_rwlock_read(struct ubik_rwlock *) {}
113 void ubik_rwlock_write(struct ubik_rwlock *) {}
114 void ubik_rwlock_release(struct ubik_rwlock *) {}
115 void ubik_rwlock_destroy(struct ubik_rwlock *) {}
116116
117117 #endif
118118
1616 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1717 */
1818
19 #include "ubik/mt.h"
1920 #include "ubik/mtio.h"
2021
22 #include <pthread.h>
2123 #include <stdarg.h>
2224 #include <stdio.h>
2325
24 static pthread_mutex_t mtio_lock = PTHREAD_MUTEX_INITIALIZER;
26 #ifndef UBIK_DISABLE_MT
27 static ubik_mutex mtio_lock = PTHREAD_MUTEX_INITIALIZER;
28 #endif
2529
2630 void ubik_mtprintf(char *fmt, ...)
2731 {
2832 va_list ap;
2933
3034 va_start(ap, fmt);
31 pthread_mutex_lock(&mtio_lock);
35 ubik_lock(&mtio_lock);
3236 vprintf(fmt, ap);
33 pthread_mutex_unlock(&mtio_lock);
37 ubik_unlock(&mtio_lock);
3438 }
3539