A SystemC productivity library for virtual platform development utilizing SCV and TLM2.0 https://www.minres.com/#opensource
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*******************************************************************************
  2. * Copyright 2019 MINRES Technologies GmbH
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *******************************************************************************/
  16. #pragma once
  17. #include "sysc/communication/sc_semaphore_if.h"
  18. #include "sysc/kernel/sc_event.h"
  19. #include "sysc/kernel/sc_object.h"
  20. #include <deque>
  21. #include <sysc/kernel/sc_process_handle.h>
  22. namespace scc {
  23. // ----------------------------------------------------------------------------
  24. // CLASS : sc_semaphore
  25. //
  26. // The sc_semaphore primitive channel class.
  27. // ----------------------------------------------------------------------------
  28. class ordered_semaphore : public sc_core::sc_semaphore_if, public sc_core::sc_object {
  29. public:
  30. // constructors
  31. explicit ordered_semaphore(int init_value_);
  32. ordered_semaphore(const char* name_, int init_value_);
  33. // interface methods
  34. // lock (take) the semaphore, block if not available
  35. virtual int wait();
  36. // lock (take) the semaphore, return -1 if not available
  37. virtual int trywait();
  38. // unlock (give) the semaphore
  39. virtual int post();
  40. // get the value of the semaphore
  41. virtual int get_value() const { return m_value; }
  42. virtual const char* kind() const { return "sc_semaphore_ordered"; }
  43. protected:
  44. // support methods
  45. bool in_use() {
  46. bool avail = m_value > 0 && queue.front() == sc_core::sc_get_current_process_handle();
  47. if(avail)
  48. queue.pop_front();
  49. return (!avail);
  50. }
  51. // error reporting
  52. void report_error(const char* id, const char* add_msg = 0) const;
  53. protected:
  54. sc_core::sc_event m_free; // event to block on when m_value is negative
  55. int m_value; // current value of the semaphore
  56. std::deque<sc_core::sc_process_handle> queue;
  57. private:
  58. // disabled
  59. ordered_semaphore(const ordered_semaphore&);
  60. ordered_semaphore& operator=(const ordered_semaphore&);
  61. };
  62. } // namespace scc