summaryrefslogtreecommitdiff
path: root/src/bindings/cxx/eina_cxx/eina_thread.hh
blob: bd0cad89ae8d79a92336f9ce89a8599d176f479b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
/*
 * Copyright 2019 by its authors. See AUTHORS.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef EINA_THREAD_HH_
#define EINA_THREAD_HH_

#include <Eina.h>
#include <eina_error.hh>
#include <eina_throw.hh>

#include <memory>
#include <iterator>
#include <cstdlib>
#include <cassert>
#include <iosfwd>
#include <functional>
#include <chrono>
#include <mutex>
#include <functional>

/**
 * @addtogroup Eina_Cxx_Tools_Group Tools
 *
 * @{
 */

#define EFL_EINA_BOOST_MOVABLE_BUT_NOT_COPYABLE(x)
#define EFL_EINA_BOOST_RV_REF(x) x const&

namespace efl { namespace eina {

/**
 * @defgroup Eina_Cxx_Mutex_Group Mutex
 * @ingroup Eina_Cxx_Tools_Group
 *
 * @{
 */

/**
 * Provides an OOP interface to the @c Eina_Lock and automatic resource
 * allocation and deallocation using the RAII programming idiom.
 *
 * This class implements mutual exclusion variables (mutexes) in a way
 * that strongly resembles the STL <tt>std::mutex</tt>.
 */
struct mutex
{
  typedef Eina_Lock* native_handle_type; /**< Type for the native Eina_Lock pointer. */


  /**
   * @brief Create a new mutex.
   *
   * Automatically allocates a new mutex and does any platform dependent
   * initialization that is required.
   */
  mutex()
  {
    ::eina_lock_new(&_mutex);
  }

  /**
   * @brief Release mutex resources.
   *
   * Automatically deallocates the mutex and does any platform dependent
   * cleanup that is required.
   */
  ~mutex()
  {
    ::eina_lock_free(&_mutex);
  }

  /**
   * @brief Lock the mutex.
   * @throw <tt>eina::system_error</tt> with the code
   *        <tt>eina::errc::resource_deadlock_would_occur</tt> if the
   *        operation fails because a deadlock condition exists. If some
   *        other condition causes the lock to fail (other than the
   *        mutex being already locked) the error code will be an
   *        internal Eina error code.
   *
   * This member function locks the mutex. If the mutex is locked
   * already, this call will block until the lock is released. This is
   * appropriate in many cases, but consider using @ref try_lock() if
   * you don't need to block.
   */
  void lock()
  {
    ::Eina_Lock_Result r = ::eina_lock_take(&_mutex);
    switch(r)
      {
      case EINA_LOCK_SUCCEED:
        return;
      case EINA_LOCK_DEADLOCK:
        EFL_CXX_THROW(system_error(error_code(int(eina::errc::resource_deadlock_would_occur), 
                                              get_generic_category())));
      default:
        EFL_CXX_THROW(system_error(get_error_code()));
      }
  }

  /**
   * @brief Attempts to lock the mutex.
   * @return @c true if it succeed in locking the mutex, @c false otherwise.
   * @throw <tt>eina::system_error</tt> with the code
   *        <tt>eina::errc::resource_deadlock_would_occur</tt> if the
   *        operation fails because a deadlock condition exists. If some
   *        other condition causes the lock to fail (other than the
   *        mutex being already locked) the error code will be an
   *        internal Eina error code.
   *
   * This member function attempts to lock the mutex, identical to
   * @ref lock(), but returns immediately if the mutex is already locked.
   */
  bool try_lock()
  {
    ::Eina_Lock_Result r = ::eina_lock_take_try(&_mutex);
    switch(r)
      {
      case EINA_LOCK_SUCCEED:
        return true;
      case EINA_LOCK_FAIL:
        return false;
      case EINA_LOCK_DEADLOCK:
        EFL_CXX_THROW(system_error(error_code(int(eina::errc::resource_deadlock_would_occur), 
                                              get_generic_category())));
      default:
        EFL_CXX_THROW(system_error(get_error_code()));
      }
  }

  /**
   * @brief Unlock the lock.
   * @throw <tt>eina::system_error</tt> with the code
   *        <tt>eina::errc::resource_deadlock_would_occur</tt> if the
   *        operation fails because a deadlock condition exists. If some
   *        other condition causes the lock to fail the error code will
   *        be an internal Eina error code.
   *
   * This member function will unlock the mutex.
   *
   * @note If successful, and EINA_HAVE_DEBUG_THREADS is defined, the
   *       mutex is updated and information about the locking process
   *       is removed (e.g. thread number and backtrace for POSIX).
   */
  void unlock()
  {
    ::Eina_Lock_Result r = ::eina_lock_release(&_mutex);
    switch(r)
      {
      case EINA_LOCK_SUCCEED:
        return;
      case EINA_LOCK_DEADLOCK:
        EFL_CXX_THROW(system_error(error_code(int(eina::errc::resource_deadlock_would_occur),
                                              get_generic_category())));
      default:
        EFL_CXX_THROW(system_error(get_error_code()));
      }
  }

  /**
   * @brief Print debug information about the mutex.
   *
   * This member function prints debug information for the mutex. The
   * information is platform dependent. On POSIX systems it will print
   * the address of mutex, lock state, thread number and a backtrace.
   */
  void debug()
  {
    ::eina_lock_debug(&_mutex);
  }

  /**
   * @brief Get a handle for the wrapped @c Eina_Lock.
   * @return Handle for the native @c Eina_Lock.
   *
   * This member function returns the native @c Eina_Lock handle that is
   * wrapped inside this object.
   *
   * @warning It is important to take care when using it, since the
   * handle will be automatically released upon object destruction.
   */
  native_handle_type native_handle()
  {
    return &_mutex;
  }
private:
  /** Disabled copy constructor. **/
  mutex(mutex const&) = delete;
  /** Disabled assignment operator. **/
  mutex& operator=(mutex const&) = delete;

  /**
   * @internal
   */
  Eina_Lock _mutex;
};

/**
 * @brief Manage a mutex object by keeping it always locked.
 *
 * Inherited for the STL object <tt>std::lock_guard</tt>.
 */
using std::lock_guard;

/**
 * @brief Manages a mutex object.
 *
 * Inherited for the STL object <tt>std::unique_lock</tt>. This class
 * guarantees an unlocked status on destruction.
 */
using std::unique_lock;

/**
 * @}
 */

/**
 * @defgroup Eina_Cxx_Condition_Variable_Group Condition Variable
 * @ingroup Eina_Cxx_Tools_Group
 *
 * @{
 */

/**
 * Provides an OOP interface to the @c Eina_Condition and automatic
 * resource allocation and deallocation using the RAII programming idiom.
 *
 * This class implements condition variables in a way that strongly
 * resembles the STL <tt>std::condition_variable</tt>.
 */
struct condition_variable
{
  typedef Eina_Condition* native_handle_type; /**< Type for the native Eina_Lock pointer. */

  /**
   * @brief Create a new condition variable.
   *
   * Automatically allocates a new condition variable and does any
   * platform dependent initialization that is required.
   */
  condition_variable()
  {
    ::eina_condition_new(&_cond, _mutex.native_handle());
  }

  /**
   * @brief Release the condition variable resources.
   *
   * Automatically deallocates the condition variable and does any
   * platform dependent cleanup that is required.
   */
  ~condition_variable()
  {
    ::eina_condition_free(&_cond);
  }

  /**
   * @brief Unblock a thread waiting for this condition.
   * @throw <tt>eina::system_error</tt> on fail.
   *
   * This member function unblock a thread waiting on this condition
   * variable. If there is more than one thread waiting on this
   * condition, one of them will be unblocked, but which one is
   * undefined. If you do not know for sure that there is only one
   * thread waiting, use @ref notify_all() instead.
   */
  void notify_one()
  {
    eina::unique_lock<eina::mutex> l(_mutex);
    Eina_Bool r = eina_condition_signal(&_cond);
    if(!r)
      {
         EFL_CXX_THROW(eina::system_error(eina::get_error_code()));
      }
  }

  /**
   * @brief Unblock all threads waiting for this condition.
   * @throw <tt>eina::system_error</tt> on fail.
   *
   * This member function unblocks all the threads waiting on the this
   * condition. If you know for sure that there is only one thread
   * waiting, use @ref notify_one instead to gain a little optimization.
   */
  void notify_all()
  {
    eina::unique_lock<eina::mutex> l(_mutex);
    Eina_Bool r = eina_condition_broadcast(&_cond);
    if(!r)
      {
         EFL_CXX_THROW(eina::system_error(eina::get_error_code()));
      }
  }

  /**
   * @brief Causes a thread to wait until notified.
   * @param lock A lockable object (@c mutex, @c unique_lock, etc) that
   *             is currently locked by this thread. All concurrent
   *             calls to wait member functions of this object shall use
   *             the same lockable object.
   *
   * This member function makes a thread block until notified.
   */
  template <typename Lock>
  void wait(Lock& lock)
  {
    eina::unique_lock<eina::mutex> l(_mutex);
    lock.unlock();
    ::eina_condition_wait(&_cond);
    lock.lock();
  }

  /**
   * @brief Causes a thread to wait until notified.
   * @param lock A lockable object (@c mutex, @c unique_lock, etc) that
   *             is currently locked by this thread. All concurrent
   *             calls to wait member functions of this object shall use
   *             the same lockable object.
   * @param p A callable object or function that takes no arguments and
   *          returns a value that can be evaluated as a bool. This is
   *          called repeatedly until it evaluates to true.
   *
   * This member function only blocks the thread if @p p is evaluated to
   * @c false. In this case the thread remains blocked until notified
   * and the result of @p p evaluates to @c true.
   */
  template <typename Lock, typename Predicate>
  void wait(Lock& lock, Predicate p)
  {
    while(!p())
      wait(lock);
  }

  /**
   * @brief Get a handle for the wrapped @c Eina_Condition.
   * @return Handle for the native @c Eina_Condition.
   *
   * This member function returns the native @c Eina_Condition handle
   * that is wrapped inside this object.
   *
   * @warning It is important to take care when using it, since the
   * handle will be automatically released upon object destruction.
   */
  native_handle_type native_handle()
  {
    return &_cond;
  }
private:
  /** Disabled copy constructor. **/
  condition_variable(condition_variable const&);
  /** Disabled assignment operator. **/
  condition_variable& operator=(condition_variable const&);

  mutex _mutex; /**< @internal */
  Eina_Condition _cond; /**< @internal */
};

/**
 * @}
 */

/**
 * @defgroup Eina_Cxx_Thread_Group Thread
 * @ingroup Eina_Cxx_Tools_Group
 *
 * @{
 */

/**
 * Thread identifier.
 */
struct thread_id
{
  /**
   * @brief Creates a @c thread_id that represents all non-joinable.
   */
  thread_id() noexcept
    : _raw(0u)
  {
  }

  /**
   * @brief
   */
  thread_id(Eina_Thread raw)
    : _raw(raw) {}

  /**
   * @brief Check if two thread identifiers are the same.
   * @return @c true if the thread identifiers have the same value.
   */
  friend inline bool operator==(thread_id lhs, thread_id rhs)
  {
    return lhs._raw == rhs._raw;
  }

  /**
   * @brief Check if two thread identifiers are different.
   * @return @c true if the thread identifiers have different values.
   */
  friend inline bool operator!=(thread_id lhs, thread_id rhs)
  {
    return lhs._raw != rhs._raw;
  }

  /**
   * @brief Less than comparison of thread identifiers.
   * @param lhs @c thread_id at the left side of the expression.
   * @param rhs @c thread_id at the right side of the expression.
   * @return @c true if @c lhs is less than @c rhs, @c false otherwise.
   * @note The order established by relational operators is
   * implementation-defined.
   */
  friend inline bool operator<(thread_id lhs, thread_id rhs)
  {
    return std::less<Eina_Thread>()(lhs._raw, rhs._raw);
  }
private:
  Eina_Thread _raw; /**< @internal */

  /**
   * @brief Inserts a textual representation in the given stream.
   * @param out Output stream where the textual representation will be inserted.
   * @param id @c thread_id object.
   * @return Reference to the modified <tt>std::basic_ostream</tt> object.
   */
  template <typename charT, typename Traits>
  friend std::basic_ostream<charT, Traits>&
  operator<<(std::basic_ostream<charT, Traits>& out, thread_id id)
  {
    return out << id._raw;
  }
};

/**
 * @brief Less than or equal comparison of thread identifiers.
 * @param lhs @c thread_id at the left side of the expression.
 * @param rhs @c thread_id at the right side of the expression.
 * @return @c true if @c lhs is less than or equal to @c rhs, @c false otherwise.
 * @note The order established by relational operators is
 * implementation-defined.
 */
inline bool operator<=(thread_id lhs, thread_id rhs)
{
  return (lhs == rhs) || lhs < rhs;
}

/**
 * @brief More than comparison of thread identifiers.
 * @param lhs @c thread_id at the left side of the expression.
 * @param rhs @c thread_id at the right side of the expression.
 * @return @c true if @c lhs is more than @c rhs, @c false otherwise.
 * @note The order established by relational operators is
 * implementation-defined.
 */
inline bool operator>(thread_id lhs, thread_id rhs)
{
  return !(lhs <= rhs);
}

/**
 * @brief More than or equal comparison of thread identifiers.
 * @param lhs @c thread_id at the left side of the expression.
 * @param rhs @c thread_id at the right side of the expression.
 * @return @c true if @c lhs is more than or equal to @c rhs, @c false otherwise.
 * @note The order established by relational operators is
 * implementation-defined.
 */
inline bool operator>=(thread_id lhs, thread_id rhs)
{
  return !(lhs < rhs);
}

/**
 * @internal
 */
namespace _detail {

/**
 * @internal
 */
struct arguments
{
  Eina_Lock mutex;
  Eina_Condition condition;
  bool started;
  std::function<void()> function;
};

/**
 * @internal
 */
inline void* create_thread(void* data, Eina_Thread)
{
  arguments* args = static_cast<arguments*>(data);

  eina_lock_take(&args->mutex);

  std::function<void()> f = std::move(args->function);

  args->started = true;
  eina_condition_signal(&args->condition);
  eina_lock_release(&args->mutex);

  f();
  return 0;
}

}

/**
 * Provides an OOP interface to the @c Eina_Thread and automatic
 * resource allocation and deallocation using the RAII programming idiom.
 *
 * This class implements threads in a way that strongly resembles the
 * STL <tt>std::thread</tt>.
 */
struct thread
{
  typedef thread_id id; /**< Type for the thread identifier. */
  typedef Eina_Thread native_handle_type; /**< Type for the native Eina_Thread handle. */

  /**
   * @brief Creates a thread object that does not represent any thread of execution.
   */
  thread() noexcept
    : _joinable(false), _raw(0u)
  {
  }

  /**
   * @brief Creates a thread of execution.
   * @param f Pointer to function or callable object to execute in the new thread.
   *          The return value (if any) is ignored.
   * @param args Arguments to pass to the @p f.
   *
   * This constructor creates a thread object that represents a thread
   * of execution. The new thread of execution calls @p f passing
   * @p args as arguments (all arguments are copied/moved to
   * thread-accessible storage).
   *
   * Any exceptions thrown during evaluation and copying/moving of the
   * arguments are thrown in the current thread, not the new thread.
   */
  template <typename F, class ... Args>
  explicit thread(F&& f, Args&&... args)
  {
    _detail::arguments arguments;
    arguments.started = false;
    arguments.function = std::bind(f, args...);

    _joinable = true;
    Eina_Bool r = ::eina_lock_new(&arguments.mutex);
    if(!r) throw eina::system_error(eina::get_error_code());
    r = ::eina_condition_new(&arguments.condition, &arguments.mutex);
    if(!r) throw eina::system_error(eina::get_error_code());

    if(!eina_thread_create
       (&_raw, ::EINA_THREAD_NORMAL
        , -1, &eina::_detail::create_thread, &arguments))
      {
        eina_condition_free(&arguments.condition);
        eina_lock_free(&arguments.mutex);
        throw eina::system_error(eina::get_error_code());
      }
    Eina_Lock_Result lr = ::eina_lock_take(&arguments.mutex);
    if(lr != EINA_LOCK_SUCCEED)
      throw eina::system_error(eina::get_error_code());
    while(!arguments.started)
      {
        r = eina_condition_wait(&arguments.condition);
        if(!r) throw eina::system_error(eina::get_error_code());
      }
    lr = eina_lock_release(&arguments.mutex);
    if(lr != EINA_LOCK_SUCCEED)
      throw eina::system_error(eina::get_error_code());

    eina_condition_free(&arguments.condition);
    eina_lock_free(&arguments.mutex);
  }

  /**
   * @brief Move constructor. Transfer the thread of execution to the new object.
   * @param other Another thread object to construct this thread object with.
   *
   * This constructor creates a thread object that acquires the thread
   * of execution represented by @p other. This operation does not
   * affect the execution of the moved thread, it simply transfers its
   * handler.
   *
   * @note After this call @p other no longer represents a thread of execution.
   */
  thread(thread&& other)
    : _joinable(other._joinable), _raw(other._raw)
  {
  }

  /**
   * @brief Transfer the thread of execution.
   * @param other Another thread object to assign to this thread object.
   * @note After this call @p other no longer represents a thread of execution.
   */
  thread& operator=(thread&& other)
  {
    _raw = other._raw;
    _joinable = other._joinable;
    return *this;
  }

  /**
   * @brief Destroys the thread object.
   */
  ~thread()
  {
    assert(!joinable());
  }

  /**
   * @brief Exchanges the underlying handles of two thread objects.
   * @param other Another thread object.
   */
  void swap(thread& other) noexcept
  {
    std::swap(_raw, other._raw);
  }

  /**
   * @brief Check if the thread object identifies an active thread of execution.
   * @return @c true if the thread object identifies an active thread of execution, @c false otherwise.
   *
   * This member function checks if the thread object identifies an
   * active thread of execution. A default constructed thread is not
   * joinable, as well as a thread that its members join or detach has
   * been called.
   *
   * A thread that has finished executing code, but has not yet been
   * joined is still considered an active thread of execution and is
   * therefore joinable.
   */
  bool joinable() const noexcept
  {
    return _joinable;
  }

  /**
   * @brief Wait for the thread to finish its execution.
   *
   * This member function blocks the calling thread until the thread
   * identified by this object finishes its execution.
   *
   * @note A joinable thread becomes not joinable after a call to this
   * function.
   */
  void join()
  {
    assert(joinable());
    ::eina_thread_join(_raw);
    _joinable = false;
  }

  /**
   * @brief Detaches the thread from its handle, making it runs independently.
   *
   * This member function separates the thread of execution from the
   * thread object, allowing execution to continue independently.
   *
   * @note After a call to this function, the thread object becomes
   * non-joinable.
   */
  void detach()
  {
    assert(joinable());
    _joinable = false;
  }

  /**
   * @brief Returns the identifier of the thread associated with this thread object.
   * @return <tt>thread::id</tt> identifying the thread associated with this thread object.
   */
  id get_id() const noexcept
  {
    return id(_raw);
  }

  /**
   * @brief Get a handle for the wrapped @c Eina_Thread.
   * @return Handle for the native @c Eina_Thread.
   *
   * This member function returns the native @c Eina_Thread handle that
   * is wrapped inside this object.
   */
  native_handle_type native_handle() const
  {
    return _raw;
  }

  /**
   * @brief Get the number of hardware concurrent threads.
   * @return A hint on the number of hardware concurrent threads, or
   *         @c 0 if the value is not well defined or not computable.
   *
   * This static member function returns the number of hardware
   * concurrent threads.
   *
   * @note The interpretation of this value is implementation-specific,
   * and may be just an approximation.
   */
  static unsigned hardware_concurrency() noexcept
  {
    return ::eina_cpu_count();
  }
private:
  /** @internal */
  bool _joinable;

  /** @internal */
  Eina_Thread _raw;
};

/**
 * @brief Exchanges the underlying handles of two thread objects.
 * @param lhs First thread object.
 * @param rhs Second thread object.
 */
inline void swap(thread& lhs, thread& rhs)
{
  lhs.swap(rhs);
}

namespace this_thread {

/**
 * @brief Return identifier of the current thread.
 * @return <tt>thread::id</tt> identifying the current thread.
 */
inline thread::id get_id()
{
  return thread::id(eina_thread_self());
}

/**
 * @brief Provides a hint to the implementation to reschedule the
 * execution of threads, allowing other threads to run.
 */
inline void yield() {}

/**
 * @brief Block the execution of the current thread until a specified time point.
 * @param abs_time Point in time when the calling thread shall resume its execution.
 *
 * @note This function may block for longer than until after @p rel_time
 * has been reached due to scheduling or resource contention delays.
 */
template <typename Clock, typename Duration>
void sleep_until(std::chrono::time_point<Clock, Duration>const& abs_time);

/**
 * @brief Block the execution of the current thread for a specified time duration.
 * @param rel_time Time span after which the calling thread shall resume its execution.
 *
 * @note This function may block for longer than @p rel_time due to
 * scheduling or resource contention delays.
 */
template <typename Rep, typename Period>
void sleep_for(std::chrono::duration<Rep, Period>const& rel_time);
}

/**
 * @}
 */

} }

/**
 * @internal
 * Specialization of standard @c hash class to specify that a
 * <tt>thread_id</tt> object should be handled as a unsigned long
 * @{
 */
namespace std {

template <>
struct hash< ::efl::eina::thread_id> : hash<unsigned long>
{};

}
/**
 * @}
 */

/**
 * @}
 */

#endif