[En-Nut-Discussion] NutEnterCritical vs NutEnterCriticalAccess()

Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Thu Nov 19 12:00:20 CET 2015


>>>>> "Nathan" == Nathan Moore <nategoose at gmail.com> writes:

    Nathan> How about something like the following for each target cpu?
    Nathan> #define NutCriticalUpdate( VARIABLE, VALUE) \ do { \ size_t sz_
    Nathan> = sizeof(typeof(VARIABLE)); \ size_t sza_ =
    Nathan> sizeof(sig_atomic_t); \ typeof(VARIABLE) * VP_ = &(VARIABLE); \
    Nathan> typeof(VALUE) VAL_ = (VALUE); \ if (sz_ == sza_ &&
    Nathan> is_alligned(VP_) { \ *VP_ = VAL_; \ } else if (sz_ < sza) { \ /*
    Nathan> special consideration for cpu */ \ } else { \
    Nathan> NutEnterCritical(); \ *VP_ = VAL_; \ NutExitCritical(); \ } \ }
    Nathan> while (0) _______________________________________________

Nathan,

can you explain why you use do not use:

#define NutCriticalUpdate( VARIABLE, VALUE)               \
     do {                                                 \
              size_t sz_ = sizeof(typeof(VARIABLE));      \
              size_t sza_ = sizeof(sig_atomic_t);         \
              typeof(VARIABLE) * VP_ = &(VARIABLE);       \
              typeof(VALUE) VAL_ = (VALUE);               \
              if (sz_ <= sza_ && is_alligned(VP_)  {      \
                     *VP_ = VAL_;                         \
              } else {                                    \
                   NutEnterCritical();                    \
                   *VP_ = VAL_;                           \
                   NutExitCritical();                     \
              }                                           \
       } while (0)

Thanks
-- 
Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 1623569 ------- Fax. 06151 1623305 ---------


More information about the En-Nut-Discussion mailing list