void * acqrel_thr(void *id) { int me = (int)(long)id; int i; for (i = 0; i < NITERS; ++i) if (me & 1) { AO_T my_counter1; if (me != 1) fprintf(stderr, "acqrel test: too many threads\n"); my_counter1 = AO_load(&counter1); AO_store(&counter1, my_counter1 + 1); AO_store_release_write(&counter2, my_counter1 + 1); } else { AO_T my_counter2; AO_T my_counter1; my_counter2 = AO_load_acquire_read(&counter2); my_counter1 = AO_load(&counter1); if (my_counter1 < my_counter2) { fprintf(stderr, "Saw release store out of order: %lu < %lu\n", (unsigned long)my_counter1, (unsigned long)my_counter2); abort(); } } return 0; }
static cufo_termstyle_t _default_termstyle(void) { static pthread_mutex_t mutex = CU_MUTEX_INITIALISER; static AO_t done_init = 0; static struct cufo_termstyle style; if (!AO_load_acquire_read(&done_init)) { char const *style_name; cu_mutex_lock(&mutex); cufo_termstyle_init(&style); style_name = getenv("CUFO_STYLE"); if (style_name == NULL) { char const *background = getenv("BACKGROUND"); if (background && strcmp(background, "dark") == 0) style_name = "default-dark"; else style_name = "default-light"; } if (!cufo_termstyle_loadinto(&style, cu_str_new_cstr(style_name))) cu_warnf("Could not load cufo-style definition %s.", style_name); AO_store_release_write(&done_init, 1); cu_mutex_unlock(&mutex); } return &style; }
void * acqrel_thr(void *id) { int me = (int)(AO_PTRDIFF_T)id; int i; for (i = 0; i < NITERS; ++i) if (me & 1) { AO_t my_counter1; if (me != 1) { fprintf(stderr, "acqrel test: too many threads\n"); abort(); } my_counter1 = AO_load(&counter1); AO_store(&counter1, my_counter1 + 1); AO_store_release_write(&counter2, my_counter1 + 1); } else { AO_t my_counter1a, my_counter2a; AO_t my_counter1b, my_counter2b; my_counter2a = AO_load_acquire_read(&counter2); my_counter1a = AO_load(&counter1); /* Redo this, to make sure that the second load of counter1 */ /* is not viewed as a common subexpression. */ my_counter2b = AO_load_acquire_read(&counter2); my_counter1b = AO_load(&counter1); if (my_counter1a < my_counter2a) { fprintf(stderr, "Saw release store out of order: %lu < %lu\n", (unsigned long)my_counter1a, (unsigned long)my_counter2a); abort(); } if (my_counter1b < my_counter2b) { fprintf(stderr, "Saw release store out of order (bad CSE?): %lu < %lu\n", (unsigned long)my_counter1b, (unsigned long)my_counter2b); abort(); } } return 0; }
static inline void init() { AM_LOCK(); if (AM_UNLIKELY(!AO_load_acquire_read(&isInitialized))) { if (0 == isInitialized) { get_log_level(); get_log_target(); get_timestamp_setting(); AO_store_release_write(&isInitialized, 1); } } AM_UNLOCK(); }
cutext_sink_t cufo_termsink_new(cufo_termstyle_t termstyle, char const *term, char const *encoding, int fd, cu_bool_t close_fd) { static AO_t done_init = 0; _termsink_t sink; cutext_sink_t subsink; int err; subsink = cutext_sink_fdopen(encoding, fd, close_fd); cutext_sink_assert_clogfree(subsink); if (setupterm(term, fd, &err) != OK) { char const *err_msg; switch (err) { case -1: err_msg = "terminfo database could not be found."; case 0: err_msg = "terminal type not found or too generic."; case 1: err_msg = "your terminal is a hardcopy."; default: err_msg = "setupterm returned an unknown error code."; } cu_errf("Could not open terminal stream because %s", err_msg); return NULL; } if (!AO_load_acquire_read(&done_init)) { cu_mutex_lock(&_curses_mutex); _tistr.setaf = _tigetstr_alt("setaf", "setf"); _tistr.setab = _tigetstr_alt("setab", "setb"); _tistr.sitm = _tigetstr("sitm"); _tistr.ritm = _tigetstr("ritm"); _tistr.smul = _tigetstr("smul"); _tistr.rmul = _tigetstr("rmul"); _tistr.bold = _tigetstr("bold"); _tistr.rev = _tigetstr("rev"); _tistr.sgr0 = _tigetstr("sgr0"); _tistr.cols = _tigetint("cols", 0); _tistr.colors = _tigetint("colors", 8); AO_store_release_write(&done_init, 1); cu_mutex_unlock(&_curses_mutex); } sink = cu_gnew(struct _termsink); cutext_sink_init(cu_to(cutext_sink, sink), &_termsink_descriptor); sink->subsink = subsink; sink->style = termstyle; sink->current_state = &_initial_state; return cu_to(cutext_sink, sink); }