Skip to content

Commit

Permalink
Fix compile errors after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
kpamnany committed Jul 28, 2017
1 parent 78c1aea commit d58c288
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/atomics.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@
// the __atomic builtins or c11 atomics with GNU extension or c11 _Generic
# define jl_atomic_compare_exchange(obj, expected, desired) \
__sync_val_compare_and_swap(obj, expected, desired)
# define jl_atomic_bool_compare_exchange(obj, expected, desired) \
__sync_bool_compare_and_swap(obj, expected, desired)
# define jl_atomic_exchange(obj, desired) \
__atomic_exchange_n(obj, desired, __ATOMIC_SEQ_CST)
# define jl_atomic_exchange_generic(obj, desired, orig)\
__atomic_exchange(obj, desired, orig, __ATOMIC_SEQ_CST)
# define jl_atomic_exchange_relaxed(obj, desired) \
__atomic_exchange_n(obj, desired, __ATOMIC_RELAXED)
// TODO: Maybe add jl_atomic_compare_exchange_weak for spin lock
Expand Down Expand Up @@ -115,6 +119,7 @@ jl_atomic_fetch_add(T *obj, T2 arg)
{
return (T)_InterlockedExchangeAdd64((volatile __int64*)obj, (__int64)arg);
}
// TODO: jl_atomic_exchange_generic
#define jl_atomic_fetch_add_relaxed(obj, arg) jl_atomic_fetch_add(obj, arg)

// and
Expand Down Expand Up @@ -200,6 +205,7 @@ jl_atomic_compare_exchange(volatile T *obj, T2 expected, T3 desired)
return (T)_InterlockedCompareExchange64((volatile __int64*)obj,
(__int64)desired, (__int64)expected);
}
// TODO: jl_atomic_bool_compare_exchange
// atomic exchange
template<typename T, typename T2>
static inline typename std::enable_if<sizeof(T) == 1, T>::type
Expand Down
73 changes: 73 additions & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,79 @@ JL_DLLEXPORT void JL_NORETURN jl_no_exc_handler(jl_value_t *e);

#include "locks.h" // requires jl_task_t definition

#ifdef JULIA_ENABLE_THREADING
#ifdef JULIA_ENABLE_PARTR
/* ptask settings */
#define TASK_IS_DETACHED 0x02
/* clean up the task on completion */
#define TASK_IS_STICKY 0x04
/* task is sticky to the thread that first runs it */

typedef struct _arriver_t arriver_t;
typedef struct _reducer_t reducer_t;

typedef struct _jl_ptaskq_t jl_ptaskq_t;
typedef struct _jl_ptaskq_t jl_condition_t;
typedef struct _jl_ptask_t jl_ptask_t;

struct _jl_ptaskq_t {
jl_ptask_t *head;
jl_mutex_t lock;
};

struct _jl_ptask_t {
/* to link this task into queues */
jl_ptask_t *next;

/* TODO: context and stack */

/* state */
size_t started:1;

/* task entry point, arguments, result, etc. */
jl_method_instance_t *mfunc;
jl_generic_fptr_t fptr;
jl_value_t *args;
jl_value_t *result;
jl_module_t *current_module;
size_t world_age;

/* grain's range, for parfors */
int64_t start, end;

/* reduction function, for parfors */
jl_method_instance_t *mredfunc;
jl_generic_fptr_t rfptr;
jl_value_t *rargs;

/* parent (first) task of a parfor set */
jl_ptask_t *parent;

/* to synchronize/reduce grains of a parfor */
arriver_t *arr;
reducer_t *red;

/* parfor reduction result */
jl_value_t *red_result;

/* completion queue */
jl_ptaskq_t cq;

/* task settings */
int8_t settings;

/* tid of the thread to which this task is sticky */
int16_t sticky_tid;

/* the index of this task in the set of grains of a parfor */
int16_t grain_num;

/* for the multiqueue */
int16_t prio;
};
#endif // JULIA_ENABLE_PARTR
#endif // JULIA_ENABLE_THREADING

STATIC_INLINE void jl_eh_restore_state(jl_handler_t *eh)
{
jl_ptls_t ptls = jl_get_ptls_states();
Expand Down
16 changes: 16 additions & 0 deletions src/locks.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ static inline void jl_mutex_lock(jl_mutex_t *lock)
jl_gc_enable_finalizers(ptls, 0);
}

static inline int jl_mutex_trylock_nogc(jl_mutex_t *lock)
{
unsigned long self = jl_thread_self();
unsigned long owner = jl_atomic_load_acquire(&lock->owner);
if (owner == self) {
lock->count++;
return 1;
}
if (owner == 0 &&
jl_atomic_compare_exchange(&lock->owner, 0, self) == 0) {
lock->count = 1;
return 1;
}
return 0;
}

/* Call this function for code that could be called from either a managed
or an unmanaged thread */
static inline void jl_mutex_lock_maybe_nogc(jl_mutex_t *lock)
Expand Down

0 comments on commit d58c288

Please sign in to comment.