Previous 199869 Revisions Next

r34125 Wednesday 31st December, 2014 at 10:43:50 UTC by Oliver Stöneberg
more ThreadSanitizer data race warning "fixes" (nw)
[src/lib/util]chd.c chd.h
[src/osd/sdl]sdlwork.c
[src/osd/windows]winwork.c

trunk/src/lib/util/chd.c
r242636r242637
1919#include <stddef.h>
2020#include <stdlib.h>
2121#include <new>
22#include "eminline.h"
2223
2324
2425//**************************************************************************
r242636r242637
24182419
24192420      // queue the next read
24202421      for (curitem = startitem; curitem < enditem; curitem++)
2421         m_work_item[curitem % WORK_BUFFER_HUNKS].m_status = WS_READING;
2422         atomic_exchange32(&m_work_item[curitem % WORK_BUFFER_HUNKS].m_status, WS_READING);
24222423      osd_work_item_queue(m_read_queue, async_read_static, this, WORK_ITEM_FLAG_AUTO_RELEASE);
24232424      m_read_queue_offset += WORK_BUFFER_HUNKS * hunk_bytes() / 2;
24242425   }
r242636r242637
24892490      } while (0);
24902491
24912492      // reset the item and advance
2492      item.m_status = WS_READY;
2493      atomic_exchange32(&item.m_status, WS_READY);
24932494      m_write_hunk++;
24942495
24952496      // if we hit the end, finalize
r242636r242637
25022503            m_read_queue_offset = m_read_done_offset = 0;
25032504            m_write_hunk = 0;
25042505            for (int itemnum = 0; itemnum < WORK_BUFFER_HUNKS; itemnum++)
2505               m_work_item[itemnum].m_status = WS_READY;
2506               atomic_exchange32(&m_work_item[itemnum].m_status, WS_READY);
25062507         }
25072508
25082509         // wait for all reads to finish and if we're compressed, write the final SHA1 and map
r242636r242637
25552556      item.m_hash[unit].m_crc16 = crc16_creator::simple(item.m_data + unit * unit_bytes(), hunk_bytes());
25562557      item.m_hash[unit].m_sha1 = sha1_creator::simple(item.m_data + unit * unit_bytes(), hunk_bytes());
25572558   }
2558   item.m_status = WS_COMPLETE;
2559   atomic_exchange32(&item.m_status, WS_COMPLETE);
25592560}
25602561
25612562
r242636r242637
25832584
25842585   // find the best compression scheme, unless we already have a self or parent match
25852586   // (note we may miss a self match from blocks not yet added, but this just results in extra work)
2587   // TODO: data race
25862588   if (m_current_map.find(item.m_hash[0].m_crc16, item.m_hash[0].m_sha1) == hashmap::NOT_FOUND &&
25872589      m_parent_map.find(item.m_hash[0].m_crc16, item.m_hash[0].m_sha1) == hashmap::NOT_FOUND)
25882590      item.m_compression = item.m_codecs->find_best_compressor(item.m_data, item.m_compressed, item.m_complen);
25892591
25902592   // mark us complete
2591   item.m_status = WS_COMPLETE;
2593   atomic_exchange32(&item.m_status, WS_COMPLETE);
25922594}
25932595
25942596
r242636r242637
26442646         UINT32 hunknum = curoffs / hunk_bytes();
26452647         work_item &item = m_work_item[hunknum % WORK_BUFFER_HUNKS];
26462648         assert(item.m_status == WS_READING);
2647         item.m_status = WS_QUEUED;
2649         atomic_exchange32(&item.m_status, WS_QUEUED);
26482650         item.m_hunknum = hunknum;
26492651         item.m_osd = osd_work_item_queue(m_work_queue, m_walking_parent ? async_walk_parent_static : async_compress_hunk_static, &item, 0);
26502652      }
trunk/src/lib/util/chd.h
r242636r242637
530530
531531      osd_work_item *     m_osd;              // OSD work item running on this block
532532      chd_file_compressor *m_compressor;      // pointer back to the compressor
533      volatile work_status m_status;          // current status of this item
533      // TODO: had to change this to be able to use atomic_* functions on this
534      //volatile work_status m_status;          // current status of this item
535      volatile INT32      m_status;           // current status of this item
534536      UINT32              m_hunknum;          // number of the hunk we're working on
535537      UINT8 *             m_data;             // pointer to the data we are working on
536538      UINT8 *             m_compressed;       // pointer to the compressed data
trunk/src/osd/sdl/sdlwork.c
r242636r242637
436436      item->param = parambase;
437437      item->result = NULL;
438438      item->flags = flags;
439      item->done = FALSE;
439      atomic_exchange32(&item->done, FALSE);
440440
441441      // advance to the next
442442      lastitem = item;
r242636r242637
502502
503503   // if we don't have an event, create one
504504   if (item->event == NULL)
505   {
506      INT32 lockslot = osd_scalable_lock_acquire(item->queue->lock);
505507      item->event = osd_event_alloc(TRUE, FALSE);     // manual reset, not signalled
508      osd_scalable_lock_release(item->queue->lock, lockslot);
509   }
506510   else
507511      osd_event_reset(item->event);
508512
r242636r242637
719723            osd_work_item_release(item);
720724
721725         // set the result and signal the event
722         else if (item->event != NULL)
726         else
723727         {
724            osd_event_set(item->event);
725            add_to_stat(&item->queue->setevents, 1);
728            INT32 lockslot = osd_scalable_lock_acquire(item->queue->lock);
729            if (item->event != NULL)
730            {
731               osd_event_set(item->event);
732               add_to_stat(&item->queue->setevents, 1);
733            }
734            osd_scalable_lock_release(item->queue->lock, lockslot);
726735         }
727736
728737         // if we removed an item and there's still work to do, bump the stats
738         // TODO: data race
729739         if (queue->list != NULL)
730740            add_to_stat(&queue->extraitems, 1);
731741      }
trunk/src/osd/windows/winwork.c
r242636r242637
446446      item->param = parambase;
447447      item->result = NULL;
448448      item->flags = flags;
449      item->done = FALSE;
449      atomic_exchange32(&item->done, FALSE);
450450
451451      // advance to the next
452452      lastitem = item;
r242636r242637
509509
510510   // if we don't have an event, create one
511511   if (item->event == NULL)
512   {
513      INT32 lockslot = osd_scalable_lock_acquire(item->queue->lock);
512514      item->event = osd_event_alloc(TRUE, FALSE);     // manual reset, not signalled
515      osd_scalable_lock_release(item->queue->lock, lockslot);
516   }
513517   else
514         osd_event_reset(item->event);
518      osd_event_reset(item->event);
515519
516520   // if we don't have an event, we need to spin (shouldn't ever really happen)
517521   if (item->event == NULL)
r242636r242637
710714            osd_work_item_release(item);
711715
712716         // set the result and signal the event
713         else if (item->event != NULL)
717         else
714718         {
715            osd_event_set(item->event);
716            add_to_stat(&item->queue->setevents, 1);
719            INT32 lockslot = osd_scalable_lock_acquire(item->queue->lock);
720            if (item->event != NULL)
721            {
722               osd_event_set(item->event);
723               add_to_stat(&item->queue->setevents, 1);
724            }
725            osd_scalable_lock_release(item->queue->lock, lockslot);
717726         }
718727
719728         // if we removed an item and there's still work to do, bump the stats
729         // TODO: data race
720730         if (queue->list != NULL)
721731            add_to_stat(&queue->extraitems, 1);
722732      }


Previous 199869 Revisions Next


© 1997-2024 The MAME Team