~pbxt-core/pbxt/2.0

« back to all changes in this revision

Viewing changes to src/lock_xt.cc

  • Committer: Paul McCullagh
  • Date: 2010-05-03 12:43:05 UTC
  • mfrom: (831.2.21 1.5-trunk)
  • Revision ID: paul.mccullagh@primebase.org-20100503124305-ifpcfm7234cx4371
Merged with 1.5 trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1141
1141
        sxs->sxs_locker = thd_id;
1142
1142
#endif
1143
1143
 
1144
 
        /* Wait for all the reader to wait! */
1145
 
        while (sxs->sxs_wait_count < sxs->sxs_rlock_count)
1146
 
                xt_yield();
 
1144
        /* Wait for all the readers to wait! */
 
1145
        while (sxs->sxs_wait_count < sxs->sxs_rlock_count) {
 
1146
                sxs->sxs_xwaiter = 1;
 
1147
                xt_yield(); //*
 
1148
                /* This should not be required, because there is only one thread
 
1149
                 * accessing this value. However, the lock fails if this
 
1150
                 * is not done with an atomic op.
 
1151
                 *
 
1152
                 * This is because threads on other processors have the
 
1153
                 * value in processor cache. So they do not
 
1154
                 * notice that the value has been set to zero.
 
1155
                 * They think it is still 1 and march through
 
1156
                 * the barrier (sxs->sxs_xwaiter < sxs->sxs_xlocked) below.
 
1157
                 *
 
1158
                 * In the meantime, this X locker has gone on thinking
 
1159
                 * all is OK.
 
1160
                 */
 
1161
                xt_atomic_tas2(&sxs->sxs_xwaiter, 0);
 
1162
        }
1147
1163
 
1148
1164
#ifdef XT_THREAD_LOCK_INFO
1149
1165
        xt_thread_lock_info_add_owner(&sxs->sxs_lock_info);
1155
1171
{
1156
1172
        xt_atomic_inc2(&sxs->sxs_rlock_count);
1157
1173
 
1158
 
        /* Check if there could be an X locker: */
1159
 
        if (sxs->sxs_xlocked) {
1160
 
                /* I am waiting... */
 
1174
        /* Wait as long as the locker is not waiting: */
 
1175
        while (sxs->sxs_xwaiter < sxs->sxs_xlocked) {
1161
1176
                xt_atomic_inc2(&sxs->sxs_wait_count);
1162
 
                while (sxs->sxs_xlocked)
 
1177
                while (sxs->sxs_xwaiter < sxs->sxs_xlocked) {
1163
1178
                        xt_yield();
 
1179
                }
1164
1180
                xt_atomic_dec2(&sxs->sxs_wait_count);
1165
1181
        }
1166
1182