Changeset 24806

Show
Ignore:
Timestamp:
04/05/08 06:23:11 (8 months ago)
Author:
axeld
Message:

The wait_for_notifications() function now detects if it has been run from
within the notifier/writer thread, and will then flush the notifications
directly. This should fix #2008 again.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • haiku/trunk/src/system/kernel/cache/block_cache.cpp

    r24793 r24806  
    288288static sem_id sEventSemaphore; 
    289289static mutex sNotificationsLock; 
     290static thread_id sWriterNotifyThread; 
    290291static DoublyLinkedListLink<block_cache> sMarkCache; 
    291292        // TODO: this only works if the link is the first entry of block_cache 
     
    13541355 
    13551356 
    1356 static void 
    1357 notify_sync(int32 transactionID, int32 event, void *_cache) 
    1358 { 
    1359         block_cache *cache = (block_cache *)_cache; 
    1360  
    1361         cache->condition_variable.NotifyOne(); 
    1362 } 
    1363  
    1364  
    1365 static void 
    1366 wait_for_notifications(block_cache *cache) 
    1367 { 
    1368         // add sync notification 
    1369         cache_notification notification; 
    1370         set_notification(NULL, notification, TRANSACTION_WRITTEN, notify_sync, 
    1371                 cache); 
    1372  
    1373         ConditionVariableEntry<block_cache> entry; 
    1374         entry.Add(cache); 
    1375  
    1376         add_notification(cache, &notification, TRANSACTION_WRITTEN, false); 
    1377  
    1378         // wait for notification hook to be called 
    1379         entry.Wait(); 
    1380 } 
    1381  
    1382  
    13831357static block_cache * 
    13841358get_next_locked_block_cache(block_cache *last) 
     
    15601534 
    15611535 
     1536static void 
     1537notify_sync(int32 transactionID, int32 event, void *_cache) 
     1538{ 
     1539        block_cache *cache = (block_cache *)_cache; 
     1540 
     1541        cache->condition_variable.NotifyOne(); 
     1542} 
     1543 
     1544 
     1545static void 
     1546wait_for_notifications(block_cache *cache) 
     1547{ 
     1548        if (find_thread(NULL) == sWriterNotifyThread) { 
     1549                // We're the notifier thread, don't wait, but flush all pending 
     1550                // notifications directly. 
     1551                flush_pending_notifications(cache); 
     1552                return; 
     1553        } 
     1554 
     1555        // add sync notification 
     1556        cache_notification notification; 
     1557        set_notification(NULL, notification, TRANSACTION_WRITTEN, notify_sync, 
     1558                cache); 
     1559 
     1560        ConditionVariableEntry<block_cache> entry; 
     1561        entry.Add(cache); 
     1562 
     1563        add_notification(cache, &notification, TRANSACTION_WRITTEN, false); 
     1564 
     1565        // wait for notification hook to be called 
     1566        entry.Wait(); 
     1567} 
     1568 
     1569 
    15621570extern "C" status_t 
    15631571block_cache_init(void) 
     
    15781586                return sEventSemaphore; 
    15791587 
    1580         thread_id thread = spawn_kernel_thread(&block_notifier_and_writer, 
     1588        sWriterNotifyThread = spawn_kernel_thread(&block_notifier_and_writer, 
    15811589                "block writer/notifier", B_LOW_PRIORITY, NULL); 
    1582         if (thread >= B_OK) 
    1583                 send_signal_etc(thread, SIGCONT, B_DO_NOT_RESCHEDULE); 
     1590        if (sWriterNotifyThread >= B_OK) 
     1591                send_signal_etc(sWriterNotifyThread, SIGCONT, B_DO_NOT_RESCHEDULE); 
    15841592 
    15851593#ifdef DEBUG_BLOCK_CACHE