123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- ({ \
- __typeof (*location) _result; \
- if(sizeof(*location) == 1){ \
- __asm__ __volatile__ ( \
- "lock\n\t" \
- "cmpxchgb %b2,(%1)" \
- :"=a" (_result) \
- :"r" (location), "r" (value), "a" (comparand) \
- :"memory", "cc"); \
- } else if(sizeof(*location) == 2){ \
- __asm__ __volatile__ ( \
- "lock\n\t" \
- "cmpxchgw %w2,(%1)" \
- :"=a" (_result) \
- :"r" (location), "r" (value), "a" (comparand) \
- :"memory", "cc"); \
- } else if(sizeof(*location) == 4){ \
- __asm__ __volatile__ ( \
- "lock\n\t" \
- "cmpxchgl %w2,(%1)" \
- :"=a" (_result) \
- :"r" (location), "r" (value), "a" (comparand) \
- :"memory", "cc"); \
- } else { \
- __asm__ __volatile__ ( \
- "lock\n\t" \
- "cmpxchgq %2,(%1)" \
- :"=a" (_result) \
- :"r" (location), "r" (value), "a" (comparand) \
- :"memory", "cc"); \
- } \
- _result; \
- })
- struct tname
- struct tname
- struct tname
- int n_cpu; \
- int t_idx; \
- volatile int running; \
- volatile int state; \
- volatile int once; \
- pthread_mutex_t *mutex_lock; \
- pthread_rwlock_t *rw_lock; \
- pthread_mutex_t _COND_LOCK; \
- pthread_cond_t _COND
- struct tname
- pthread_t *tname
- pthread_mutex_t *tname
- pthread_rwlock_t *tname
- struct tname
- int tname
- int tname
- int tname
- struct tname
- int tname
- struct tname
- tname
- if(tname
- fprintf(stderr, " -- Unexcepted error in thread [%s] in %s -- %s:%d --\n",
- }
- struct tname
- int tname
- struct tname
- tname
- if(tname
- fprintf(stderr, " -- Unexcepted error in thread [%s] in %s -- %s:%d --\n",
- }
- pthread_mutex_lock(&tname->_COND_LOCK); \
- tname->state = 0; \
- pthread_cond_signal(&tname->_COND); \
- pthread_mutex_unlock(&tname->_COND_LOCK); \
- while(tname->running){ \
- if(tname->state != 1){ \
- struct timespec _timeout; \
- pthread_mutex_lock(&tname->_COND_LOCK); \
- clock_gettime(CLOCK_REALTIME, &_timeout); \
- _timeout.tv_nsec += 1000000; \
- pthread_cond_timedwait(&tname->_COND, &tname->_COND_LOCK, &_timeout); \
- pthread_mutex_unlock(&tname->_COND_LOCK); \
- continue; \
- } \
- for(tname
- } \
- if(tname->once){ \
- pthread_mutex_lock(&tname->_COND_LOCK); \
- tname->state = 2; \
- pthread_cond_signal(&tname->_COND); \
- pthread_mutex_unlock(&tname->_COND_LOCK); \
- } \
- } \
- pthread_mutex_lock(&tname->_COND_LOCK); \
- tname->state = 2; \
- pthread_cond_signal(&tname->_COND); \
- pthread_mutex_unlock(&tname->_COND_LOCK)
- thread_def_shared_vars(tname); \
- (void)(tname
- (void)(tname
- (void)(tname
- (void)(tname
- (void)(tname); \
- tname
- tname
- tname
- tname
- tname
- tname
- *tname
- tname
- *tname
- for(tname
- tname = tname
- tname->mutex_lock = tname
- tname->rw_lock = tname
- tname->_COND_LOCK = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER; \
- tname->_COND = (pthread_cond_t)PTHREAD_COND_INITIALIZER; \
- tname->n_cpu = n_thread;\
- tname->t_idx = tname
- tname->running = 1;\
- tname->state = 3;\
- tname->once = 1;\
- tname->tname
- tname->tname
- if(pthread_create(tname
- fprintf(stderr, " -- Failed to create thread [%s, %04d] in %s -- %s:%d --\n",
- exit(1);\
- }\
- while(1){ \
- int _stop; \
- _stop = 0; \
- if(tname->state == 0) _stop = 1; \
- else { \
- struct timespec _timeout; \
- pthread_mutex_lock(&tname->_COND_LOCK); \
- clock_gettime(CLOCK_REALTIME, &_timeout); \
- _timeout.tv_nsec += 1000000; \
- pthread_cond_timedwait(&tname->_COND, &tname->_COND_LOCK, &_timeout); \
- if(tname->state == 0) _stop = 1; \
- pthread_mutex_unlock(&tname->_COND_LOCK); \
- } \
- if(_stop) break; \
- } \
- }\
- tname = tname
- tname
- tname
- tname
- do { \
- _tname = tname; \
- params = tname
- pids = tname
- mlock = tname
- rwlock = tname
- i = tname
- j = tname
- next = tname
- } while(0)
- do { \
- tname = _tname; \
- tname
- tname
- tname
- tname
- tname
- tname
- tname
- } while(0)
- while(1){ \
- int _stop; \
- _stop = 0; \
- pthread_mutex_lock(&tname->_COND_LOCK); \
- if(tname->state != 1) _stop = 1; \
- else { \
- struct timespec _timeout; \
- clock_gettime(CLOCK_REALTIME, &_timeout); \
- _timeout.tv_nsec += 1000; \
- pthread_cond_timedwait(&tname->_COND, &tname->_COND_LOCK, &_timeout); \
- if(tname->state != 1) _stop = 1; \
- } \
- pthread_mutex_unlock(&tname->_COND_LOCK); \
- if(_stop) break; \
- } \
- tname->state = 0
- while(1){ \
- nano_sleep(usec)
- for(tname
- if(tname
- } \
- if(tname
- }
- while(1){ \
- for(;tname
- if(tname
- tname = tname
- break; \
- } \
- } \
- if(tname
- tname
- nano_sleep(10); \
- } else { \
- tname
- break; \
- } \
- } \
- tname->state = 0
- while(1){ \
- int _nrun_; \
- _nrun_ = 0; \
- for(tname
- if(tname
- tname = tname
- break; \
- } else if(tname
- _nrun_ ++; \
- } \
- } \
- if(tname
- tname
- if(_nrun_ == 0){ \
- tname = tname
- tname
- break; \
- } else { \
- nano_sleep(10); \
- } \
- } else { \
- tname
- break; \
- } \
- } \
- tname->state = 0
- tname = tname
- pthread_mutex_lock(&tname->_COND_LOCK); \
- tname->running = 0; \
- pthread_cond_signal(&tname->_COND); \
- pthread_mutex_unlock(&tname->_COND_LOCK); \
- thread_wait(tname);\
- pthread_join(tname
- { \
- thread_beg_def(tname); \
- vars_expr \
- thread_end_def(tname); \
- thread_begin_func_core(tname); \
- pre_expr \
- thread_beg_loop(tname); \
- loop_expr \
- thread_end_loop(tname); \
- post_expr \
- thread_end_func(tname); \
- { \
- thread_preprocess(tname); \
- thread_beg_init(tname, ncpu); \
- init_expr \
- thread_end_init(tname); \
- invoke_expr \
- thread_beg_close(tname); \
- free_expr \
- thread_end_close(tname); \
- } \
- }
- { \
- thread_beg_def(tname); \
- thread_end_def(tname); \
- thread_begin_func_core(tname); \
- int NCPU, TIDX; \
- NCPU = tname->n_cpu; \
- TIDX = tname->t_idx; \
- UNUSED(NCPU); \
- UNUSED(TIDX); \
- thread_beg_loop(tname); \
- (expr); \
- thread_end_loop(tname); \
- thread_end_func(tname); \
- { \
- thread_preprocess(tname); \
- thread_beg_init(tname, ncpu); \
- thread_end_init(tname); \
- thread_wake_all(tname); \
- thread_wait_all(tname); \
- thread_beg_close(tname); \
- thread_end_close(tname); \
- } \
- }
|