Previous 199869 Revisions Next

r17416 Thursday 23rd August, 2012 at 06:39:14 UTC by Miodrag Milanović
cothread removed, was not used for a long time and was commented (no whatsnew)
[src/emu]cothread.c cothread.h diexec.c diexec.h schedule.c schedule.h
[src/lib]cothread

trunk/src/emu/cothread.c
r17415r17416
1/***************************************************************************
2
3    cothread.c
4
5    Class wrapper around byuu's cothread library.
6
7****************************************************************************
8
9    Copyright Aaron Giles
10    All rights reserved.
11
12    Redistribution and use in source and binary forms, with or without
13    modification, are permitted provided that the following conditions are
14    met:
15
16        * Redistributions of source code must retain the above copyright
17          notice, this list of conditions and the following disclaimer.
18        * Redistributions in binary form must reproduce the above copyright
19          notice, this list of conditions and the following disclaimer in
20          the documentation and/or other materials provided with the
21          distribution.
22        * Neither the name 'MAME' nor the names of its contributors may be
23          used to endorse or promote products derived from this software
24          without specific prior written permission.
25
26    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36    POSSIBILITY OF SUCH DAMAGE.
37
38***************************************************************************/
39
40#include "emu.h"
41#include "cothread/libco.h"
42
43
44//**************************************************************************
45//  GLOBAL VARIABLES
46//**************************************************************************
47
48// static members of the cothread class
49osd_lock *cothread::s_create_lock = osd_lock_alloc();
50cothread *cothread::s_create_cothread;
51
52
53
54//**************************************************************************
55//  COTHREAD
56//**************************************************************************
57
58//-------------------------------------------------
59//  cothread - constructor
60//-------------------------------------------------
61
62cothread::cothread(cothread_t existing_thread)
63   : m_cothread(existing_thread),
64     m_creator_cothread(NULL)
65{
66}
67
68cothread::cothread(cothread_entry_delegate entry, size_t stack)
69   : m_cothread(NULL),
70     m_creator_cothread(co_active()),
71     m_entry(entry)
72{
73   // due to the lack of input parameter to the entry function,
74   // all cothread creation is explicitly serialized
75   osd_lock_acquire(s_create_lock);
76   s_create_cothread = this;
77   m_cothread = co_create(stack, &cothread_entry);
78   co_switch(m_cothread);
79   osd_lock_release(s_create_lock);
80}
81
82
83//-------------------------------------------------
84//  cothread_entry - static entry point
85//-------------------------------------------------
86
87void cothread::cothread_entry()
88{
89   // on first call, retrieve the static pointer and return
90   cothread *thread = s_create_cothread;
91   co_switch(thread->m_creator_cothread);
92
93   // when actually swapped in later, call the entry point
94   thread->m_entry();
95}
trunk/src/emu/cothread.h
r17415r17416
1/***************************************************************************
2
3    cothread.h
4
5    Class wrapper around byuu's cothread library.
6
7****************************************************************************
8
9    Copyright Aaron Giles
10    All rights reserved.
11
12    Redistribution and use in source and binary forms, with or without
13    modification, are permitted provided that the following conditions are
14    met:
15
16        * Redistributions of source code must retain the above copyright
17          notice, this list of conditions and the following disclaimer.
18        * Redistributions in binary form must reproduce the above copyright
19          notice, this list of conditions and the following disclaimer in
20          the documentation and/or other materials provided with the
21          distribution.
22        * Neither the name 'MAME' nor the names of its contributors may be
23          used to endorse or promote products derived from this software
24          without specific prior written permission.
25
26    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36    POSSIBILITY OF SUCH DAMAGE.
37
38***************************************************************************/
39
40#pragma once
41
42#ifndef __EMU_H__
43#error Dont include this file directly; include emu.h instead.
44#endif
45
46#ifndef __COTHREAD_H__
47#define __COTHREAD_H__
48
49#include "cothread/libco.h"
50
51
52//**************************************************************************
53//  TYPE DEFINITIONS
54//**************************************************************************
55
56// delegate that points to a thread's entry
57typedef delegate<void ()> cothread_entry_delegate;
58
59
60// ======================> cothread
61
62class cothread
63{
64public:
65   // construction/destruction
66   cothread(cothread_t existing_thread);
67   cothread(cothread_entry_delegate entry, size_t stack = 1048576);
68   ~cothread() { if (m_creator_cothread != NULL) co_delete(m_cothread); }
69
70   // switching
71   void make_active() { co_switch(m_cothread); }
72
73private:
74   // internal helpers
75   static void cothread_entry();
76
77   // internal state
78   cothread_t         m_cothread;
79   cothread_t         m_creator_cothread;
80   cothread_entry_delegate m_entry;
81
82   // static state
83   static osd_lock *   s_create_lock;
84   static cothread *   s_create_cothread;
85};
86
87
88#endif   // __COTHREAD_H__
trunk/src/emu/schedule.c
r17415r17416
343343   m_executing_device(NULL),
344344   m_execute_list(NULL),
345345   m_basetime(attotime::zero),
346//  m_cothread(co_active()),
347346   m_timer_list(NULL),
348347   m_timer_allocator(machine.respool()),
349348   m_callback_timer(NULL),
trunk/src/emu/schedule.h
r17415r17416
165165   void abort_timeslice();
166166   void trigger(int trigid, attotime after = attotime::zero);
167167   void boost_interleave(attotime timeslice_time, attotime boost_duration);
168//  void make_active() { m_cothread.make_active(); }
169168
170169   // timers, specified by callback/name
171170   emu_timer *timer_alloc(timer_expired_delegate callback, void *ptr = NULL);
r17415r17416
210209   device_execute_interface *   m_executing_device;         // pointer to currently executing device
211210   device_execute_interface *   m_execute_list;            // list of devices to be executed
212211   attotime               m_basetime;               // global basetime; everything moves forward from here
213//  cothread                    m_cothread;                 // core scheduler thread
214212
215213   // list of active timers
216214   emu_timer *               m_timer_list;            // head of the active list
trunk/src/emu/diexec.c
r17415r17416
7272
7373device_execute_interface::device_execute_interface(const machine_config &mconfig, device_t &device)
7474   : device_interface(device),
75//    m_cothread(cothread_entry_delegate(FUNC(device_execute_interface::run_thread_wrapper), this)),
7675     m_disabled(false),
7776     m_vblank_interrupt_legacy(NULL),
7877     m_vblank_interrupt_screen(NULL),
r17415r17416
388387
389388
390389//-------------------------------------------------
391//  run_thread_wrapper - wrapper for our cothread
392//  which just calls run and then returns to the
393//  scheduler thread, over and over
394//-------------------------------------------------
395/*
396void device_execute_interface::run_thread_wrapper()
397{
398    // loop infinitely
399    device_scheduler &scheduler = device().machine().scheduler();
400    while (1)
401    {
402        // call the classic run function, then swap back to the scheduler's thread
403        execute_run();
404        scheduler.make_active();
405    }
406}
407*/
408
409//-------------------------------------------------
410390//  execute_clocks_to_cycles - convert the number
411391//  of clocks to cycles, rounding down if necessary
412392//-------------------------------------------------
trunk/src/emu/diexec.h
r17415r17416
4747#define __DIEXEC_H__
4848
4949
50// set to 1 to execute on cothread instead of directly
51//#define USE_COTHREADS 1
52
53
5450//**************************************************************************
5551//  CONSTANTS
5652//**************************************************************************
r17415r17416
222218   UINT64 total_cycles() const;
223219
224220   // required operation overrides
225//#if USE_COTHREADS
226//  void run() { m_cothread.make_active(); }
227//#else
228221   void run() { execute_run(); }
229//#endif
230222
231223protected:
232224   // internal helpers
r17415r17416
289281      void empty_event_queue();
290282   };
291283
292   // internal state
293//  cothread                m_cothread;                 // thread used for execution
294
295284   // configuration
296285   bool               m_disabled;               // disabled from executing?
297286   device_interrupt_delegate m_vblank_interrupt;      // for interrupts tied to VBLANK

Previous 199869 Revisions Next


© 1997-2024 The MAME Team