--- linuxsampler/trunk/src/engines/InstrumentManagerThread.h 2022/01/03 17:10:09 4018 +++ linuxsampler/trunk/src/engines/InstrumentManagerThread.h 2022/01/03 17:45:26 4019 @@ -1,6 +1,6 @@ /*************************************************************************** * * - * Copyright (C) 2005 - 2012 Christian Schoenebeck * + * Copyright (C) 2005 - 2022 Christian Schoenebeck * * * * This library is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -30,6 +30,7 @@ #include "InstrumentManager.h" #include +#include namespace LinuxSampler { @@ -47,6 +48,8 @@ InstrumentManagerThread(); void StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel); void StartSettingMode(InstrumentManager* pManager, const InstrumentManager::instrument_id_t& ID, InstrumentManager::mode_t Mode); + void AddPeriodicJob(String name, std::function fn); + void RemovePeriodicJob(String name); virtual ~InstrumentManagerThread(); #if (defined(__APPLE__) && !defined(__x86_64__)) || defined(WIN32) int StopThread(); @@ -63,12 +66,23 @@ InstrumentManager::mode_t mode; ///< only for INSTR_MODE commands }; + /// Custom job to be executed on behalf of external components. + struct ext_job_t { + String name; ///< unique name of the job + std::function fn; ///< The actual callback for the job to be executed. + }; + // Instance variables. std::list queue; ///< queue with commands for loading new instruments. Mutex mutex; ///< for making the queue thread safe Condition conditionJobsLeft; ///< synchronizer to block this thread until a new job arrives + std::vector periodicJobs; ///< list of external tasks to be executed periodically + Mutex periodicJobsMutex; ///< for making access to periodicJobs thread safe + int Main(); ///< Implementation of virtual method from class Thread. + void RemovePeriodicJobWithoutLock(String name); + bool AnyPeriodicJobs(); private: class EventHandler : public ChannelCountAdapter { public: