Beispiel #1
0
static inline void release_lock(int i)
{
    if ( pthread_mutex_unlock(&__hlt_globals()->synced_fiber_pool_lock) != 0 )
        fatal_error("cannot unlock mutex");

    hlt_pthread_setcancelstate(i, NULL);
}
Beispiel #2
0
static inline void acqire_lock(int* i)
{
    hlt_pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, i);

    if ( pthread_mutex_lock(&__hlt_globals()->synced_fiber_pool_lock) != 0 )
        fatal_error("cannot lock mutex");
}
Beispiel #3
0
inline static void _release_lock(hlt_thread_queue* queue, int i, int reader, int thread)
{
    if ( PTHREAD_SPIN_UNLOCK(&queue->lock) != 0 )
        _fatal_error("cannot release lock");

    // fprintf(stderr, "released %p %d %d\n", queue, reader, thread);

    hlt_pthread_setcancelstate(i, NULL);
}
Beispiel #4
0
// Note: When using _acquire/_release, it is important that there's no
// cancelation point between the two calls as otherwise a lock main remain
// acquired after a thread has already terminated.
inline static void _acquire_lock(hlt_thread_queue* queue, int* i, int reader, int thread)
{
    hlt_pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, i);

    // stderr, "trying acquired %p %d %d\n", queue, reader, thread);

    if ( PTHREAD_SPIN_LOCK(&queue->lock) != 0 )
        _fatal_error("cannot acquire lock");

    // fprintf(stderr, "acquired %p %d %d\n", queue, reader, thread);

}
Beispiel #5
0
static void __exception_print(const char* prefix, hlt_exception* e, hlt_execution_context* ctx)
{
    hlt_exception* excpt = 0;

    // We must not terminate while in here.
    int old_state;
    hlt_pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_state);

    flockfile(stderr);

    hlt_string s = __exception_render(e, ctx);
    char* c = hlt_string_to_native(s, &excpt, ctx);

    fprintf(stderr, "%s%s\n", prefix, c);

    hlt_free(c);

    fflush(stderr);
    funlockfile(stderr);

    hlt_pthread_setcancelstate(old_state, NULL);
}