use new buildit OS_Lock
This commit is contained in:
parent
28cb519b7a
commit
afea5ea512
52
build.c
52
build.c
@ -73,27 +73,23 @@ struct StepList {
|
|||||||
|
|
||||||
void AddStep(String name, T_TaskFunc *func, void *arg)
|
void AddStep(String name, T_TaskFunc *func, void *arg)
|
||||||
{
|
{
|
||||||
OS_MutexLockE(&sl->mutex);
|
OS_Lock lock = OS_MutexLockE(&sl->mutex);
|
||||||
{
|
Step *s = ArenaPush(&sl->arena, Step);
|
||||||
Step *s = ArenaPush(&sl->arena, Step);
|
s->res_mutex = OS_MutexAlloc();
|
||||||
s->res_mutex = OS_MutexAlloc();
|
s->res_cv = OS_ConditionVariableAlloc();
|
||||||
s->res_cv = OS_ConditionVariableAlloc();
|
s->name = name;
|
||||||
s->name = name;
|
s->arg = arg;
|
||||||
s->arg = arg;
|
SllQueuePush(sl->first, sl->last, s);
|
||||||
SllQueuePush(sl->first, sl->last, s);
|
++sl->count;
|
||||||
++sl->count;
|
T_AddTask(&sl->tq, func, s);
|
||||||
T_AddTask(&sl->tq, func, s);
|
OS_MutexUnlock(&lock);
|
||||||
}
|
|
||||||
OS_MutexUnlockE(&sl->mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddSyncPoint(void)
|
void AddSyncPoint(void)
|
||||||
{
|
{
|
||||||
OS_MutexLockE(&sl->mutex);
|
OS_Lock lock = OS_MutexLockE(&sl->mutex);
|
||||||
{
|
T_AddSyncPoint(&sl->tq);
|
||||||
T_AddSyncPoint(&sl->tq);
|
OS_MutexUnlock(&lock);
|
||||||
}
|
|
||||||
OS_MutexUnlockE(&sl->mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExecuteSteps(void)
|
void ExecuteSteps(void)
|
||||||
@ -126,21 +122,21 @@ void BuildStepSimpleCommand(void *arg_raw)
|
|||||||
BuildStepSimpleCommandArg *arg = s->arg;
|
BuildStepSimpleCommandArg *arg = s->arg;
|
||||||
SH_CommandResult result = SH_RunCommandCaptureOutput(scratch.arena, arg->cmd, true);
|
SH_CommandResult result = SH_RunCommandCaptureOutput(scratch.arena, arg->cmd, true);
|
||||||
|
|
||||||
OS_MutexLockE(&s->res_mutex);
|
|
||||||
{
|
{
|
||||||
|
OS_Lock res_lock = OS_MutexLockE(&s->res_mutex);
|
||||||
if (result.output.len > 0) {
|
if (result.output.len > 0) {
|
||||||
OS_MutexLockE(&sl->mutex);
|
OS_Lock sl_lock = OS_MutexLockE(&sl->mutex);
|
||||||
{
|
{
|
||||||
s->res_output.text = ArenaPushArrayNoZero(&sl->arena, Byte, result.output.len);
|
s->res_output.text = ArenaPushArrayNoZero(&sl->arena, Byte, result.output.len);
|
||||||
}
|
}
|
||||||
OS_MutexUnlockE(&sl->mutex);
|
OS_MutexUnlock(&sl_lock);
|
||||||
s->res_output.len = result.output.len;
|
s->res_output.len = result.output.len;
|
||||||
MemoryCopy(s->res_output.text, result.output.text, result.output.len);
|
MemoryCopy(s->res_output.text, result.output.text, result.output.len);
|
||||||
}
|
}
|
||||||
s->res_status = result.error ? StepStatus_Failure : StepStatus_Success;
|
s->res_status = result.error ? StepStatus_Failure : StepStatus_Success;
|
||||||
OS_ConditionVariableBroadcast(&s->res_cv);
|
OS_ConditionVariableBroadcast(&s->res_cv);
|
||||||
|
OS_MutexUnlock(&res_lock);
|
||||||
}
|
}
|
||||||
OS_MutexUnlockE(&s->res_mutex);
|
|
||||||
|
|
||||||
ScratchEnd(scratch);
|
ScratchEnd(scratch);
|
||||||
}
|
}
|
||||||
@ -158,21 +154,21 @@ void BuildStepMsvcCompileCommand(void *arg_raw)
|
|||||||
D_ClearWrite(arg->output_depfile, depfile_data);
|
D_ClearWrite(arg->output_depfile, depfile_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
OS_MutexLockE(&s->res_mutex);
|
|
||||||
{
|
{
|
||||||
|
OS_Lock res_lock = OS_MutexLockE(&s->res_mutex);
|
||||||
if (result.output.len > 0) {
|
if (result.output.len > 0) {
|
||||||
OS_MutexLockE(&sl->mutex);
|
OS_Lock sl_lock = OS_MutexLockE(&sl->mutex);
|
||||||
{
|
{
|
||||||
s->res_output.text = ArenaPushArrayNoZero(&sl->arena, Byte, result.output.len);
|
s->res_output.text = ArenaPushArrayNoZero(&sl->arena, Byte, result.output.len);
|
||||||
}
|
}
|
||||||
OS_MutexUnlockE(&sl->mutex);
|
OS_MutexUnlock(&sl_lock);
|
||||||
s->res_output.len = result.output.len;
|
s->res_output.len = result.output.len;
|
||||||
MemoryCopy(s->res_output.text, result.output.text, result.output.len);
|
MemoryCopy(s->res_output.text, result.output.text, result.output.len);
|
||||||
}
|
}
|
||||||
s->res_status = result.error ? StepStatus_Failure : StepStatus_Success;
|
s->res_status = result.error ? StepStatus_Failure : StepStatus_Success;
|
||||||
OS_ConditionVariableBroadcast(&s->res_cv);
|
OS_ConditionVariableBroadcast(&s->res_cv);
|
||||||
|
OS_MutexUnlock(&res_lock);
|
||||||
}
|
}
|
||||||
OS_MutexUnlockE(&s->res_mutex);
|
|
||||||
|
|
||||||
ScratchEnd(scratch);
|
ScratchEnd(scratch);
|
||||||
}
|
}
|
||||||
@ -835,13 +831,13 @@ void OnBuild(StringList cli_args)
|
|||||||
|
|
||||||
SH_PrintF(Lit("[%F/%F] %F\n"), FmtI64(step_i), FmtI64(step_count), FmtStr(s->name));
|
SH_PrintF(Lit("[%F/%F] %F\n"), FmtI64(step_i), FmtI64(step_count), FmtStr(s->name));
|
||||||
|
|
||||||
OS_MutexLockS(&s->res_mutex);
|
|
||||||
{
|
{
|
||||||
|
OS_Lock lock = OS_MutexLockS(&s->res_mutex);
|
||||||
while (s->res_status == StepStatus_None) {
|
while (s->res_status == StepStatus_None) {
|
||||||
OS_ConditionVariableWaitS(&s->res_cv, &s->res_mutex);
|
OS_ConditionVariableWait(&s->res_cv, &lock);
|
||||||
}
|
}
|
||||||
|
OS_MutexUnlock(&lock);
|
||||||
}
|
}
|
||||||
OS_MutexUnlockS(&s->res_mutex);
|
|
||||||
|
|
||||||
String output = s->res_output;
|
String output = s->res_output;
|
||||||
if (s->res_status != StepStatus_Success) {
|
if (s->res_status != StepStatus_Success) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user